# arima

Class: regARIMA

Convert regression model with ARIMA errors to ARIMAX model

## Syntax

```ARIMAX = arima(Mdl) [ARIMAX,XNew] = arima(Mdl,Name,Value) ```

## Description

The `arima` object function converts a specified regression model with ARIMA errors (`regARIMA` model object) to the equivalent ARIMAX model (`arima` model object). To create an ARIMAX model directly, see `arima`.

`ARIMAX = arima(Mdl)` converts the univariate regression model with ARIMA time series errors `Mdl` to a model of type `arima` including a regression component (ARIMAX).

```[ARIMAX,XNew] = arima(Mdl,Name,Value)``` returns an updated regression matrix of predictor data using additional options specified by one or more `Name,Value` pair arguments.

## Input Arguments

 `Mdl` Regression model with ARIMA time series errors, as created by `regARIMA` or `estimate`.

### Name-Value Arguments

Specify optional pairs of arguments as `Name1=Value1,...,NameN=ValueN`, where `Name` is the argument name and `Value` is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose `Name` in quotes.

 `X` Predictor data for the regression component of `Mdl`, specified as the comma-separated pair consisting of `'X'` and a matrix. The last row of `X` contains the latest observation of each series. Each column of `X` is a separate time series.

## Output Arguments

 `ARIMAX` ARIMAX model equivalent to the regression model with ARIMA errors `Mdl`, returned as a model of type `arima`. `XNew` Updated predictor data matrix for the regression component of `ARIMAX`, returned as a matrix. `XNew` has the same number of rows as `X`. The last row of `XNew` contains the latest observation of each series. Each column of `XNew` is a separate time series. The number of columns of `XNew` is one plus the number of nonzero autoregressive coefficients in the difference equation of `Mdl`.

## Examples

expand all

Convert a regression model with ARMA(4,1) errors to an ARIMAX model using the `arima` converter.

Specify the regression model with ARMA(4,1) errors:

`$\begin{array}{l}{y}_{t}=1+0.5{X}_{t}+{u}_{t}\\ {u}_{t}=0.8{u}_{t-1}-0.4{u}_{t-4}+{\epsilon }_{t}+0.3{\epsilon }_{t-1},\end{array}$`

where ${\epsilon }_{t}$ is Gaussian with mean 0 and variance 1.

```Mdl = regARIMA('AR',{0.8, -0.4},'MA',0.3,... 'ARLags',[1 4],'Intercept',1,'Beta',0.5,... 'Variance',1)```
```Mdl = regARIMA with properties: Description: "Regression with ARMA(4,1) Error Model (Gaussian Distribution)" Distribution: Name = "Gaussian" Intercept: 1 Beta: [0.5] P: 4 Q: 1 AR: {0.8 -0.4} at lags [1 4] SAR: {} MA: {0.3} at lag [1] SMA: {} Variance: 1 ```

You can verify that the lags of the autoregressive terms are `1` and `4` in the `AR` row.

Generate random predictor data.

```rng(1); % For reproducibility T = 20; X = randn(T,1);```

Convert `Mdl` to an ARIMAX model.

```[ARIMAX,XNew] = arima(Mdl,'X',X); ARIMAX```
```ARIMAX = arima with properties: Description: "ARIMAX(4,0,1) Model (Gaussian Distribution)" Distribution: Name = "Gaussian" P: 4 D: 0 Q: 1 Constant: 0.6 AR: {0.8 -0.4} at lags [1 4] SAR: {} MA: {0.3} at lag [1] SMA: {} Seasonality: 0 Beta: [1 -0.8 0.4] Variance: 1 ```

The new `arima` model, `ARIMAX`, is

`${y}_{t}=0.6+{Z}_{t}\Gamma +0.8{y}_{t-1}-0.4{y}_{t-4}+{\epsilon }_{t}+0.3{\epsilon }_{t-1},$`

where

`${Z}_{t}\Gamma =\left[\begin{array}{ccc}0.5{x}_{1}& NaN& NaN\\ 0.5{x}_{2}& 0.5{x}_{1}& NaN\\ 0.5{x}_{3}& 0.5{x}_{2}& NaN\\ 0.5{x}_{4}& 0.5{x}_{3}& NaN\\ 0.5{x}_{5}& 0.5{x}_{4}& 0.5{x}_{1}\\ ⋮& ⋮& ⋮\\ {0.5}_{T}& 0.5{x}_{T-1}& 0.5{x}_{T-4}\end{array}\right]\left[\begin{array}{c}1\\ -0.8\\ 0.4\end{array}\right]$`

and ${x}_{j}$ is row j of `X`. Since the product of the autoregressive and integration polynomials is $\varphi \left(L\right)=\left(1-0.8L+0.4{L}^{4}\right),$ `ARIMAX.Beta` is simply `[1 -0.8 0.4]`. Note that the software carries over the autoregressive and moving average coefficients from `Mdl` to `ARIMAX`. Also, `Mdl.Intercept` = 1 and `ARIMAX.Constant` = (1 - 0.8 + 0.4)(1) = 0.6, i.e., the `regARIMA` model intercept and `arima` model constant are generally unequal.

Convert a regression model with seasonal ARIMA errors to an ARIMAX model using the `arima` converter.

Specify the regression model with $ARIMA\left(2,1,1\right)×{\left(1,1,0\right)}_{2}$ errors:

