Skip to content

Autoregressive models and forecasting

Today’s value is a weighted sum of earlier values plus fresh noise; forecasts lean back to the mean while their uncertainty fans out.

Helps to know first
This topic

First, the picture

A series ends on a high value. Forecast the next steps, and watch the forecast lean back while its interval opens like a fan.

Why forecasts fan out

A series where each value is 0.8 times the last plus noise, ending at 5, and its forecast 20 steps ahead (seeds 10200, 10201).

The series ends at 5, well above its mean of 0. Where will it go next?

coefficient φ
0.80
half-width, 1 step
1.96
half-width, 20 steps
3.27
futures inside
–

Predict first. Looking further ahead, what will the 95 % interval of the forecast do?

0.00 / 11.60 s
Describe this picture

One panel: the last 60 of 100 values of a series (seed 10200) in which each value is 0.8 times the one before plus fresh noise of variance 1, ending at 5, well above its mean of 0, which is a dashed line. Before the clip a question asks what the 95 % interval of the forecast does as it looks further ahead: keeps opening, stops opening at some width, or narrows. A tap picks one and starts the clip. In the clip, over 8 seconds, a forecast line leaves the series and decays towards 0 over 20 steps, and a shaded 95 % interval opens around it as a fan, widest at the right; its half-width grows from 1.96 one step ahead towards a limit of 3.27, labelled at the end. Then 24 of 1000 simulated futures (seed 10201) appear as faint lines through the fan, and a readout gives the share of all their points that fall inside it: 95.7 %. Readouts also give the coefficient and the half-widths one and 20 steps ahead. After the clip a slider sets the coefficient from 0 to 1 in steps of 0.05; at 1 the fan keeps opening.

A forecast and its interval

Before the clip you guessed. The fan opens fast at first and then stops: its half-width creeps up towards 3.27 and never passes it. Each step ahead adds new noise to the uncertainty, but the series also forgets, and the two balance. In the clip, 95.7 % of the points of 1000 simulated futures fell inside the fan, against the nominal 95 %.

The forecast itself leans back to the mean. The series is high now, and it remembers that, but its memory fades by a factor of 0.8 a step, so the forecast fades too.

After the clip, drag the coefficient to 1. The series becomes a random walk, which never forgets: the forecast stays at 5, and the fan keeps opening, wider and wider, as the square root of the horizon.

The autoregressive model

The picture’s series is the AR(1) series of Time series and autocorrelation. Allowing more of the past gives the autoregressive model of order pp, AR(pp):

Xk=ϕ1Xk−1+ϕ2Xk−2+⋯+ϕpXk−p+Vk,X_k=\phi_1X_{k-1}+\phi_2X_{k-2}+\dots+\phi_pX_{k-p}+V_k,

with VkV_k white noise of variance σV2\sigma_V^2 and coefficients ϕ1,…,ϕp\phi_1,\dots,\phi_p. Today’s value is a weighted sum of recent values plus a fresh surprise.

The model is stationary when its memory fades rather than builds up. For AR(1) that means ∣ϕ∣<1\lvert\phi\rvert<1. For AR(pp) it means every root of 1−ϕ1z−⋯−ϕpzp1-\phi_1z-\dots-\phi_pz^p lies outside the unit circle. A coefficient of 1.05 makes AR(1) explode, not settle.

Fitting the model

By regression. An AR(pp) model is a regression of each value on its pp predecessors, so Linear regression fits it: least squares of xkx_k on xk−1,…,xk−px_{k-1},\dots,x_{k-p}.

By the autocorrelation. Multiply the model by Xk−ℓX_{k-\ell} and take means. For AR(2), with ρℓ\rho_\ell short for ρX[ℓ]\rho_X[\ell], lags 1 and 2 give the Yule–Walker equations:

