时间序列预测

数据挖掘 r 预测
2022-02-19 14:39:26

我在石油和天然气行业工作。

我一直在尝试用协变量构建一个ts预测模型,模型R代码如下:

#Getting R libraries:
library(readxl)
library(ggplot2)
library(forecast)
library(timeSeries)
library(tseries)
library(MTS)

#Create a time series object:
myts <- ts(dataset, start = c(2005,1), end = c(2019,12), frequency = 12)

#Illustrate out of sample forecasting with covariates, splitting the data:
train <- window(myts, end = c(2018,12))
test <- window(myts, start = c(2019,1))

#Fitting the time series forecasting model:
covariates <- c("Income","Prices","Sites","Vehicles")
fit <- auto.arima(train[,"Volumes"], xreg = train[,covariates])

#Forecasting from test data:
mytsfcast <- forecast(fit, h = 6*12, xreg = test[,covariates])

autoplot(mytsfcast)

但是,我一直在尝试预测 12、24、36 等月份的零售量。该模型仅生成以下结果:

模型拟合结果:

请问您能否就如何让我的模型预测超出 end = c(2019,12) 提出建议。我错过了什么?

1个回答

我无法重现空白模型拟合结果。但是,我知道预测函数最多只能预测已知的 xreg 输入。例如,您的测试期从 2019 年 1 月开始,到 2019 年 12 月结束(12 个周期),但您尝试预测 72 个周期。尝试将预测函数中的 h 参数设置为 12,看看是否得到相同的结果。

为了在过去解决这个问题,我已经预测了未来的 xreg 系列(在你的情况下,四个 xreg 变量中的每一个都有额外的 60 个周期)。然后,您需要将这 60 个句点添加到每个变量的测试集末尾。