A blog by Rob J Hyndman 

Twitter Gplus RSS

The ARIMAX model muddle

Published on 4 October 2010

There is often con­fu­sion about how to include covari­ates in ARIMA mod­els, and the pre­sen­ta­tion of the sub­ject in var­i­ous text­books and in R help files has not helped the con­fu­sion. So I thought I’d give my take on the issue. To keep it sim­ple, I will only describe non-​​seasonal ARIMA mod­els although the ideas are eas­ily extended to include sea­sonal terms. I will include only one covari­ate in the mod­els although it is easy to extend the results to mul­ti­ple covari­ates. And, to start with, I will  assume the data are sta­tion­ary, so we only con­sider ARMA models.

Let the time series be denoted by y_1,\dots,y_n. First, we will define an ARMA(p,q) model with no covariates:

    \[ y_t = \phi_1 y_{t-1} + \cdots + \phi_p y_{t-p} - \theta_1 z_{t-1} - \dots - \theta_q z_{t-q} + z_t, \]

where z_t is a white noise process (i.e., zero mean and iid).

ARMAX mod­els

An ARMAX model sim­ply adds in the covari­ate on the right hand side:

    \[ y_t = \beta x_t + \phi_1 y_{t-1} + \cdots + \phi_p y_{t-p} - \theta_1 z_{t-1} - \dots - \theta_q z_{t-q} + z_t \]

where x_t is a covari­ate at time t and \beta is its coef­fi­cient. While this looks straight-​​forward, one dis­ad­van­tage is that the covari­ate coef­fi­cient is hard to inter­pret. The value of \beta is not the effect on y_t when the x_t is increased by one (as it is in regres­sion). The pres­ence of lagged val­ues of the response vari­able on the right hand side of the equa­tion mean that \beta can only be inter­preted con­di­tional on the value of pre­vi­ous val­ues of the response vari­able, which is hardly intuitive.

If we write the model using back­shift oper­a­tors, the ARMAX model is given by

    \[ \phi(B)y_t = \beta x_t + \theta(B)z_t \qquad\text{or}\qquad y_t = \frac{\beta}{\phi(B)}x_t + \frac{\theta(B)}{\phi(B)}z_t, \]

where \phi(B)=1-\phi_1B -\cdots - \phi_pB^p and \theta(B)=1-\theta_1B-\cdots-\theta_qB^q. Notice how the AR coef­fi­cients get mixed up with both the covari­ates and the error term.

Regres­sion with ARMA errors

For this rea­son, I pre­fer to use regres­sion mod­els with ARMA errors, defined as follows.

    \begin{align*} y_t &= \beta x_t + n_t\\ n_t &= \phi_1 n_{t-1} + \cdots + \phi_p n_{t-p} - \theta_1 z_{t-1} - \dots - \theta_q z_{t-q} + z_t \end{align*}

In this case, the regres­sion coef­fi­cient has its usual inter­pre­ta­tion. There is not much to choose between the mod­els in terms of fore­cast­ing abil­ity, but the addi­tional ease of inter­pre­ta­tion in the sec­ond one makes it attractive.

Using back­shift oper­a­tors, this model can be writ­ten as

    \[ y_t = \beta x_t + \frac{\theta(B)}{\phi(B)}z_t. \]

Trans­fer func­tion models

Both of these mod­els can be con­sid­ered as spe­cial cases of trans­fer func­tion mod­els, pop­u­lar­ized by Box and Jenkins:

    \[ y_t = \frac{\beta(B)}{v(B)} x_t + \frac{\theta(B)}{\phi(B)}z_t. \]

This allows for lagged effects of covari­ates (via the \beta(B) oper­a­tor) and for decay­ing effects of covari­ates (via the v(B) operator).

Some­times these are called “dynamic regres­sion mod­els”, although dif­fer­ent books use that term for dif­fer­ent models.

The method for select­ing the orders of a trans­fer func­tion model that is described in Box and Jenk­ins is cum­ber­some and dif­fi­cult, but con­tin­ues to be described in text­books. A much bet­ter pro­ce­dure is given in Pankratz (1991), and repeated in my 1998 fore­cast­ing text­book.

Non-​​stationary data

For ARIMA errors, we sim­ply replace \phi(B) with \nabla^d\phi(B) where \nabla=(1-B) denotes the dif­fer­enc­ing oper­a­tor. Notice that this is equiv­a­lent to dif­fer­enc­ing both y_t and x_t before fit­ting the model with ARMA errors. In fact, it is nec­es­sary to dif­fer­ence all vari­ables first as esti­ma­tion of a model with non-​​stationary errors is not con­sis­tent and can lead to “spu­ri­ous regression”.

