Residual Diagnostics
You have fitted a model and it produced forecasts. Before you stake a decision on it, one question towers
over the rest: did the model actually capture the structure in the data, or is there signal it
missed? The answer lives in the residuals — the one-step
forecast errors
\hat\varepsilon_t = x_t - \hat x_t left over after the fit. The governing idea
is simple and powerful: a model has extracted all the predictable structure exactly when
nothing predictable is left in the residuals — that is, when they look like
white noise. Residual
diagnostics are the battery of checks that put that claim on trial.
What "good residuals" means
White noise has three defining traits, and each becomes a thing to check:
- No autocorrelation. The residual autocorrelations
r_k \approx 0 at every lag k \ge 1 — any leftover
correlation is predictable structure the model failed to use.
- Constant variance. The spread of the residuals does not change over time or with the
level of the series.
- Approximate normality (needed for the
prediction intervals
to be valid), with no wild outliers.
Any residual pattern is the model talking to you: it is telling you what it left on the table. Structure in
the residual mean says the AR/MA orders are wrong; structure in the residual variance says
something else is going on entirely.
The residual correlogram — the first thing to plot
Plot the residual autocorrelations r_k against lag and overlay the
\pm 1.96/\sqrt{T} significance bands (for white noise, each
r_k is approximately normal with standard deviation
1/\sqrt{T}). The verdict is visual: all the stems should sit inside the
bands, with no more than the occasional chance excursion. The correlogram below is a clean bill of
health — every lag is comfortably within \pm 1.96/\sqrt{T}. A single spike
poking out at a meaningful lag (lag 1, or a seasonal lag like 12) is the tell-tale of a missed term.
Eyeballing individual lags has a flaw, though: with 20 lags plotted you expect about one to breach
a 95% band by pure chance. That is why we need a single test that judges all the lags together.
The Ljung–Box portmanteau test
A portmanteau test bundles many lags into one number. The
Ljung–Box statistic pools the first
h squared residual autocorrelations, each weighted to correct for small-sample
bias:
Q = T(T+2) \sum_{k=1}^{h} \frac{r_k^{\,2}}{T-k}.
- Null hypothesis H_0: the residuals are uncorrelated
(white noise) up to lag h.
- Under H_0, Q is approximately
\chi^2 distributed.
- The degrees of freedom are h - m, where
m is the number of estimated ARMA parameters (p + q)
— you must subtract them.
- A large Q (small p-value) rejects
H_0: the residuals are correlated and the model is inadequate.
This is a proper hypothesis test,
so read it the usual way: compare Q to the
\chi^2_{h-m} critical value (or just look at the p-value). We want to
fail to reject here — a comfortably small Q is the model passing.
Worked example — computing Q
Take T = 100 observations and the first three residual autocorrelations
r_1 = 0.08,\ r_2 = -0.05,\ r_3 = 0.11. Then T(T+2) = 100 \cdot 102 = 10200,
and
\sum_{k=1}^{3}\frac{r_k^2}{T-k} = \frac{0.0064}{99} + \frac{0.0025}{98} + \frac{0.0121}{97} \approx 2.15\times 10^{-4},
so Q \approx 10200 \times 2.15\times 10^{-4} \approx 2.19. If the model was an
AR(1) (m = 1 parameter), compare against
\chi^2_{3-1} = \chi^2_{2}, whose 5% critical value is
5.99. Since 2.19 < 5.99 we do not
reject: no evidence of leftover autocorrelation. The model passes this check.
Beyond correlation: normality and changing variance
Two more checks round out the diagnosis:
- Normality — a Q–Q plot of the residuals against normal quantiles
should track the diagonal; systematic bends in the tails reveal skew or heavy tails, which quietly
invalidate the Gaussian prediction intervals. A Jarque–Bera test formalises it.
- Constant variance — plot the residuals over time and look for volatility
clustering: calm stretches punctuated by bursts of large swings. The autocorrelations of the
squared residuals catch this even when the raw residuals look uncorrelated. Such
ARCH effects mean the mean model is fine but the variance is time-varying — the cue to
reach for a variance
model rather than re-tinkering with the AR/MA orders.
Two traps live here. First, a small Q means only that the residuals show no
detectable linear autocorrelation at the lags you tested — it is a failure to reject, not a proof
of correctness. A wrong model with white-noise residuals is still a wrong model: it can be missing a
non-linear dependence, have unstable parameters, or forecast badly out of sample. "Diagnostics passed" is
a necessary hurdle, never a certificate of truth. Second, remember the degrees-of-freedom
adjustment: the df are h - m after subtracting the
m = p + q fitted parameters, not h. Software that
applies Ljung–Box to residuals of an estimated model without subtracting parameters reports a
p-value that is too large — you will wave through models you should have rejected. Always check what your
tool used for the df.
The older Box–Pierce statistic was simply Q^{*} = T\sum_k r_k^2. It works
asymptotically, but in the finite samples we actually have it is biased — its true distribution sits below
the \chi^2 it is compared against, making it under-reject. Ljung and Box noticed
that the higher-lag autocorrelations r_k, estimated from fewer usable pairs
(only T-k of them), are more variable, and reweighted each term by
(T+2)/(T-k) to bring the statistic's finite-sample distribution much closer to
the nominal \chi^2. For large T the two agree; for the
modest samples of real applied work, the Ljung–Box correction is why it is the one everyone uses.