Course contentsShow
← Data Science
Lesson 787 of 2,14520. Time Series ModelsFree lesson

Ljung-Box Test for Residual Autocorrelation

Using the Ljung-Box test to formally test whether residuals exhibit significant autocorrelation at multiple lags.

Ljung-Box Test for Residual Autocorrelation

What you'll learn: How to use the Ljung-Box test to formally check if your time series model's residuals contain leftover patterns across multiple lags at once.

Why Test Multiple Lags Together?

You've already learned to look at ACF plots of residuals and test independence at individual lags. But what if autocorrelation appears weak at each individual lag yet collectively suggests a problem? The Ljung-Box test solves this by testing multiple lags simultaneously with a single hypothesis test.

Think of it like checking whether a student consistently misses questions: one wrong answer might be random, but five scattered mistakes across a test could reveal a pattern of misunderstanding.

What the Ljung-Box Test Does

The Ljung-Box test examines whether residuals show significant autocorrelation across the first k lags (commonly k=10 or k=20). It computes a single test statistic that summarizes autocorrelation evidence across all those lags.

Hypotheses:

  • Null (H₀): Residuals are independently distributed (no autocorrelation at any tested lag)
  • Alternative (H₁): At least one lag shows significant autocorrelation

Interpreting Results

You get a p-value:

  • High p-value (> 0.05): Good news! No evidence of autocorrelation patterns. Your model captured the time series structure well.
  • Low p-value (≤ 0.05): Warning! Residuals still contain autocorrelation patterns. Your model missed something—consider adjusting AR/MA orders or checking for seasonality.

This test is more powerful than eyeballing ACF plots because it accounts for sampling uncertainty across multiple lags simultaneously.

When to Use It

Apply the Ljung-Box test after fitting your ARIMA model as part of residual diagnostics. It complements visual ACF checks and helps confirm whether your model successfully removed all autocorrelation structure.

Key Takeaway: The Ljung-Box test provides formal statistical evidence of whether residuals contain autocorrelation patterns across multiple lags, confirming if your time series model adequately captured all temporal dependencies.