r - 在 R 中拟合和绘制时间序列的谐波回归模型
问题描述
在 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
知道如何实现吗?
解决方案
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
手册解释说,您必须将 inputts 和 inputtime 作为向量或矩阵提供给harmonic.regression()
.
推荐阅读
- r - 在shinydashboard 中,白框被夹在右上角和右下角
- ag-grid - 在 ag-grid 中删除匹配过滤条件的记录
- swift - 在 while 循环中使用 perform(afterDelay:) 会给我一个逻辑错误?
- html - 将元素粘贴到某个位置
- flutter - 无法在flutter中使用firebase auth使用电子邮件和密码登录或注册
- python - 为什么我的长时间运行的 python 脚本在运行大约 3 天后会因“无效指针”而崩溃?
- jersey - JerseyTest:如何绑定到 Set
- angular - 如何在 Angular 6 中使用路由设置类
- android - Android LayoutInflater 不在单独的类中工作,也没有发生错误
- ffmpeg - h264 二进制流中的 key_frame(I) 和 P 帧序列无效