[1ρ1ρ11][ϕ1ϕ2]=[ρ1ρ2].\begin{bmatrix}1&\rho_1\\\rho_1&1\end{bmatrix}\begin{bmatrix}\phi_1\\\phi_2\end{bmatrix}=\begin{bmatrix}\rho_1\\\rho_2\end{bmatrix}.

Put in the sample autocorrelations and solve for the coefficients. The matrix is symmetric with constant diagonals, the structure of Positive definite matrices.

Partial autocorrelation

How do you pick the order pp? The autocorrelation of an AR(1) series does not stop at lag 1; it fades like ϕℓ\phi^\ell. A better tool is the partial autocorrelation at lag ℓ\ell: the last coefficient of the best AR(ℓ\ell) fit. It measures what lag ℓ\ell adds once the lags in between are accounted for. For an AR(pp) series it is 0 beyond lag pp: it cuts off, and the cut-off shows the order. Criteria such as the AIC of Overfitting and model choice make the choice a rule.

Forecasts and their uncertainty

For AR(1) about a mean of 0, the forecast hh steps ahead of the last value xnx_n is

ϕh xn,\phi^h\,x_n,

which decays to the mean. Its error collects the noise of the hh steps not yet seen, each faded by the steps after it, so its variance is

σV2 1−ϕ2h1−ϕ2,\sigma_V^2\,\frac{1-\phi^{2h}}{1-\phi^2},

rising towards the series’ own variance σX2=σV2/(1−ϕ2)\sigma_X^2=\sigma_V^2/(1-\phi^2): far ahead, the forecast knows no more than the mean. For a random walk, ϕ=1\phi=1, the variance is hσV2h\sigma_V^2 and grows without limit.

Watch out

A model that fits the past well does not forecast far ahead well. For a stationary model the forecast returns towards the mean, faster the weaker its memory, and the interval widens to the series’ whole spread.

The same model as a filter

An AR(1) series is white noise passed through a one-pole filter. Its spectrum shows the same memory in frequency.

Slow wandering, seen as a spectrum

The power of the series at each frequency: white noise through a one-pole filter with coefficient 0.8.

The series as white noise through a one-pole filter: its power at each frequency Ω.

at Ω = 0
25
at Ω = π
–
ratio
–
0.00 / 7.30 s
Describe this picture

One panel: the spectrum σV2/∣1−ϕe−jΩ∣2\sigma_V^2/\lvert1-\phi e^{-j\Omega}\rvert^2 of the AR(1) series with coefficient 0.8 and noise variance 1, drawn in decibels against frequency Ω\Omega from 0 to π\pi radians per sample. The clip traces it from left to right, then marks both ends: 25 (14.0 dB) at Ω=0\Omega=0 and 0.309 (−5.1 dB) at Ω=π\Omega=\pi, with a dashed bracket for the ratio of 81, or 19.1 dB. Readouts give both values and the ratio. The panel has a play button and no other control.

Slow swings dominate: the series’ memory, 0.8ℓ0.8^\ell in the lag domain, is the same fact as its power at low frequencies.

Moving-average models, in one line

A different model mixes recent noise instead of recent values: the moving-average model MA(1), Xk=Vk+θVk−1X_k=V_k+\theta V_{k-1}, has ρX[1]=θ/(1+θ2)\rho_X[1]=\theta/(1+\theta^2) and no autocorrelation beyond lag 1. Combining both kinds gives ARMA models.

Worked example

1. Fitting the short series. For the series 1,2,4,5,4,3,2,31,2,4,5,4,3,2,3 of Time series and autocorrelation, with deviations dkd_k from the mean 3, the regression of each deviation on the one before gives

ϕ^=∑k=17dkdk+1∑k=17dk2=512=0.4167,\hat\phi=\frac{\sum_{k=1}^{7}d_kd_{k+1}}{\sum_{k=1}^{7}d_k^2}=\frac{5}{12}=0.4167,

the same as ρ^X[1]\hat\rho_X[1], because the last deviation, d8d_8, is 0.

