y代表黄土,但因预测而出错

问题描述 投票:0回答:1

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

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)

我收到以下错误:

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

怎么了?看起来很简单。对。如果有人也有帮助,我还需要计算出连接点所形成的弧的长度。我已经试过arclength,但是没有功能是行不通的。我正在该地区使用AUC,它工作正常。

r curve-fitting predict loess
1个回答
0
投票

以下代码使用功能loess,而不是lowess。根据lowess的帮助页面,第[[另请参见部分,此功能为

另见

[loess,基于公式的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")

enter image description here

数据。

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')
© www.soinside.com 2019 - 2024. All rights reserved.