ARIMA models

1. ARIMA models

ARIMA stands for Autoregressive Integrated Moving Average Models. Let's break that down into its parts.

2. ARIMA models

First, an Autoregressive model is simply a regression of a time series against the lagged values of that series. The last p observations are used as predictors in the regression equation. A Moving Average model can also be thought of as a regression. But instead of regressing against lagged observations, we regress against lagged errors. The last q errors are used as predictors in the equation.

3. ARIMA models

When we put these together we have an ARMA model, where the last p observations and the last q errors are all used as predictors in the equation. ARMA models can only work with stationary data. So we need to difference the data first. That brings me to the I in ARIMA which stands for Integrated. That is the opposite of differencing. If our time series needs to be differenced d times to make it stationary, then the resulting model is called an ARIMA(p,d,q) model. So to apply an ARIMA model to data, we need to decide on the value of p, d and q, and whether or not to include the constant c (the intercept in these equations). Fortunately, there is an automated procedure to do that.

4. US net electricity generation

Let's apply it to these data on annual US net electricity generation. From your experience of using differencing, you would probably guess this series needs one difference to make it stationary.

5. US net electricity generation

The auto-dot-arima function chooses the ARIMA model given the time series. In this case, it has selected an ARIMA(2,1,2) model with drift. So the data has been differenced once, and then 2 past observations and 2 past errors have been used in the equation. The drift here refers to the coefficient c. It is called a drift coefficient when there is differencing. The rest of the output tells you about the value of the parameters, and other model information. Notice that the AICc value is given, just as it was for ETS models. auto-dot-arima is selecting the values of p and q by minimizing the AICc value, just like the ets function did. However, you cannot compare an ARIMA AICc value with an ETS AICc value. You can only compare AICc values between models of the same class. You also can't compare AICc values between models with different amounts of differencing.

6. US net electricity generation

The resulting forecasts look pretty good don't they? The upward trend has been captured nicely.

7. How does auto.arima() work?

auto-dot-arima is using an algorithm I developed with Yeasmin Khandakar. It chooses the number of differences using a tool called a unit root test, and it selects the values of p and q by minimizing the AICc. The parameters are estimated using maximum likelihood estimation. One issue here is the model space is very large as p and q can take any non-negative values, so to save time we only try some of the possible models. That means it is possible that auto-dot-arima returns a model that is not actually the one with the minimum AICc value. Sometimes you can beat it, as you will see in a later exercise. There is a whole DataCamp course on ARIMA models, which I recommend you take if you want to delve deeper into this class of models.

8. Let's practice!

For now, let's get started using auto-dot-arima to do the work for us.