[英]Forecasting using a tslm
I have created a time series linear model using tslm. 我使用tslm创建了时间序列线性模型。 It is built using 179 observations of weekly data and I want to forecast the next 26 weeks but keep getting the error:
它是使用179个每周数据观察构建的,我想预测接下来的26周,但仍会收到错误消息:
tslm5<-tslm(tsorders~ trend +
I(trend^2) + Month.number, data=ppc.order.forecasting[1:179,])
forecast(tslm5,newdata=ppc.order.forecasting[180:205,])
Error in `[[<-.data.frame`(`*tmp*`, length(tmpdata) + 1, value = c(1, :
replacement has 179 rows, data has 26'
How do I use the data in rows 180:205 and tslm5 to forecast the next 26 weeks? 如何使用行180:205和tslm5中的数据来预测未来26周?
Without more information about your package versions, and the nature of ppc.order.forecasting
, it is impossible to know what causes your error. 如果没有有关软件包版本以及
ppc.order.forecasting
的性质的更多信息,就不可能知道导致错误的原因。
The following example works using the latest version (8.4) of the forecast
package. 以下示例使用
forecast
程序包的最新版本(8.4)进行工作。
library(forecast)
library(ggplot2)
ppc.order.forecasting <- cbind(
trend = 1:205,
Month.number = rep(1:12,18)[1:205],
tsorders = rpois(205, abs((1:205)/50 + 2*sin(2*pi*(1:205)/12)))
) %>% ts(freq=12)
tslm5 <- tslm(tsorders~ trend + I(trend^2) + Month.number,
data=subset(ppc.order.forecasting, end=179))
forecast(tslm5, newdata=subset(ppc.order.forecasting, start=180)[,1:2]) %>%
autoplot()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.