The Ljung–Box test is a statistical hypothesis test used to assess whether a time series has nonzero autocorrelations over a specified range of lags. It combines several estimated autocorrelations into one statistic, rather than testing each lag separately. A common application is checking whether the residuals of a fitted time-series model retain serial correlation that the model has not explained. The test concerns linear dependence across time; it is not a general test of randomness or independence.
Hypotheses and scope
For a weakly stationary process, let denote the population autocorrelation at lag , the correlation between observations separated by time steps. For a chosen maximum lag , the null hypothesis is
The alternative is that at least one of these autocorrelations is nonzero.
The test is called a portmanteau test because it combines evidence across multiple lags into a single assessment. Rejection indicates evidence against the joint hypothesis, but does not identify which lags account for the result.
Zero autocorrelation is weaker than statistical independence. A process can have no linear correlation between observations at different times while still exhibiting nonlinear dependence. Consequently, failing to reject the null does not establish that the observations are independent or that every aspect of a fitted model is adequate.
Test statistic
For observations , define the sample mean as
A commonly used sample autocorrelation at lag is
The Ljung–Box test statistic is
Here, is the number of observations entering the calculation and is the maximum lag included. When applied to model residuals, is the number of usable residuals.
Each autocorrelation is squared, so positive and negative autocorrelations both increase the statistic. The denominator reflects the declining number of observation pairs at higher lags. Large values of provide evidence against the null hypothesis.
Reference distribution
For independent, identically distributed observations with finite, nonzero variance, and with fixed as increases, the null sampling distribution is asymptotically
Thus, the statistic is commonly compared with a chi-squared distribution with degrees of freedom. The upper-tail p-value is
At significance level , the null is rejected when .
This calibration requires more than zero autocorrelations alone. Under some forms of dependent but uncorrelated data, particularly processes with time-varying conditional variance, the usual chi-squared reference distribution may be inappropriate.
Use with fitted time-series models
A principal use of the test is checking residuals from an autoregressive integrated moving-average model, or ARIMA model. A model that adequately captures the series’ linear temporal structure should leave residuals without systematic autocorrelation.
Parameter estimation changes the distribution of residual autocorrelations. For residuals from a fitted nonseasonal ARMA model, a conventional approximation uses
rather than . Here, is the autoregressive order and is the moving-average order. This approximation is typically used when is sufficiently greater than ; it is not an exact finite-sample result.
For seasonal ARIMA models with seasonal autoregressive and moving-average orders and , a common convention uses
The differencing orders are not ordinarily included in this subtraction. The resulting degrees of freedom must be positive.
These adjustments are model-specific conventions, not a universal instruction to subtract every estimated coefficient. Models containing regression terms, complex seasonal structures, or other fitted components may require different treatment. Software implementations can also differ in how they count fitted parameters.
A significant result suggests remaining serial correlation, which may reflect omitted dynamics, an inadequate seasonal specification, or another form of misspecification. A nonsignificant result means only that the selected test did not detect autocorrelation through lag ; it does not establish accurate forecasts, normally distributed errors, or correct variance dynamics.
Choosing the lag range
The maximum lag determines which departures the test can detect.
- Small : concentrates on short-range dependence but can miss longer-lag or seasonal patterns.
- Larger : includes a broader range of dependence, but adds degrees of freedom and may reduce power against alternatives concentrated at a few lags.
- Seasonal data: including relevant seasonal lags can help detect patterns that a short-lag test would miss.
For a fixed dataset, increases or remains unchanged as increases. Its p-value need not decrease, because the reference distribution’s degrees of freedom also change.
Lag selection is therefore part of the test specification. Examining many lag cutoffs and reporting only a significant result introduces a multiple-testing issue. A sample autocorrelation plot can help locate patterns, but individual-lag assessments are not equivalent to the joint Ljung–Box test.
Numerical example
Suppose a series of observations has sample autocorrelations
Testing through lag gives
If these are observations rather than residuals requiring a model-fitting adjustment, the conventional reference distribution has three degrees of freedom. Its 5% upper-tail critical value is approximately , so the null is not rejected at that level. This does not imply that all three population autocorrelations are exactly zero.
Relationship to the Box–Pierce test
The Ljung–Box test modifies the earlier Box–Pierce test, whose statistic is
The two statistics are asymptotically equivalent for fixed , because
as increases. The Ljung–Box weighting was designed to improve the finite-sample approximation to the reference distribution. It is therefore widely used in place of the original Box–Pierce statistic, although its chi-squared calibration remains approximate.
The modification was introduced by Greta M. Ljung and George E. P. Box in their 1978 paper On a Measure of Lack of Fit in Time Series Models.
Limitations and related diagnostics
Nonlinear dependence. An uncorrelated series may still have dependence in its squared values or other transformations. Applying a Ljung–Box test to squared residuals is a common diagnostic for some forms of volatility dependence, but it tests a different hypothesis from a test on the residuals themselves.
Conditional heteroskedasticity. Changes in conditional variance can affect the sampling distribution of the statistic even when raw observations are serially uncorrelated. Robust portmanteau procedures or appropriately designed bootstrap methods may be used in such settings.
Small samples and large lag ranges. The finite-sample correction does not make the test exact. Its reference approximation can be inaccurate when the sample is short, the lag range is large relative to the sample size, or the fitted model is complex.
Nonstationarity and structural change. Trends, changing seasonal patterns, or structural breaks can generate autocorrelation that does not correspond to a stable stationary dependence structure. The test does not distinguish these explanations.
Distributional shape. Normality is not the null hypothesis. The test neither establishes nor directly assesses whether observations or residuals follow a normal distribution.
Irregular observation times. The standard formulation assumes that a lag represents a consistent time interval. Missing observations and irregular sampling require care, since deleting observations and treating the remainder as equally spaced can change the temporal meaning of the test.