首页 > 解决方案 > 无法预测 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 是什么或如何解决此错误,任何帮助将不胜感激。

标签: rforecasting

解决方案


推荐阅读