R: perfect smoothing curve

前端 未结 3 1789
Happy的楠姐
Happy的楠姐 2021-02-06 19:35

I am trying to fit smooth curve to my dataset; is there is any better smoothing curve than I produced using the following codes:

x <- seq(1, 10, 0.5)
y <-          


        
3条回答
  •  囚心锁ツ
    2021-02-06 19:44

    You've got 19 points, so a polynomial up to X^18 will bullseye each of your points:

    > xl=seq(0,10,len=100)
    > p=lm(y~poly(x,18))
    > plot(x,y)
    > lines(xl,predict(p,newdata=data.frame(x=xl)))
    

    BUT that's ignoring what statistics is all about. Its about acknowledging that curves won't fit through points. Its about finding a model with a small number of parameters that explains as much as it can about the data, and leaves only noise. Its not about spearing your points with a curve - a curve so drawn has very little meaning between the data points.

提交回复
热议问题