R中的三角回归

时间:2014-11-03 22:47:47

标签: r regression trigonometry

如何使用R?

进行三角回归

例如,对于数据

t<-c(1,2,3,4,5,6,7,8,9,10,11,12)
y<-c(7.53,3.85,3.22,6.40,7.42,3.43,1.60,7.26,7.33,3.20,2.67,6.74)

我如何在表格

中拟合模型
$Y_t=\beta+\alpha \cos(\frac{2\pi}{p})t+\gamma \sin(\frac{2\pi}{p})t$  p=4 and is the period

查找参数\ beta \ alpha和\ gamma?

的估算值

我试过做

modelo<-lm(y~cos((2*pi)/p)+sin((2*pi)/p))

但它没有工作。

1 个答案:

答案 0 :(得分:1)

您忘记在回归中包含t

p <- 4
modelo<-lm(y~cos((2*pi*t)/p)+sin((2*pi*t)/p))

绘制数据和预测:

plot(t,y)
dpred <- data.frame(t=seq(1,12,length=51))
dpred$y <- predict(modelo,newdata=dpred)
with(dpred,lines(t,y))