Autoregression

Learn how to use autoregression to forecast with time series data.

Understanding autoregression

Autoregression, as the name suggests, is a regression of a value over itself at some other moment. It means we look at the model like this:

xt=α+β1xt1+...+βnxtn+ϵx_t=\alpha+\beta_1x_{t-1}+...+\beta_n x_{t-n}+\epsilon

Where:

  • xtx_t is the variable we want to predict at a time, tt,xt1x_{t-1} is that same variable at time t1t-1, and so on.

  • α\alpha is a constant.

  • β1\beta_1 is the coefficient used for xt1x_{t-1}, β2\beta_2 is the coefficient used for xt2x_{t-2}, and so on.

  • ϵ\epsilon is the error term.

Intuitively, that model works almost as a weighted average between past observations, and the β\beta coefficients will give the weights for each time lag.

How far does nn go? That is up to us to choose depending on how far back in time we want to go to make our forecasts. We define an AR model as AR(n) depending on the value we want to set for nn. So an AR(2) model will forecast a value based on the two previous values.

Forecasting with autoregression

Fortunately, we don't have to do that regression on our own. We can use the same Python function, ARIMA, which we used to calculate the MA(n) model. To implement AR(2), let us set the MA parameter to zero and the AR parameter to two, in the ARIMA function.

Get hands-on with 1400+ tech skills courses.