【问题标题】:Fitting and plotting harmonic regression model of a time series in R在 R 中拟合和绘制时间序列的谐波回归模型
【发布时间】:2019-10-10 14:02:12
【问题描述】:

在 R 中,使用 HarmonicRegression 库,我试图将谐波回归模型与趋势拟合,但我正在努力弄清楚如何调用harmonic.regression 函数并绘制拟合模型。

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

知道如何实现吗?

【问题讨论】:

    标签: r time-series modeling


    【解决方案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() 的向量或矩阵提供。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-07
      • 2014-04-25
      • 2015-08-09
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      相关资源
      最近更新 更多