简体   繁体   English

从 Auto.arima 到 R 中的预测

[英]From Auto.arima to forecast in R

I don't quite understand the syntax of how forecast() applies external regressors in the library(forecast) in R .我不太明白 predict forecast()如何在R中的library(forecast)中应用外部回归量的语法。

My fit looks like this:我的身材是这样的:

fit <- auto.arima(Y,xreg=factors)

where Y is a timeSeries object 100 x 1 and factors is a timeSeries object 100 x 5.其中Y是一个 100 x 1 的时间timeSeries对象,因子是一个 100 x 5 的时间timeSeries对象。

When I go to forecast, I apply...当我去预测时,我申请...

forecast(fit, h=horizon)

And I get an error:我收到一个错误:

Error in forecast.Arima(fit, h = horizon) : No regressors provided

Does it want me to add back the xregressors from the fit?它是否希望我从拟合中重新添加 xregressors? I thought these were included in the fit object as fit$xreg .我认为这些作为fit$xreg包含在fit对象中。 Does that mean it's asking for future values of the xregressors, or that I should repeat the same values I used in the fit set?这是否意味着它要求 xregressors 的未来值,或者我应该重复我在拟合集中使用的相同值? The documentation doesn't cover the meaning of xreg in the forecast step.该文档未涵盖预测步骤中xreg的含义。

I believe all this means I should use我相信这一切意味着我应该使用

forecast(fit, h=horizon,xreg=factors)

or或者

forecast(fit, h=horizon,xreg=fit$xreg)

Which gives the same results.这给出了相同的结果。 But I'm not sure whether the forecast step is interpreting the factors as future values, or appropriately as previous ones.但我不确定预测步骤是将这些因素解释为未来值,还是适当地解释为以前的值。 So,所以,

  1. Is this doing a forecast out of purely past values, as I expect?正如我所期望的那样,这是根据纯粹的过去值进行预测吗?
  2. Why do I have to specify the xreg values twice?为什么我必须两次指定 xreg 值? It doesn't run if I exclude them, so it doesn't behave like an option.如果我排除它们,它就不会运行,所以它的行为不像一个选项。

Correct me if I am wrong, but I think you may not completely understand how the ARIMA model with regressors works. 如果我错了,请纠正我,但我想你可能不完全理解带有回归器的ARIMA模型是如何工作的。

When you forecast with a simple ARIMA model (without regressors), it simply uses past values of your time series to predict future values. 当您使用简单的ARIMA模型(没有回归量)进行预测时,它只使用您时间序列的过去值来预测未来值。 In such a model, you could simply specify your horizon, and it would give you a forecast until that horizon. 在这样的模型中,您可以简单地指定您的地平线,它会为您提供预测,直到该范围。

When you use regressors to build an ARIMA model, you need to include future values of the regressors to forecast. 使用回归量来构建ARIMA模型时,需要包含要预测的回归量的未来值 For example, if you used temperature as a regressor, and you were predicting disease incidence, then you would need future values of temperature to predict disease incidence. 例如,如果您使用温度作为回归量,并且您预测疾病发病率,那么您将需要未来的温度值来预测疾病发病率。

In fact, the documentation does talk about xreg specifically. 事实上,文档确实特别谈到了xreg look up ?forecast.Arima and look at both the arguments h and xreg . 查看?forecast.Arima并查看参数hxreg You will see that If xreg is used, then h is ignored. 您将看到如果使用xreg ,则忽略h Why? 为什么? Because if your function uses xreg , then it needs them for forecasting. 因为如果你的函数使用xreg ,那么它需要它们进行预测。

So, in your code, h was simply ignored when you included xreg . 因此,在您的代码中,当您包含xreg时, h被忽略了。 Since you just used the values that you used to fit the model, it just gave you all the predictions for the same set of regressors as if they were in the future . 由于您刚刚使用了用于拟合模型的值,因此它只是为您提供了同一组回归量的所有预测, 就像将来一样

related https://stats.stackexchange.com/questions/110589/arima-with-xreg-rebuilding-the-fitted-values-by-hand相关https://stats.stackexchange.com/questions/110589/arima-with-xreg-rebuilding-the-fitted-values-by-hand

I read that arima in R is borked See Issue 3 and 4我读到 R 中的 arima 很无聊,请参阅第 3 期和第 4 期

https://www.stat.pitt.edu/stoffer/tsa4/Rissues.htm https://www.stat.pitt.edu/stoffer/tsa4/Rissues.htm

the xreg was suggested to derive the proper intercept.建议使用 xreg 导出正确的截距。

I'm using real statistics for excel to figure out what is the actual constant.我正在使用excel的真实统计数据来确定实际常数是多少。 I had a professor tell me you need to have a constant我有一位教授告诉我你需要有一个常数

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

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