R func­tions

The arima() func­tion in R (and Arima() and auto.arima() from the fore­cast pack­age) fits a regres­sion with ARIMA errors. Note that R reverses the signs of the mov­ing aver­age coef­fi­cients com­pared to the stan­dard para­me­ter­i­za­tion given above.

The arimax() func­tion from the TSA pack­age fits the trans­fer func­tion model (but not the ARIMAX model). This is a new pack­age and I have not yet used it, but it is nice to finally be able to fit trans­fer func­tion mod­els in R. Some­time I plan to write a func­tion to allow auto­mated order selec­tion for trans­fer func­tions as I have done with auto.arima() for regres­sion with ARMA errors (part of the fore­cast pack­age)


Related Posts:


 
25 Comments  comments 
  • http://www.twitter.com/BrockTibert Brock

    Hi Rob,

    I just started out in time series and R, and recently I have tried to fit a uni­vari­ate time series. The basic process was that I con­verted my data to a ts object and fit a model using auto.arima to a weekly dataset. A plot of my data shows my data are most likely non-​​stationary, but based on the post above, and if I under­stand this cor­rectly, I need to dif­fer­ence my dataset first? When look­ing at the help, it looks like the default option is to feed auto.arima a non-​​stationary process. I am new to time series and may be bit­ing off more than I can chew in some cases, but I just want to make sure I learn as much as I can. Thanks in advance.

    • http://robjhyndman.com Rob J Hyndman

      No, you do not need to dif­fer­ence the data first. auto.arima() will deter­mine the order of dif­fer­enc­ing required using a unit-​​root test.

      • Diet­mar

        Hi Rob,

        how can I rec­on­cile the state­ment in the arti­cle “The ARIMAX model muddle”

        Con­se­quently, you should do your own dif­fer­enc­ing when required.”

        with the statement

        No, you do not need to dif­fer­ence the data first. auto.arima() will
        deter­mine the order of dif­fer­enc­ing required using a unit-​​root test.”

        Thanks a lot!!

        Diet­mar

        • http://robjhyndman.com Rob J Hyndman

          Brock was try­ing to fit a uni­vari­ate ARIMA model with no regres­sors. In that case, auto.arima() han­dles the dif­fer­enc­ing with­out a prob­lem. In the arti­cle, I was talk­ing about regres­sion with ARIMA errors. In that sit­u­a­tion (where there is at least one regres­sor), dif­fer­enc­ing should be done by hand if required, because the under­ly­ing ‘arima()‘ code (not my code) does not do it correctly.

  • http://www.twitter.com/BrockTibert Brock

    Per­fect thanks Rob!

  • saugat gurung

    dear Rob,
    do i need to do log trans­for­ma­tion (if data requires) to use auto.arima() func­tion. as the func­tion does the dif­fer­enc­ing itself. what if my data requires log transformation,where should i apply auto.arima in the orig­i­nal data or the log trans­formed data.

    • http://robjhyndman.com Rob J Hyndman

      In v3 of the fore­cast pack­age, you can do the log trans­for­ma­tion inside the auto.arima() function:

      fit <- auto.arima(x,lambda=0)
      plot(forecast(fit))

      The lambda indi­cates a Box-​​Cox trans­for­ma­tion and lambda=0 cor­re­sponds to a log­a­rithm. The fore­cast func­tion will rec­og­nize that a log has been applied and back-​​transform the fore­casts appropriately.

      • saugat gurung

        thank you very much, i find it very helpful.

  • Hervé

    dear Rob, I have some prob­lem with the use of ARIMA with covari­ate in R. For exam­ple how can I esti­mate in R an ARIMA(2,01) included a covari­ate with a time lag of 20s for exam­ple. Thanks
    Hervé.

    • http://robjhyndman.com Rob J Hyndman

      Let x be the lagged covari­ate. Then
      fit <- Arima(y, xreg=x, order=c(2,0,1))

  • Wolf3616

    I find this arti­cle very help­ful! thank you!

  • Wolf3616

    Dear Rob,

    I gen­er­ate a syn­thetic series using ARX model, using the arima.sim() func­tion, and adding a con­stant to it (i.e. Yt=C+arima.sim()) to have an Expectation/​mean of the ‘obser­va­tion’ Yt~1000. later I ‘esti­mate’ the para­me­ters using an arima() func­tion for the gen­er­ated series. The esti­mates of the poly­no­mi­als and mean turn out with small s.e. val­ues to the ‘true’ para­me­ters which I believe, based on your arti­cle, that the arima() fits a regres­sion with arima errors. Is my assump­tion is true?

    My other ques­tion is, I use a ran­dom vari­ables gen­er­ated from a ‘GEV dis­tri­b­u­tion’ for the ‘inno­va­tion’ (for the arima.sim() func­tion) to gen­er­ate the ‘obser­va­tion’, Yt, in hope that a sim­i­lar dis­tri­b­u­tion type (i.e. GEV) is likely to be gen­er­ated for the Yt. as far as I had sim­u­lated, the ‘obser­va­tion’ tend to be skewed and non-​​normal. Am I wrong to pre­dict that?

    • http://robjhyndman.com Rob J Hyndman

      1. Yes, arima() fits a regres­sion with ARIMA errors.
      2. GEV errors does not lead to a GEV mar­ginal dis­tri­b­u­tion. I don’t know what error dis­tri­b­u­tion would lead to a GEV mar­ginal distribution.

  • Wolf3616

    Thank you for your answer! Really appre­ci­ate it!

  • Mohamed

    Dear Rob,

    i have two vari­ables, one response vari­able and the other is covari­ate, i would like to use ari­max in r and i’m con­fused if i should put the covari­ate in xreg or in x transf and if i would like to esti­mate the rela­tion between them at dif­fer­ent lags, how can i apply this in R?!! thanks for help in advance.

  • Shea Parkes

    Might as well dig up an old thread. This is very solid infor­ma­tion, I’m cur­rently explor­ing trans­fer func­tions and their use for interventions.

    I’m unable to repro­duce the dif­fer­enc­ing error in the base arima() func­tion of R-​​stats now (when using an xreg). Is this still a prob­lem or was it even­tu­ally fixed?

    If it was fixed, you might want to toss a note into the post since google pager­anks this post rather high for “ARIMAX” key words.

    • http://robjhyndman.com Rob J Hyndman

      The bug still exists. It doesn’t return an error. The prob­lem is the method of esti­ma­tion used is incon­sis­tent. Dif­fer­enc­ing should be done first so all vari­ables are sta­tion­ary before estimation.

  • Vinayraj

    Hi Mr.Hyndman.….I have used the auto.arima func­tion in fore­cast pack­age with causal vari­ables and found that for non sta­tion­ary data, the para­me­ter co effi­cient esti­mates are not correct…as per your sug­ges­tion, i did dif­fer­enc­ing of the time series before feed­ing to auto.arima…however how do i use the above arima model and the dif­fer­enced series while gen­er­at­ing the forecast?

    • http://robjhyndman.com Rob J Hyndman

      I don’t know what you mean “not cor­rect” as auto.arima does fit the model cor­rectly. It is arima() that is incorrect.

  • Mar­cel

    Dear Rob,

    thank you for writ­ing this arti­cle! I was won­der­ing if you have come across a package/​method for fit­ting ARIMAX mod­els for ensem­ble traces, e.g.

    Over a period of 30 days I record 3 mea­sures A,B,C every minute between 12am to 3pm. I assume that A(t) = alpha_​1 A(t-1) + … + alpha_​n A(t-n) + beta_​1 B(t-1) + … + gamma_​1 C(t-1) + … + Z(t), while B and C do not depend on A. I want to esti­mate the alpha’s, beta’s and gamma’s such that the errors min­imise the sum of the pre­dic­tion error over all days.

    Gen­er­ally I have found quite few tools/​libraries for gen­eral ARIMAX fit­ting, but there seems to be lit­tle infor­ma­tion about how to do this when I have mul­ti­ple non-​​consecutive time series of the same process.

  • Cana­dian Tom

    Hi Rob,

    Thanks for this. This was one of the clear­est expla­na­tions I could find on the web. If you don’t mind, I have a ques­tion to do with non-​​stationary data. It was my under­stand­ing that it’s OK to cal­i­brate an OLS model with non-​​stationary time-​​series data, as long as the resid­u­als are a sta­tion­ary time series. This would imply that they ‘co-​​integrate’. So if I can cal­i­brate an ARMAX model with a cou­ple AR lags that pro­duces a resid­u­als series with no auto­cor­re­la­tion, in gen­eral, that’s OK… right? Or, as you said, do I need to difference?

  • Pingback: cointegration – mixing S & NS regressors; how to test for stationarity; so on | Question and Answer