本文介绍了在传递给 R 中 Arima() 的 xreg 参数之前,我们是否需要对外生变量进行差分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 R 中的 ARIMAX 构建预测模型,并且需要一些有关如何在 xreg 参数中处理协变量的指导.

I am trying to build a forecasting model using ARIMAX in R and require some guidance on how covariates are handled in xreg argument.

我明白,auto.arima 函数在拟合模型时处理协变量的差异(来自训练期数据),我也不需要区分协变量来生成测试期(未来值)的预测.但是,在 R 中使用 Arima() 拟合模型时,使用自定义 (p, d, q) 和 (P, D, Q)[m] 值,d 或 D 大于 0,我们是否需要手动对协变量?如果我做差分,我会得到一个问题,即差分协变量矩阵的长度小于因变量的数据点数.

I understand that, auto.arima function takes care of differencing of covariates while fitting the model (from training period data) and I also don't need to difference the covariates for generating forecasts for test period (future values).However, while fitting the model using Arima() in R with custom (p, d, q) and (P, D, Q)[m] values with d or D greater than 0, do we need to manually do differencing of the covariates?If I do differencing, I get the issue that the differenced covariates matrix is of smaller length than the number of data points of the dependent variable.

应该如何处理?

  • 我是否应该按原样发送协变量矩阵,即没有差异?
  • 我是否应该进行差分但省略前几个观察,因为差分协变量数据不可用?
  • 我是否应该保留前几行的实际值,其中差异协变量值不可用,其余行具有差异值?
  • 如果我必须将标志变量 (1/0) 传递给 xreg 矩阵,我应该对这些变量进行差分还是将标志变量的实际值与剩余变量的差分值结合起来?

此外,在生成未来期间的预测时,我如何传递协变量值(按原样或差分后)?

Also, while generating the forecasts for future period, how do I pass the covariate values (as it is or after differencing)?

我正在使用以下代码:

ndiff <- ifelse(((pdq_order == "auto") || (PDQ_order == "auto")), ndiffs(ts_train_PowerTransformed), pdq_order[2])
nsdiff <- ifelse(((pdq_order == "auto") || (PDQ_order == "auto")), nsdiffs(ts_train_PowerTransformed), PDQ_order$order[2])

# Creating the appropriate covariates matrix after doing differencing

ifelse(nsdiff >= 1
      , ifelse(ndiff >= 1
                , xreg_differenced <- diff(diff(ts_CovariatesData_TrainingPeriod, lag =  PDQ_order$period, differences = nsdiff),  lag = 1, differences = ndiff)
                , xreg_differenced <- diff(ts_CovariatesData_TrainingPeriod , lag =  PDQ_order$period, differences = nsdiff)
                )
      , ifelse(ndiff >= 1
               , xreg_differenced <- diff( ts_CovariatesData,  lag = 1, differences = ndiff)
               , xreg_differenced <- ts_CovariatesData
 )

# Fitting the model
model_arimax <- Arima(ts_train_PowerTransformed, order = pdq_order, seasonal = PDQ_order, xreg = xreg_differenced))

# Generating Forecast for the test period
fit.test <- model_arimax %>% forecast(h=length(ts_test),
                                              xreg = as.data.frame(diff(diff(ts_CovariatesData_TestPeriod, lag =  PDQ_order$period, differences = nsdiff),  lag = 1, differences = ndiff))

请提出建议.

推荐答案

Arima 将区分响应变量和 xreg 变量,如顺序和季节性参数中指定的那样.您永远不需要自己进行差分.

Arima will difference both the response variable and the xreg variables as specified in the order and seasonal arguments. You should never need to do the differencing yourself.

这篇关于在传递给 R 中 Arima() 的 xreg 参数之前,我们是否需要对外生变量进行差分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 09:24