Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R y代表黄土中的x,但预测结果存在误差_R_Curve Fitting_Predict_Loess - Fatal编程技术网

R y代表黄土中的x,但预测结果存在误差

R y代表黄土中的x,但预测结果存在误差,r,curve-fitting,predict,loess,R,Curve Fitting,Predict,Loess,我有一些河流横截面数据。它看起来像: width [1] 0.00 0.00 1.85 4.00 5.70 6.40 7.40 8.00 9.70 10.70 12.20 14.00 16.65 18.00 18.80 19.55 20.17 [18] 20.17 depth [1] 0.000 0.185 0.310 0.550 0.720 1.110 1.490 1.740 1.810 2.000 1.920 1.680 1.530 0.6

我有一些河流横截面数据。它看起来像:

width
 [1]  0.00  0.00  1.85  4.00  5.70  6.40  7.40  8.00  9.70 10.70 12.20 14.00 16.65 18.00 18.80 19.55 20.17
[18] 20.17

depth
 [1]  0.000  0.185  0.310  0.550  0.720  1.110  1.490  1.740  1.810  2.000  1.920  1.680  1.530  0.600
[15] -0.620 -0.760 -0.830 -0.998
我想画点,连接点,然后计算标准x的y值,比如每0.5米。 我可以使用smooth.spline实现这一点,但使用黄土实际上只是连接点

这是我试过的

plot(width, depth)
connectlines=lowess(depth[-c(1, length(depth))]~width[-c(1,length(width))], f=1/8)
lines(connectlines)
因为第一次和最后一次的深度测量是在一个参考针上,所以我把它们放了下来

然后,我尝试在将其应用于.5m增量之前找到一个值

predict(connectlines, 4)
我得到以下错误:

使用方法中的错误(“预测”):
没有适用于“列表”类对象的“预测”方法

怎么了?看起来很简单。正确的。
我还需要计算连接点所形成的弧的长度,如果有人对此有帮助的话。我试过arclength,但如果没有函数,它就不起作用。我正在为该区域使用AUC,它工作正常。

以下代码使用函数
lowess
,而不是
lowess

根据
lowess
的帮助页面,请参见部分,此功能是

另请参见

width <- scan(text = '
0.00  0.00  1.85  4.00  5.70  6.40  7.40  8.00  9.70 
10.70 12.20 14.00 16.65 18.00 18.80 19.55 20.17 20.17')

depth <- scan(text = '
0.000  0.185  0.310  0.550  0.720  1.110  1.490  1.740  1.810  
2.000  1.920  1.680  1.530  0.600  -0.620 -0.760 -0.830 -0.998')
lowess
,一个基于公式的较新版本的
lowess
(具有不同的默认值!)

参数
f
成为拟合中使用的点的范围。我已设置
span=0.5

df1 <- data.frame(width, depth)
fit <- loess(depth ~ width, data = df1[-c(1, nrow(df1)),], span = 0.5)

new <- data.frame(width = seq(min(width), max(width), by = 0.5))
new$depth <- predict(fit, newdata = new)

plot(depth ~ width, df1)
lines(fit)
lines(depth ~ width, new, col = "blue")

df1关闭,但我的问题是因为这是一个物理测量,一个河床,我不能近似河床的曲线,而是需要连接点。如果我减小跨距,我可以得到错误信息,这也可以通过平滑样条曲线来实现,但我只想连接点并计算连接点的线的值。我想我也可以写一些循环函数来定义每条线,计算点和长度。但是我认为有一种更简单的方法。@JoeSlow如果你减小范围,消息是警告,而不是错误。您可以运行
suppressWarnings(黄土(…)
来清除它们。@JoeSlow预测线的长度是
和(新的,求和(sqrt(宽度^2+深度^2)))
。确定抑制警告并设置spar=.125将获得连接点的直线上的所有预测点。最后我添加了一个循环来更正长度计算,因为它的宽度/深度发生了变化。
for(I in 1:nrow(mydata)){n=(new$depth[I+1]-new$depth[I])new$depth2[I]=n}new$linelength=with(new,sum(sqrt(0.5^2+depth2^2))