2017-08-12 12 views
2
set.seed(1); x <- round(rnorm(30), 1); y <- sin(pi * x) + rnorm(30)/10 
plot(x, y, main = "spline(x,y) when x has ties") 
lines(spline(x, y, n = 201), col = 2) 

enter image description hereどのよう

スプラインの滑らかさを調整する方法はありスプラインの滑らかさを調整するには?特に-0.5以降では、よりスムーズになるくすんだ部分があります。私はドキュメントを見てきましたが、これを行う単純なパラメータではないようです(のようなものがsmooth.spline)。

答えて

1

黄土は、このソリューションに問題があり補間spline

set.seed(1); 
x <- round(rnorm(30), 1); 
y <- sin(pi * x) + rnorm(30)/10 
plot(x, y, main = "spline(x,y) when x has ties") 
sm <- smooth.spline(x, y, spar = 0.5) # play with spar 
pred <- predict(sm, seq(-2, 2, by = 0.1)) 
lines(pred, col = "red") 

smoothing splines

の一つの方法ですが、スプラインを使用したい場合は、smooth.splineを使用し、ありませんポイントの密度が低い場合、フィット感はあまり良くありません。 loessはよりローカルなので(これがlの略です)、より良いかもしれません。

0

私は、平滑用LOESSを使用します。必要に応じて

lines(loess.smooth(y=spl[["y"]], x=spl[["x"]], span = 0.05), col=2) 

は、スパンを調整します。負の領域では次の点に注意してください