在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
知道如何实现吗?
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()
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句