Tutorials › Exam SRM - Statistics for Risk Modeling › Ljung–Box Tests for Residual Autocorrelation

Exam SRM · Time-Series Model Selection · Tutorial 517 of 926

Ljung–Box Tests for Residual Autocorrelation

Use the Ljung–Box test to assess whether fitted time-series residuals retain autocorrelation across a chosen range of lags.

Advanced 11 min read

What You'll Learn

  • State the joint null hypothesis tested by the Ljung–Box statistic
  • Calculate the statistic from residual autocorrelations through a chosen lag
  • Explain the finite-sample adjustment relative to the Box–Pierce statistic
  • Choose a lag range that reflects the data frequency and diagnostic question
  • Interpret a chi-square p-value without claiming it identifies a specific lag
  • Avoid confusing a non-rejection with proof that residuals are white noise

Why Test Residual Autocorrelation?

After fitting a time-series model, residuals should not retain a systematic linear relationship across time. A residual autocorrelation plot can reveal individual lags that merit attention, but it is also useful to have a single test of whether autocorrelations across a specified range are jointly consistent with zero. The Ljung–Box test provides that portmanteau test. Its conclusion depends on the residual autocorrelations, the largest lag included, and the reference distribution used.

The test assesses a specific aspect of model adequacy: serial correlation in the residuals. It does not establish that a model is correct in every respect, nor does it identify which alternative model should replace it. This diagnostic is aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus.

Definition: Let \(e_1,\ldots,e_n\) be the residuals from a fitted time-series model, and let \(r_k\) be their sample autocorrelation at lag \(k\). For a chosen maximum lag \(h\), the Ljung–Box statistic is $$ Q^*=n(n+2)\sum_{k=1}^{h}\frac{r_k^2}{n-k}. $$ The null hypothesis is that the residual autocorrelations at lags \(1,\ldots,h\) are all zero. The alternative is that at least one of them is nonzero.

What the Statistic Measures

A sample autocorrelation \(r_k\) measures the association between residuals \(k\) time steps apart. One common definition, using residuals centered at their sample mean \(\bar e\), is $$ r_k=\frac{\sum_{t=k+1}^{n}(e_t-\bar e)(e_{t-k}-\bar e)} {\sum_{t=1}^{n}(e_t-\bar e)^2}. $$ The autocorrelations are dimensionless. Squaring them makes positive and negative residual association contribute equally, and summing from lag 1 through \(h\) combines the evidence across all selected lags. A large \(Q^*\) indicates that the autocorrelations, taken together, are large relative to what the null model would typically produce.

The Ljung–Box statistic is related to the Box–Pierce statistic, \(Q_{\mathrm{BP}}=n\sum_{k=1}^{h}r_k^2\), but it is not the same calculation. In \(Q^*\), the contribution from lag \(k\) has the factor \(n(n+2)/(n-k)\). For finite \(n\), this factor adjusts the simple Box–Pierce weighting; later lags receive a larger adjustment because \(n-k\) is smaller. The distinction matters especially when the sample is not large relative to the chosen lag.

Why the Formula Has This Form

Under a null model with no serial correlation, the sample autocorrelation at a fixed lag is approximately centered at zero and has variance about \(1/n\), for a sufficiently long series. Thus, a squared autocorrelation is typically of order \(1/n\). If the first \(h\) autocorrelations are approximately independent under the null, then \(n\sum_{k=1}^{h}r_k^2\) behaves approximately like a sum of \(h\) squared standard normal quantities. Such a sum has a chi-square distribution with \(h\) degrees of freedom.

The Box–Pierce statistic uses that basic large-sample scaling. The Ljung–Box form refines the scaling for finite samples by replacing the contribution \(n r_k^2\) with $$ \frac{n(n+2)}{n-k}r_k^2. $$ This is a finite-sample correction to the approximate portmanteau statistic, not a guarantee of an exact chi-square distribution for every sample or every fitted model. Under the usual large-sample approximation, the null distribution is chi-square. The degrees of freedom used for residuals from a fitted model can depend on the fitting procedure and model; use the reference degrees of freedom specified for the diagnostic. The examples below explicitly use \(h\) degrees of freedom.

