R中时间序列的谐波回归模型的拟合和绘制

时间:2019-03-29 23:15:22

标签: r time-series modeling

在R中,我使用HarmonicRegression库试图使具有趋势的谐波回归模型拟合,但是我仍在努力弄清楚如何调用谐函数,回归函数并绘制拟合模型。

library(TSA)    
library(HarmonicRegression)
data(tempdub)

har_model <- harmonic.regression(tempdub, time(tempdub), Tau = 24, normalize = TRUE, norm.pol = FALSE, norm.pol.degree = 1, trend.eliminate = FALSE, trend.degree = 1)

plot(ts(fitted(har_model), freq=1, start=c(1964,1)), type='l', ylim=range(c(fitted(har_model), tempdub))) 

points(tempdub)

我遇到的第一个错误是:

Error in if (nrow(inputts) != length(inputtime)) stop(paste("Length of time series (inputts):",  : 
  argument is of length zero

有什么想法可以实现吗?

1 个答案:

答案 0 :(得分:1)

library("TSA")    
library("HarmonicRegression")
data(tempdub)

har_model <- harmonic.regression(as.vector(tempdub), 
                             1:length(tempdub), Tau = 12, 
                             normalize = TRUE, norm.pol = FALSE, norm.pol.degree = 1, 
                             trend.eliminate = FALSE, trend.degree = 1)


plot(tempdub)
lines(ts(har_model$fit.vals, freq=12, start=c(1964,1)), lty=2, col=3)
  

https://cran.r-project.org/web/packages/HarmonicRegression/HarmonicRegression.pdf

手册说明,您必须提供harmonic.regression()的输入和输入时间作为矢量或矩阵。

相关问题