- Introduced by
- Greta Ljung & George Box
- Year
- 1978
- Type
- Portmanteau goodness-of-fit test
- Family
- Autocorrelation
What does it do?
The Ljung-Box Q test, proposed by Ljung and Box (1978), is a portmanteau test of whether a group of residual autocorrelations up to lag h is jointly zero.
It is mainly used as a post-estimation diagnostic for fitted time series models, such as ARIMA models, to check whether temporal dependence remains in the residuals. The null hypothesis is no autocorrelation up to lag h.
The intuition behind the method
After fitting a time series model, ideal residuals should look like white noise — no structure, no memory. The Ljung-Box test asks: do the residuals still correlate with their own past values at any lag up to some chosen maximum? Rather than checking each lag one by one, it combines all autocorrelations up to lag h into a single Q statistic. A large Q means the residuals are not random enough, signaling that the model has failed to capture some temporal dynamics.
History
As reported in Ljung and Box (1978), Box and Pierce (1970) proposed the overall test for lack of fit in autoregressive-moving average models, based on the sum of squared residual autocorrelations. Ljung and Box showed that a simple modification of this test gives a substantially improved approximation to the chi-squared distribution. They also considered its power and its robustness when the innovations are non-normal, and proposed similar modifications for transfer function-noise models. The modified statistic is the form now usually called the Ljung-Box test. The test is sometimes called simply the Box test, but the Ljung-Box name is preferred because the test is based on a joint paper of Ljung and Box.
When to use it
Use the Ljung-Box test after estimating a time series model to check whether its residuals are free of serial dependence, for example after fitting an ARIMA model. It applies to model residuals; applied to the raw series, it will typically reject H₀ whenever the series is serially dependent and so says little about model adequacy. Its asymptotic chi-squared distribution requires a reasonably large sample, and the test is less reliable in very small samples. No universal rule exists for choosing h. Informal defaults such as h = min(10, n/5) are sometimes used in practice, but they are not validated for this test, so results should be reported for several values of h. If the fitted model has estimated parameters beyond AR and MA orders, the df rule on this page does not cover them and the adjustment should be checked before interpreting the p-value. For regression residuals, the Breusch-Godfrey test is the usual alternative, and the Box-Pierce test is an older statistic with poorer small-sample accuracy.
Limitations and considerations
- Performance depends on the chosen maximum lag h; no universally optimal rule exists for selecting h.
- The chi-squared reference distribution is an asymptotic approximation. It is less reliable in very small samples, and its behaviour under non-normal innovations should be checked.
- The reference distribution assumes residuals from a correctly specified model. Misspecification in other respects, such as non-normal innovations or changing variance, can distort the p-value even when no autocorrelation is present.
- Not designed as a primary specification test for regression models; the Breusch-Godfrey test is more appropriate in that context.
- Only the sample autocorrelations up to lag h are tested, so serial dependence at longer lags, or dependence not reflected in linear autocorrelations, may go undetected.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Tests joint significance of multiple autocorrelations simultaneously, avoiding the multiple-testing problem of individual lag tests.
- The finite-sample modification gives a substantially improved chi-squared approximation compared with the original Box-Pierce statistic.
- Degrees of freedom are simple to adjust for the AR and MA orders of an ARIMA model.
- Available in common statistical software; the R implementation is shown in the practical note.
Applications
- Validating ARIMA model residuals in economic forecasting to confirm that no autocorrelation structure remains unexplained.
- Checking residuals of a fitted conditional-mean model before modelling volatility, so that remaining serial dependence does not contaminate the volatility analysis.
- Applying the test to squared residuals of a conditional-mean model to detect volatility clustering before fitting an ARCH or GARCH model.
- Quality control of sensor or process data where temporal independence of residuals is required for valid inference.
- Testing for remaining serial correlation in macroeconomic VAR residuals before drawing structural conclusions.
- Diagnostic check in academic time series studies to confirm that model residuals show no remaining serial dependence.
How it works
How it works
First, compute the sample autocorrelation function (ACF) of the model residuals at each lag k from 1 to h. Each autocorrelation coefficient measures the linear association between residuals separated by k time periods.
Formula
\hat{\rho}_k = \frac{\sum_{t=k+1}^{n} \hat{e}_t \hat{e}_{t-k}}{\sum_{t=1}^{n} \hat{e}_t^2}, \quad k = 1, 2, \ldots, hCombine the squared autocorrelations into Q = n(n+2) Σ ρ̂ₖ²/(n−k). Compared with the Box-Pierce statistic, n Σ ρ̂ₖ², the factor 1/(n−k) gives greater weight to higher lags. This is the modification Ljung and Box proposed to obtain a substantially better approximation to the chi-squared distribution.
Formula
Q = n(n+2) \sum_{k=1}^{h} \frac{\hat{\rho}_k^2}{n - k}Degrees of freedom are reduced by the number of estimated AR and MA parameters: df = h − p − q. For a raw series with no fitted model, df equals h. The formula counts only ARMA orders, so any other estimated parameters in the fitted model are not accounted for here.
Formula
df = h - p - q, \quad \text{where } p, q \text{ are AR and MA orders of the fitted model}Compare Q with the chi-squared critical value at the chosen significance level, or equivalently check whether the p-value is below α. Rejection of H₀ indicates residual autocorrelation, which suggests the model is misspecified or underfitted.
Formula
\text{Reject } H_0 \text{ if } Q > \chi^2_{\alpha,\, df}, \quad \text{i.e., } p\text{-value} < \alphaCommon pitfalls
- Using h too small can miss higher-order autocorrelation; using h too large dilutes power by adding degrees of freedom unnecessarily.
- Applying the test to the original series rather than model residuals will typically reject H₀ for any serially dependent data, providing no diagnostic information about the model.
- Forgetting to subtract the fitted AR and MA orders (df = h − p − q) uses the wrong chi-squared reference distribution, so the p-value is misstated.
- Treating a non-significant result as proof of correct specification; the test may simply lack power against the true alternative.
Frequently asked questions
How many lags h should I use for the Ljung-Box test?
There is no universal rule. Informal defaults such as h = min(10, n/5) are sometimes used, but they are not validated for this test. Choosing too few lags may miss higher-order dependencies, while too many lags reduce power by increasing degrees of freedom. Checking several values of h, for example 5, 10 and 20, shows whether the conclusion depends on the lag choice.
What is the difference between the Ljung-Box and Box-Pierce tests?
Both are portmanteau tests based on the same residual autocorrelations, but the Box-Pierce statistic uses the simpler form Q = n Σ ρ̂ₖ², whereas the Ljung-Box statistic uses the finite-sample form n(n+2) Σ ρ̂ₖ²/(n−k). The Ljung-Box version gives a substantially better chi-squared approximation in finite samples and is the form most often used in current practice.
If the Ljung-Box test rejects H₀, what should I do?
Rejection indicates residual autocorrelation, meaning the fitted model has not captured all temporal dependence. The appropriate response depends on context: for ARIMA models, consider increasing the AR or MA order; for regression residuals, investigate omitted lagged variables or switch to an ARIMA-error specification. Always examine the sample ACF/PACF of residuals to identify the lag structure causing rejection before refitting.
Related methods
Sources
Ljung, G. M., & Box, G. E. P. (1978). On a measure of lack of fit in time series models. Biometrika, 65(2), 297–303.
Open DOI reference