简体   繁体   English

用xreg预测ARIMA

[英]Forecasting ARIMA with xreg

I'm trying to forecast time in time out ("TiTo") for someone ordering food at a restaurant using the code below. 我正在尝试使用下面的代码来预测某人在餐厅点菜的时间(“ TiTo”)。 TiTo is the total time it takes someone from the time they walk through the door to the time they get their food. TiTo是某人从走进门到获得食物所花费的总时间。 TimeTT is the time the customer spends talking to the waiter. TimeTT是客户花在与服务员交谈上的时间。 I believe TimeTT is a predictor of TiTo and I would like to use it as a covariate in the forecast for TiTo. 我相信TimeTT是TiTo的预测指标,我想将其用作TiTo预测的协变量。 I've read some about ARIMA, and as I understand it you add the predictors to the model in the xreg parameter. 我已经读过一些关于ARIMA的知识,据我了解,您可以在xreg参数中将预测变量添加到模型中。 I'm thinking of the xreg parameter as something like the independent variable for a regression model, like lm(TiTo ~ TimeTT). 我认为xreg参数就像回归模型的自变量一样,如lm(TiTo〜TimeTT)。 Is this the correct way to think of the xreg parameter? 这是考虑xreg参数的正确方法吗? Also what does the error message below mean? 另外,以下错误消息是什么意思? Do I need to convert TimeTT into a time series to use it in the xreg parameter? 我需要将TimeTT转换为时间序列以在xreg参数中使用它吗? I'm new to forecasting so all help is very appreciated. 我是天气预报的新手,因此非常感谢所有帮助。

Forecast Attempt: 预测尝试:

OV<-zoo(SampleData$TiTo, order.by=SampleData$DateTime)

eData <- ts(OV, frequency = 24)

Train <-eData[1:15000]

Test <- eData[15001:20809]

Arima.fit <- auto.arima(Train)

Acast<-forecast(Arima.fit, h=5808, xreg = SampleData$TimeTT)

Error: 错误:

Error in if (ncol(xreg) != ncol(object$call$xreg)) stop("Number of regressors does not match fitted model") : argument is of length zero if(ncol(xreg)!= ncol(object $ call $ xreg))stop(“回归数与拟合模型不匹配”)中的错误:参数长度为零

Data: 数据:

dput(Train[1:5])
c(1152L, 1680L, 1680L, 968L, 1680L)

dput(SampleData[1,]$TimeTT)
structure(1156L, .Label = c("0.000000", "0.125000", "0.142857",  
"96.750000", "97.800000", "99.000000", "99.600000", "NULL"), class = "factor")

You need to define the xreg when you estimate the model itself, and these need to be forecasted ahead as well. 在估计模型本身时,您需要定义xreg ,并且还需要提前进行预测。 So this will look something like: 所以这看起来像:

Arima.fit <- auto.arima(Train, xreg = SampleData$TimeTT)
forecast(Arima.fit, h = 508, xreg = NewData$TimeTT)

Here is an example using Arima and xreg from Rob Hyndman (here is the link to the example, but to read more about using contemporaneous covariates in ARIMA models go here ), this is analogous to auto.arima . 这是一个使用Rob Hyndman的Arimaxreg的示例(这里是示例的链接 ,但要了解有关在ARIMA模型中使用同期协变量的更多信息,请点击此处 ),这类似于auto.arima

n <- 2000
m <- 200
y <- ts(rnorm(n) + (1:n)%%100/30, f=m)

library(forecast)
fit <- Arima(y, order=c(2,0,1), xreg=fourier(y, K=4))
plot(forecast(fit, h=2*m, xreg=fourierf(y, K=4, h=2*m)))

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM