How to fit a smooth curve to my data in R?

前端 未结 8 1896
无人共我
无人共我 2020-11-29 15:59

I\'m trying to draw a smooth curve in R. I have the following simple toy data:

> x
 [1]  1  2  3  4  5  6  7  8  9 10
> y
 [1]  2  4  6  8         


        
8条回答
  •  攒了一身酷
    2020-11-29 16:43

    Maybe smooth.spline is an option, You can set a smoothing parameter (typically between 0 and 1) here

    smoothingSpline = smooth.spline(x, y, spar=0.35)
    plot(x,y)
    lines(smoothingSpline)
    

    you can also use predict on smooth.spline objects. The function comes with base R, see ?smooth.spline for details.

提交回复
热议问题