AI Glossary / Time series and signal processing / Intermediate

Ljung-Box test

Definition

The Ljung-Box test is a statistical test that jointly assesses whether a set of autocorrelations, from lag one through a chosen maximum lag, is consistent with zero. It is often used to check whether forecast-model residuals retain serial correlation. Its reference distribution is approximate and must account appropriately for the model and parameters estimated.

What it means

A forecasting model may miss a pattern that remains visible in its errors. If today's error tends to be followed by a related error tomorrow, the model may leave useful temporal structure unexplained. The Ljung-Box statistic combines evidence across several lags instead of examining each autocorrelation separately.
A nonsignificant result means that this test did not detect the specified autocorrelation pattern with the available data. It does not prove independence, normality, constant variance, or complete adequacy of a forecasting model.

How it works

For n usable observations and sample autocorrelations rk, calculate Q = n(n + 2) times the sum of rk squared/(n − k), for k from one through m, where m is the chosen maximum lag. Large values indicate stronger aggregate evidence of autocorrelation.
Under appropriate conditions, compare Q with a chi-squared reference distribution. For a raw series without fitted dynamic parameters, the usual reference has m degrees of freedom. For residuals from certain fitted models, degrees of freedom are reduced to account for estimated dynamics; the adjustment depends on the model. Choose lags deliberately, consider seasonality, and avoid making m too large relative to sample size.

Three practical examples

  • A demand forecaster checks whether residuals from a seasonal model still contain correlation at relevant weekly or monthly lags.
  • An analyst compares residual diagnostics across candidate models while retaining out-of-sample forecasting performance as a separate criterion.
  • A monitoring team examines whether a sequence of standardized prediction errors has temporal structure that suggests missing dynamics or changing operating conditions.

Think of it this way

Think of checking several windows for signs that a room is still drafty after repairs. Looking across windows can reveal an overall problem even when no single observation is decisive. A clean inspection does not prove that every aspect of the building is sound; similarly, this test addresses a specific group of autocorrelations, not every possible model defect.

Worked example

Consider an original numerical illustration with n = 100 usable observations. Suppose sample autocorrelations at lags one and two are 0.20 and 0.10. Take maximum lag m = 2 and, for this calculation, assume no fitted dynamic-parameter adjustment is required.
The statistic is Q = 100 × 102 × [(0.20 squared/99) + (0.10 squared/98)] = approximately 5.16203. Using a chi-squared distribution with two degrees of freedom, the upper-tail probability is exp(−Q/2), approximately 0.07570. At a prechosen 5% significance level, this result does not reject the null hypothesis of zero autocorrelation through lag two.
It would be incorrect to conclude that the sequence is definitely independent, or that there is a 7.57% probability the null hypothesis is true. The p-value describes the reference-model probability of a statistic at least this large under the null and its assumptions.
The autocorrelations are stipulated summary values for demonstrating the calculation, not estimates from a supplied empirical dataset. If they were residuals from a fitted model requiring a degrees-of-freedom adjustment, the same statistic could have a different reference p-value. The maximum lag also needs to cover the structure relevant to the actual application.

Illustrative case study

Illustrative fictional case: Cypress Forecasting fits a model to weekly service demand and obtains a nonsignificant Ljung-Box result at a short lag. A residual plot still shows an unusual seasonal pattern, prompting the team to review whether the tested lag range was appropriate.
The analysts specify a diagnostic plan that includes relevant seasonal lags, residual plots, and later-period forecast evaluation. They report the selected lags and parameter adjustment with every p-value. This fictional case illustrates how a diagnostic is interpreted within a broader assessment rather than used as an automatic approval stamp.

Common misconceptions and mistakes

The test concerns autocorrelation, not all forms of dependence. A sequence can have little linear autocorrelation while exhibiting changing conditional variance or other nonlinear structure. Residual normality is a separate question.
Do not repeatedly try different lag cutoffs and report only the most convenient p-value. Data-dependent selection changes the interpretation of the nominal test. Also avoid using unadjusted degrees of freedom mechanically for fitted-model residuals. Too few effective degrees of freedom, short samples, or unsuitable reference assumptions can make the reported p-value unreliable or undefined.

Business use

Businesses can use the test as one check on whether a forecasting system has left predictable temporal patterns in its errors. Detecting such patterns can motivate investigation of missing seasonality, delayed predictors, or model changes.
Record the residual definition, usable sample size, lag count, parameter adjustment, and significance convention. Combine results with visual diagnostics and operational forecast performance. A low p-value identifies a reason to investigate; it does not by itself identify the correct replacement model or quantify the financial value of changing it.

People also ask

How does it differ from Box-Pierce?

Both combine squared autocorrelations, but Ljung-Box uses a sample-size and lag correction.

Does passing the test prove forecast accuracy?

No. Lack of detected residual autocorrelation is only one diagnostic property.

Should every estimated coefficient always be subtracted from the degrees of freedom?

No. Use an adjustment appropriate to the fitted model and documented testing procedure, rather than a universal counting rule.

Check your understanding

What two autocorrelations enter the example?

Answer: Those at lags one and two.

Why are negative autocorrelations also relevant?

Answer: The statistic squares them, so sufficiently large negative values contribute evidence too.

What decision follows at the stated 5% level?

Answer: Do not reject for this illustrative calculation; do not assert that the null has been proved.

Related terms

  • Autocorrelation
  • Box-Pierce test
  • White noise
  • Degrees of freedom
  • Chi-squared distribution
  • P-value
  • residual diagnostics
  • portmanteau test
  • seasonal lag

Learn next

compare a residual time plot and autocorrelation plot with the joint test. Then examine the documented degrees-of-freedom treatment for the specific forecasting model you use and evaluate predictions at the required business horizon.

  • Degrees of freedom
  • Autocorrelation

More in Time series and signal processing

  • Lagrangian - A Lagrangian is a function that combines an optimization objective with weighted constraint expressions. The weights are called Lagrange multipliers.
  • Laplace smoothing - Laplace smoothing, also called add-one smoothing, estimates probabilities from categorical counts by adding one to every category count before normalizing.
  • Linear interpolation smoothing - Linear interpolation smoothing combines two or more probability distributions using nonnegative weights that sum to one.
  • Loess - Loess is a local regression method that estimates a smooth relationship by fitting low-degree polynomials to nearby observations.
  • Logarithmic transformation - A logarithmic transformation replaces positive values with their logarithms.
  • Lomb-Scargle Periodograms - Lomb-Scargle periodograms assess periodic structure by fitting sinusoidal models across a range of frequencies, including when observations are unevenly...

Work in finance? Get the free CFO AI Prompt Pack: 7 prompts for finance leaders.

Sources

Sources: Hyndman and Athanasopoulos, Forecasting: Principles and Practice, portmanteau tests: https://otexts.com/fpp3/toolbox.html . statsmodels, official acorr_ljungbox documentation: https://www.statsmodels.org/stable/generated/statsmodels.stats.diagnostic.acorr_ljungbox.html . Primary textbook and documentation consulted. Original statistic and chi-squared-two upper tail independently checked; the case is fictional.

Previous: Literature-based discovery Next: LLM-as-a-judge

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer