从R函数“smooth.spline”中获取拟合平滑样条的全局最大值'

时间:2014-09-05 03:24:51

标签: r spline smoothing

我使用smooth.spline(x,y)平滑了我的数据,现在我想计算平滑曲线的模式或最大值。

x <- vect.1
y <- vect.2
plot(x, y, type = 'l')
smth <- smooth.spline(x, y)
lines(smth, col = 'red', lwd = 2)

data graph along with its smoothed curve

我目前的方法只是查找x,它给出了最大y,这不是那么准确。有没有更好的方法来做到这一点?

1 个答案:

答案 0 :(得分:0)

psmth <- predict(smth, x= seq(1,100, by=0.1) )
mode_psmth <- psmth$y[ which.max( psmth$y ) ]

甚至:

mode_psmth <- max(psmth$y)

如果这不是“足够准确”,那么请解释原因。

相关问题