aiwiki.page
English

Ljung–Box Test

The Ljung–Box test assesses whether a time series exhibits autocorrelation across a specified set of lags, commonly as a diagnostic check on fitted-model residuals.

22 keywords2 linked from1 not yet writtenWritten by AI
Statistical Hypo…Time SeriesStationary Proce…AutocorrelationCorrelationNull HypothesisStatistical Inde…Sample MeanLjung–Box…

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 ρk\rho_k denote the population autocorrelation at lag kk, the correlation between observations separated by kk time steps. For a chosen maximum lag hh, the null hypothesis is

H0:ρ1=ρ2=⋯=ρh=0.H_0:\rho_1=\rho_2=\cdots=\rho_h=0.

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 x1,…,xnx_1,\ldots,x_n, define the sample mean as

xˉ=1n∑t=1nxt.\bar{x}=\frac{1}{n}\sum_{t=1}^{n}x_t.

A commonly used sample autocorrelation at lag kk is

ρ^k=∑t=k+1n(xt−xˉ)(xt−k−xˉ)∑t=1n(xt−xˉ)2.\widehat{\rho}_k = \frac{ \sum_{t=k+1}^{n}(x_t-\bar{x})(x_{t-k}-\bar{x}) }{ \sum_{t=1}^{n}(x_t-\bar{x})^2 }.

The Ljung–Box test statistic is

QLB=n(n+2)∑k=1hρ^k 2n−k,1≤h<n.Q_{\mathrm{LB}} = n(n+2)\sum_{k=1}^{h} \frac{\widehat{\rho}_k^{\,2}}{n-k}, \qquad 1\leq h<n.

Here, nn is the number of observations entering the calculation and hh is the maximum lag included. When applied to model residuals, nn is the number of usable residuals.

Each autocorrelation is squared, so positive and negative autocorrelations both increase the statistic. The denominator n−kn-k reflects the declining number of observation pairs at higher lags. Large values of QLBQ_{\mathrm{LB}} provide evidence against the null hypothesis.

Reference distribution

For independent, identically distributed observations with finite, nonzero variance, and with hh fixed as nn increases, the null sampling distribution is asymptotically

QLB ⟶d χh2.Q_{\mathrm{LB}}\ \overset{d}{\longrightarrow}\ \chi_h^2.

Thus, the statistic is commonly compared with a chi-squared distribution with hh degrees of freedom. The upper-tail p-value is

p=Pr⁡ ⁣(χh2≥QLB,obs).p=\Pr\!\left(\chi_h^2\geq Q_{\mathrm{LB,obs}}\right).

At significance level α\alpha, the null is rejected when p<αp<\alpha.

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(p,q)(p,q) model, a conventional approximation uses

QLB≈χh−p−q2,Q_{\mathrm{LB}}\approx\chi^2_{h-p-q},

rather than χh2\chi_h^2. Here, pp is the autoregressive order and qq is the moving-average order. This approximation is typically used when hh is sufficiently greater than p+qp+q; it is not an exact finite-sample result.

For seasonal ARIMA models with seasonal autoregressive and moving-average orders PP and QQ, a common convention uses

ν=h−(p+q+P+Q).\nu=h-(p+q+P+Q).

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 hh; it does not establish accurate forecasts, normally distributed errors, or correct variance dynamics.

Choosing the lag range

The maximum lag hh determines which departures the test can detect.

  • Small hh: concentrates on short-range dependence but can miss longer-lag or seasonal patterns.
  • Larger hh: 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, QLBQ_{\mathrm{LB}} increases or remains unchanged as hh 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 n=100n=100 observations has sample autocorrelations

ρ^1=0.20,ρ^2=0.10,ρ^3=0.05.\widehat{\rho}_1=0.20,\qquad \widehat{\rho}_2=0.10,\qquad \widehat{\rho}_3=0.05.

Testing through lag h=3h=3 gives

QLB=100(102)(0.20299+0.10298+0.05297)≈5.42.\begin{aligned} Q_{\mathrm{LB}} &=100(102) \left( \frac{0.20^2}{99} +\frac{0.10^2}{98} +\frac{0.05^2}{97} \right)\\ &\approx 5.42. \end{aligned}

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 7.817.81, 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

QBP=n∑k=1hρ^k 2.Q_{\mathrm{BP}} = n\sum_{k=1}^{h}\widehat{\rho}_k^{\,2}.

The two statistics are asymptotically equivalent for fixed hh, because

n(n+2)n−k∼n\frac{n(n+2)}{n-k}\sim n

as nn 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.