Interpretation: If the reference distribution is \(\chi^2_h\), the p-value is the upper-tail probability \(P(\chi^2_h\geq Q^*)\). A small p-value is evidence against the joint null of zero residual autocorrelation through lag \(h\). It does not show that every lag is correlated, or specify which lag is responsible.

Choosing the Lag Range and Making a Decision

Choose \(h\) to match the diagnostic question and the time scale of the data. For example, a seasonal pattern may make a seasonal lag important, while a short-run dependence question may call for a smaller range. The selected range should be defensible before interpreting the test result, and \(h\) must be less than \(n\) so that the statistic is defined. Including many lags indiscriminately can dilute the diagnostic and make interpretation less focused; choosing a range only after noticing an inconvenient result can also make the conclusion misleading.

1
Set the diagnostic range.
Choose the maximum lag \(h\) based on the sampling frequency and the residual dependence worth checking.
2
Calculate the statistic.
Square each residual autocorrelation from lag 1 through \(h\), apply its \(n(n+2)/(n-k)\) weight, and add the contributions.
3
Use the stated reference distribution.
Calculate an upper-tail p-value or compare \(Q^*\) with the appropriate upper critical value.
4
Interpret the evidence.
At significance level \(\alpha\), reject the joint null when the p-value is below \(\alpha\). Otherwise, do not reject it.

A non-rejection is not proof that the residuals are independent, or even that every individual autocorrelation is exactly zero. It means the test did not find sufficient evidence against its joint null at the chosen significance level and lag range. Conversely, a rejection says that some autocorrelation is indicated somewhere among the tested lags, not that the model is necessarily unusable.

Worked Example: Testing Three Residual Lags

A hypothetical model for monthly service-request counts has \(n=20\) fitted residuals. Their sample autocorrelations are \(r_1=0.30\), \(r_2=-0.20\), and \(r_3=0.10\). Test the joint null through lag \(h=3\), using a \(\chi^2_3\) reference distribution and \(\alpha=0.05\). Name the method and state the conclusion.

Method and statistic. Use the Ljung–Box statistic. The multiplier is \(n(n+2)=20(22)=440\). The squared autocorrelations are \(0.30^2=0.09\), \((-0.20)^2=0.04\), and \(0.10^2=0.01\). The three weighted terms are $$ \frac{0.09}{19}=0.004736842,\qquad \frac{0.04}{18}=0.002222222,\qquad \frac{0.01}{17}=0.000588235. $$ Their sum, calculated before rounding, is approximately \(0.007547300\). Therefore $$ Q^*=440(0.007547300)\approx 3.3208. $$

Reference and decision. With the stipulated \(\chi^2_3\) reference distribution, the upper-tail p-value is approximately \(0.3448\). Since \(0.3448>0.05\), do not reject the joint null. These residuals do not provide sufficient evidence of autocorrelation at one or more of lags 1 through 3 at the 5% level.

Check. The negative value at lag 2 contributes positively because the autocorrelation is squared. The common mistake of retaining its negative sign in the sum would not be the Ljung–Box calculation.

Worked Example: Interpreting a Small Statistic

A hypothetical weekly payment series is fitted with a time-series model. For its \(n=18\) residuals, the autocorrelations are \(r_1=0.20\) and \(r_2=0.10\). Test through \(h=2\) using a \(\chi^2_2\) reference distribution at \(\alpha=0.05\). Calculate the statistic and p-value.

Method and statistic. The multiplier is \(18(18+2)=360\). The weighted terms are $$ \frac{0.20^2}{18-1}=\frac{0.04}{17}=0.002352941,\qquad \frac{0.10^2}{18-2}=\frac{0.01}{16}=0.000625000. $$ Their sum is approximately \(0.002977941\), so $$ Q^*=360(0.002977941)\approx1.072059. $$

Reference and decision. For two degrees of freedom, the chi-square upper-tail probability is \(e^{-Q^*/2}\). Thus the p-value is $$ e^{-1.072059/2}=e^{-0.5360295}\approx0.5851. $$ Since \(0.5851>0.05\), do not reject the joint null through lag 2.

