r - 无法预测 tslm
问题描述
尝试使用一组领先指标变量来创建提前 12 个月的预测,但在创建 tslm 之后,我一直遇到 forecast() 函数错误。这是我用于领先指标的代码:
ret.0 <- readxl::read_excel("Texas County Sales taxes.xlsx")
ret.1 <- ts(ret.0[,"Williamson"], frequency=12, start=c(2012, 12))
ret.2 <- window(ret.1, start=c(2012,12))
# Read Leading Indicator Data
lead.0 <- readxl::read_excel("Leading.xlsx")
alc.sales <- ts(lead.0[,"Alcohol Sales"], frequency=12, start=c(2012, 12))
house.sales <- ts(lead.0[,"Housing Sales"], frequency=12 , start=c(2012, 12))
alc.sales.1 <- ts.intersect(ret.2, alc.sales)[, "alc.sales"]
ret.2.1 <- ts.intersect(ret.2, alc.sales)[, "ret.2"]
ggCcf(alc.sales.1, ret.2.1)
sd_ret <- diff(ret.2, 12)
d_alc <- diff(alc.sales)
alc.sales.2 <- ts.intersect(sd_ret, d_alc)[, "d_alc"]
ret.2.2 <- ts.intersect(sd_ret, d_alc)[, "sd_ret"]
ggCcf(alc.sales.2, ret.2.2)
ccf.mat <- ts.intersect(ret.2, alc.sales, house.sales)
ggCcf(ccf.mat[,2], ccf.mat[,1])
ggCcf(ccf.mat[,3], ccf.mat[,1])
alc.salesl6 <- lag(alc.sales, k=6)
house.salesl6 <- lag(house.sales, k=6)
lead.fit.1 <- tslm(ret.2 ~ alc.salesl6 + house.salesl6 + season)
summary(lead.fit.1)
checkresiduals(lead.fit.1)
forecast(lead.fit.1)
运行 forecast(lead.fit.1) 时遇到错误:
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
variable lengths differ (found for 'season')
In addition: Warning message:
'newdata' had 10 rows but variables found have 99 rows
我不完全确定 newdata 是什么或如何解决此错误,任何帮助将不胜感激。
解决方案
推荐阅读
- python - Python数据框到字典
- c# - 如何让相机从后面跟随一个滚动的球?
- node.js - 为什么续集 Intellisense 不起作用?
- npm - 从 Github Action 中检索 Github Registry npm 包
- apache-spark - 为什么 Spark 确定了 7 个分区?
- c# - C# Mysql datareader - 如何使用datareader获取其他列
- javascript - JS中如何按公共元素对子数组进行分组
- mysql - 导入计数后行数不同
- path - 不能将 ipython 或 julia repls 的命令与 zsh 一起使用
- node.js - 运行需要不同版本节点的 NodeJS 程序