在传递给R中的Arima()的xreg参数之前,是否需要对外生变量进行差分处理? [英] Do we need to do differencing of exogenous variables before passing to xreg argument of Arima() in R?

查看:439
本文介绍了在传递给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函数在拟合模型时(根据训练期间的数据)照顾了协变量的差异,而且我也不需要为生成测试时期(未来值)的预测而对协变量进行差异化. 但是,在使用自定义(p,d,q)和(d,D大于0的(P,D,Q)[m]值)在R中使用Arima()拟合模型时,我们是否需要手动进行差分协变量? 如果进行差分,则会出现一个问题,即差分协变量矩阵的长度小于因变量的数据点数量.

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.

一个人应该如何处理呢?

How should one handle this?

  • 我应该按原样发送协变量矩阵吗?
  • 我应该进行差异分析,但忽略前几个观测值,因为这些观测值没有可用的协变量数据吗?
  • 我应该保留前几行的实际值,而前几行中的协变量差值不可用,而其余行的值都不同吗?
  • 如果我必须将标记变量(1/0)传递给xreg矩阵,我是否也应该对它们进行差分处理或将标记变量的实际值与其余变量的差分值绑定?
  • Should I send the covariate matrix as it is i.e. without differencing?
  • Should I do differencing but omit first few observations for which differenced covariate data is not available?
  • Should I keep the actual values for first few rows where difference covariate values are not available and remaining rows to have differenced values?
  • If I have to pass flag variables (1/0) to the xreg matrix, should I do differencing of those as well or cbind the actual values of flag variables with the differenced values of remaining variables?

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

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参数之前,是否需要对外生变量进行差分处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