Processing math: 100%

forecast::Arima Models

This vignette is intended to show the current ability to parse objects generated by forecast::Arima() by {equatiomatic}, thanks to contributions from Jay Sumners. The output uses notation from Hyndman with the exception of a and b for intercept and drift, respectively, being replace by μ and delta. To improve readability and reduce formula size, Arima functions are presented in Backshift (sometimes called lag) notation. forecast::Arima() will automatically generate either an Arima model or a linear regression model with Arima errors. We’ll address both in the examples below.

Basic Examples

ARIMA without Exogenous Regressors

Setup

First we need to generate a model. In this example, we won’t worry too much about whether or not the model is appropriate. Rather, we aim to illustrate that the corresponding equations are parsed correctly.

library(equatiomatic)
library(forecast)

# Build Arima (no regression)
simple_ts_mod <- Arima(simple_ts,
  order = c(1, 1, 1),
  seasonal = c(1, 0, 1),
  include.constant = TRUE
)

Extracting the equation

To extract the equation, we just call equatiomatic::extract_eq() on the resulting model object, equivalent to other model types. The model above outputs the following.

extract_eq(simple_ts_mod)

(1ϕ1B) (1Φ1B4) (1B)(ytδt)=(1+θ1B) (1+Θ1B4) εt

Regression with ARIMA Errors

Next, we’ll illustrate a slightly more complicated example that includes a linear regression. We’ll use the ts_reg_list object that is exported from {equatiomatic} to build up our data.

Setup

# Build Exogenous Regressors
xregs <- as.matrix(data.frame(
  x1 = ts_reg_list$x1 + 5,
  x2 = ts_reg_list$x2 * 5
))

# Build Regression Model
ts_reg_mod <- Arima(ts(ts_reg_list$ts_rnorm, freq = 4),
  order = c(1, 1, 1),
  seasonal = c(1, 0, 1),
  xreg = xregs,
  include.constant = TRUE
)

Extracting the equation

Despite the extra complexity of the model, the code to pull the equation remains equivalent.

extract_eq(ts_reg_mod)

letyt=y0+δt+β1x1t+β2x2t+ηtwhere(1ϕ1B) (1Φ1B4) (1B)ηt=(1+θ1B) (1+Θ1B4) εtwhereεtWN(0,σ2)

Working with other parts of {equatiomatic}

Although currently still in development, the other functionalities of extract_eq() for lm objects should generally work for forecast::Arima objects as well (e.g. interaction terms). Please let us know (preferably with a reproducible example) if you run into any issues.

Future Development

Development items on the docket include:

This is the first of (hopefully) most of the models in forecast being implemented in {equatiomatic}. Arima is one of the most used modeling techniques for time-series and, as such, got first treatment. There’s a lot we can do from here and I’m happy for any help or feedback from the community.