我从USGS Nation Water Data网站获取了数据。目前我正在尝试绘制并适应该数据的曲线,以用于预测数据集中不同测量值(溶解氧、pH、高程和温度)与流量的关系。我使用了“nls”命令,并使用了一本方程书来查找要使用的曲线……对于这个例子,我特别使用了Schumacher的方程(书上第48页)。
数据链接如下:
曲线书籍:http://www.for.gov.bc.ca/hfd/pubs/docs/bio/bio04.htm 我使用的数据:http://waterdata.usgs.gov/mi/nwis/uv?referred_module=qw&search_station_nm=River%20Rouge%20at%20Detroit%20MI&search_station_nm_match_type=anywhere&index_pmcode_00065=1&index_pmcode_00060=1&index_pmcode_00300=1&index_pmcode_00400=1&index_pmcode_00095=1&index_pmcode_00010=1&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&range_selection=date_range&begin_date=2013-11-18&end_date=2013-12-18&format=html_table&date_format=YYYY-MM-DD&rdb_compression=file&list_of_search_criteria=search_station_nm,realtime_parameter_selection
数据链接如下:
曲线书籍:http://www.for.gov.bc.ca/hfd/pubs/docs/bio/bio04.htm 我使用的数据:http://waterdata.usgs.gov/mi/nwis/uv?referred_module=qw&search_station_nm=River%20Rouge%20at%20Detroit%20MI&search_station_nm_match_type=anywhere&index_pmcode_00065=1&index_pmcode_00060=1&index_pmcode_00300=1&index_pmcode_00400=1&index_pmcode_00095=1&index_pmcode_00010=1&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&range_selection=date_range&begin_date=2013-11-18&end_date=2013-12-18&format=html_table&date_format=YYYY-MM-DD&rdb_compression=file&list_of_search_criteria=search_station_nm,realtime_parameter_selection
我的问题是,一旦我选择了一条曲线编码它,我就无法使用nls来预测新值...我也无法弄清楚如何绘制它...我猜这可以通过残差来解决吗?在代码中,我使用“聚合”提取列出测量值和相应的放电速率的平均值,现在我只需要让R为我预测即可。我已经得到了我认为是拟合值...但我不确定并被“?nls”挡住了。
##Create new dataframes with means given date for each constituent
ph <- aggregate(Discharge~pH, data=River.Data, mean)
##pH models
pH <- ph$pH
disch <- ph$Discharge
phm <- nls(disch~exp(a+(b/pH)), data=ph, trace=T, start=list(a=-47.06 ,b=400.2))
newph<- data.frame(ph=c(3.0,4.0,5.0,6.0,7.0,8.0,9.0))
predict(phm, newdata=newph)
predict
中使用与原始模型完全相同的变量名称。否则,就像您发现的那样,predict
将返回拟合值而没有任何警告消息。我认为predict(phm,newdata=list(ph=newph))
会起作用。 - Carl Witthoft