Check. The multiplier is 360, not 18 alone. Using only \(n\) and omitting the lag-specific denominators would not give the Ljung–Box statistic.

Worked Example: A Larger Contribution at a Seasonal Lag

A hypothetical quarterly exposure series has \(n=30\) fitted residuals. The sample autocorrelations at lags 1 through 4 are \(0.10, 0.10, 0.10,\) and \(0.40\). A four-quarter cycle is relevant, so test through \(h=4\), using \(\chi^2_4\) and \(\alpha=0.05\). What is the decision?

Method and statistic. Here \(n(n+2)=30(32)=960\). The terms in the sum are $$ \frac{0.01}{29}=0.000344828,\quad \frac{0.01}{28}=0.000357143,\quad \frac{0.01}{27}=0.000370370,\quad \frac{0.16}{26}=0.006153846. $$ The unrounded terms sum to approximately \(0.007226187\). Therefore $$ Q^*=960(0.007226187)\approx6.9371. $$

Reference and decision. The 5% upper critical value for \(\chi^2_4\) is approximately \(9.488\). Since \(6.9371<9.488\), do not reject the joint null at the 5% level. The lag-4 autocorrelation is visibly larger than the first three, but the portmanteau decision concerns their combined evidence.

Check. The lag-4 contribution is \(0.16/26\), not \(0.16/30\). The denominator in each term is \(n-k\), which changes with the lag.

Common Exam Traps

  • Using the Box–Pierce expression by mistake. For the first example, \(Q_{\mathrm{BP}}=20(0.09+0.04+0.01)=2.80\). That is not \(Q^*\), which is approximately \(3.3208\) after the Ljung–Box lag adjustments.
  • Forgetting to square autocorrelations. A negative autocorrelation is not subtracted from the statistic. Both positive and negative autocorrelations contribute through \(r_k^2\).
  • Testing a different set of lags than stated. “Through lag \(h\)” includes every lag from 1 to \(h\), not just lag \(h\) or the visually largest lag.
  • Reading non-rejection as confirmation. A large p-value does not prove white noise. It indicates insufficient evidence against the tested joint null under the chosen reference approximation.
  • Overstating a rejection. Rejection indicates evidence of autocorrelation at one or more tested lags. The portmanteau statistic alone does not identify the responsible lag.

The Ljung–Box test is most informative when it complements residual plots and a clearly stated diagnostic question. Its value is in summarizing joint evidence over a chosen range, not replacing the examination of residual patterns or other aspects of model adequacy.

Check Your Understanding

For each problem, use the stated reference distribution and significance level. Answers are provided for checking.

  1. A fitted model has \(n=16\), \(r_1=0.25\), and \(h=1\). Use \(\chi^2_1\) at \(\alpha=0.05\). Calculate \(Q^*\) and state the decision. (Answer: \(Q^*=1.200\); do not reject at 0.05.)
  2. For \(n=18\), \(r_1=0.20\), and \(r_2=0.10\), test through lag 2 using \(\chi^2_2\). Give the statistic and p-value to four decimals, then decide at 0.05. (Answer: \(Q^*\approx1.0721\); p-value \(\approx0.5851\); do not reject.)
  3. For \(n=20\), the residual autocorrelations are \(r_1=0.30\) and \(r_2=-0.20\). A candidate calculation gives \(20(0.09+0.04)=2.60\). Identify that calculation and find the Ljung–Box statistic through lag 2. (Answer: \(2.60\) is the Box–Pierce statistic; \(Q^*=440[0.09/19+0.04/18]\approx3.062\).)
  4. A diagnostic reports \(Q^*=10.20\) through lag 4, with reference distribution \(\chi^2_4\). Find the upper-tail p-value to four decimal places and interpret the result at 0.05. (Answer: p-value \(\approx0.0372\); reject; there is evidence of autocorrelation at one or more of lags 1–4.)
  5. For \(n=30\), the residual autocorrelations at lags 1–4 are \(0.10,0.10,0.10,0.40\). Using \(\chi^2_4\) and \(\alpha=0.05\), calculate the statistic and decide. (Answer: \(Q^*\approx6.9371\); do not reject at 0.05.)
Clinical Biostats