`$\begin{array}{c}{y}_{t}={X}_{t}\left[\begin{array}{c}-2\\ 1\end{array}\right]+{u}_{t}\\ \left(1-0.3L+0.15{L}^{2}\right)\left(1-L\right)\left(1-0.2{L}^{2}\right)\left(1-{L}^{2}\right){u}_{t}=\left(1+0.1L\right){\epsilon }_{t},\end{array}$`

where ${\epsilon }_{t}$ is Gaussian with mean 0 and variance 1.

```Mdl = regARIMA('AR',{0.3, -0.15},'MA',0.1,... 'ARLags',[1 2],'SAR',0.2,'SARLags',2,... 'Intercept',0,'Beta',[-2; 1],'Variance',1,'D',1,... 'Seasonality',2)```
```Mdl = regARIMA with properties: Description: "Regression with ARIMA(2,1,1) Error Model Seasonally Integrated with Seasonal AR(2) (Gaussian Distribution)" Distribution: Name = "Gaussian" Intercept: 0 Beta: [-2 1] P: 7 D: 1 Q: 1 AR: {0.3 -0.15} at lags [1 2] SAR: {0.2} at lag [2] MA: {0.1} at lag [1] SMA: {} Seasonality: 2 Variance: 1 ```

Generate predictor data.

```rng(1); % For reproducibility T = 20; X = randn(T,2);```

Convert `Mdl` to an ARIMAX model.

```[ARIMAX,XNew] = arima(Mdl,'X',X); ARIMAX```
```ARIMAX = arima with properties: Description: "ARIMAX(2,1,1) Model Seasonally Integrated with Seasonal AR(2) (Gaussian Distribution)" Distribution: Name = "Gaussian" P: 7 D: 1 Q: 1 Constant: 0 AR: {0.3 -0.15} at lags [1 2] SAR: {0.2} at lag [2] MA: {0.1} at lag [1] SMA: {} Seasonality: 2 Beta: [1 -1.3 -0.75 1.41 -0.34 -0.08 0.09 -0.03] Variance: 1 ```

`Mdl.Beta` has length 2, but `ARIMAX.Beta` has length 8. This is because the product of the autoregressive and integration polynomials, $\varphi \left(L\right)\left(1-L\right)\Phi \left(L\right)\left(1-{L}^{s}\right)$, is

`$1-1.3L-0.75{L}^{2}+1.41{L}^{3}-0.34{L}^{4}-0.08{L}^{5}+0.09{L}^{6}-0.03{L}^{7}.$`

You can see that when you add seasonality, seasonal lag terms, and integration to a model, the size of `XNew` can grow quite large. A conversion such as this might not be ideal for analyses involving small sample sizes.

## Algorithms

Let X denote the matrix of concatenated predictor data vectors (or design matrix) and β denote the regression component for the regression model with ARIMA errors, `Mdl`.

• If you specify `X`, then `arima` returns `XNew` in a certain format. Suppose that the nonzero autoregressive lag term degrees of `Mdl` are 0 < a1 < a2 < ...< P, which is the largest lag term degree. The software obtains these lag term degrees by expanding and reducing the product of the seasonal and nonseasonal autoregressive lag polynomials, and the seasonal and nonseasonal integration lag polynomials

`$\varphi \left(L\right){\left(1-L\right)}^{D}\Phi \left(L\right)\left(1-{L}^{s}\right).$`

• The first column of `XNew` is .

• The second column of `XNew` is a sequence of a1 `NaN`s, and then the product ${X}_{{a}_{1}}\beta ,$ where ${X}_{{a}_{1}}\beta ={L}^{{a}_{1}}X\beta .$

• The jth column of `XNew` is a sequence of aj `NaN`s, and then the product ${X}_{{a}_{j}}\beta ,$ where ${X}_{{a}_{j}}\beta ={L}^{{a}_{j}}X\beta .$

• The last column of `XNew` is a sequence of ap `NaN`s, and then the product ${X}_{p}\beta ,$ where ${X}_{p}\beta ={L}^{p}X\beta .$

Suppose that `Mdl` is a regression model with ARIMA(3,1,0) errors, and ϕ1 = 0.2 and ϕ3 = 0.05. Then the product of the autoregressive and integration lag polynomials is

`$\left(1-0.2L-0.05{L}^{3}\right)\left(1-L\right)=1-1.2L+0.02{L}^{2}-0.05{L}^{3}+0.05{L}^{4}.$`

This implies that `ARIMAX.Beta` is `[1 -1.2 0.02 -0.05 0.05]` and `XNew` is

`$\left[\begin{array}{ccccc}{x}_{1}\beta & NaN& NaN& NaN& NaN\\ {x}_{2}\beta & {x}_{1}\beta & NaN& NaN& NaN\\ {x}_{3}\beta & {x}_{2}\beta & {x}_{1}\beta & NaN& NaN\\ {x}_{4}\beta & {x}_{3}\beta & {x}_{2}\beta & {x}_{1}\beta & NaN\\ {x}_{5}\beta & {x}_{4}\beta & {x}_{3}\beta & {x}_{2}\beta & {x}_{1}\beta \\ ⋮& ⋮& ⋮& ⋮& ⋮\\ {x}_{T}\beta & {x}_{T-1}\beta & {x}_{T-2}\beta & {x}_{T-3}\beta & {x}_{T-4}\beta \end{array}\right],$`

where xj is the jth row of X.

• If you do not specify `X`, then `arima` returns `XNew` as an empty matrix without rows and one plus the number of nonzero autoregressive coefficients in the difference equation of `Mdl` columns.