2. Forecasting. With ϕ=0.8\phi=0.8, σV=1\sigma_V=1 and xn=5x_n=5:

Steps aheadForecastError variance95 % half-width
14.011.96
23.21.642.51
32.562.04962.81
42.0482.31172.98
51.63842.47953.09
far ahead02.77783.27

At 12 steps ahead the half-width is 3.26, nearly at its limit. With ϕ=0.5\phi=0.5 the limit is lower, 2.26. A random walk has a half-width of 1.96×2=3.921.96\times2=3.92 at 4 steps and 6.796.79 at 12, still growing.

3. Yule–Walker for AR(2). Take ϕ1=0.5\phi_1=0.5 and ϕ2=0.3\phi_2=0.3, a stationary pair. Its autocorrelations are ρ1=ϕ1/(1−ϕ2)=0.7143\rho_1=\phi_1/(1-\phi_2)=0.7143 and ρ2=ϕ1ρ1+ϕ2=0.6571\rho_2=\phi_1\rho_1+\phi_2=0.6571. Solving the two equations with these values returns (0.5, 0.3)(0.5,\ 0.3): the determinant is 1−ρ12=0.48981-\rho_1^2=0.4898, ϕ1=ρ1(1−ρ2)/0.4898=0.5\phi_1=\rho_1(1-\rho_2)/0.4898=0.5 and ϕ2=(ρ2−ρ12)/0.4898=0.3\phi_2=(\rho_2-\rho_1^2)/0.4898=0.3. The partial autocorrelation is 0.3 at lag 2 and 0 at lag 3.

4. A moving average. MA(1) with θ=0.5\theta=0.5 has ρX[1]=0.5/1.25=0.4\rho_X[1]=0.5/1.25=0.4; no MA(1) gets above 0.5, reached at θ=1\theta=1.

Try it yourself. Two steps ahead from xn=5x_n=5 with ϕ=0.8\phi=0.8, the forecast is 3.2. A coefficient of 1.05 is not stationary. The partial autocorrelation of an AR(2) series is 0 beyond lag 2.

Where you’ll meet this

Forecasting. Demand, electricity load and temperature are forecast with autoregressive models and their fans; planners use the fan, not just the line.

Speech coding. Linear prediction fits an AR model to each short frame of speech, and sends the coefficients and the small prediction error instead of the samples.

Tracking. The Kalman filter often models the motion it tracks as an autoregressive process, predicting one step ahead and correcting with each measurement.

In signal processing · linear prediction

Signal processing writes the same model as x[n]=−∑kakx[n−k]+v[n]x[n]=-\sum_ka_kx[n-k]+v[n], so ak=−ϕka_k=-\phi_k. The partial autocorrelation at lag mm is then minus the reflection coefficient kmk_m of the Levinson–Durbin recursion in Linear prediction, and a stationary AR model is a stable all-pole filter, as in Stability and causality.

Reference card

QuantityFormulaNotes
AR(pp)Xk=ϕ1Xk−1+⋯+ϕpXk−p+VkX_k=\phi_1X_{k-1}+\dots+\phi_pX_{k-p}+V_kregression on the past
Stationary AR(1)∣ϕ∣<1\lvert\phi\rvert<1AR(pp): roots outside the unit circle
Yule–Walkerautocorrelations in, coefficients outa symmetric Toeplitz system
Partial autocorrelationlast coefficient of the best AR(ℓ\ell) fit0 beyond lag pp
AR(1) forecastϕhxn\phi^hx_nleans back to the mean
Forecast error varianceσV2(1−ϕ2h)/(1−ϕ2)\sigma_V^2(1-\phi^{2h})/(1-\phi^2)tends to σX2\sigma_X^2
Random walkhσV2h\sigma_V^2the fan never stops opening
MA(1)ρX[1]=θ/(1+θ2)\rho_X[1]=\theta/(1+\theta^2)0 beyond lag 1

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look