Sine curve fit using lm and nls in R

后端 未结 4 1462
自闭症患者
自闭症患者 2020-12-30 09:42

I am a beginner in curve fitting and several posts on Stackoverflow really helped me.

I tried to fit a sine curve to my data using lm and nls

4条回答
  •  被撕碎了的回忆
    2020-12-30 10:11

    Alternatively, you could have eliminated the NAs from your data after reading it in:

    data <- subset(data, !is.na(temperature))
    

    Then, when plotting, you could set the x-axis to the time points from the reduced data set:

    plot(temp~time, data=data, xlim=c(1, 900))
    lines(x=time, y=fit.lm$fitted, col="red")
    

    This curve won't be as smooth as the one produced by @andy-barbour but it will work in a pinch.

提交回复
热议问题