Português

Ljung-Box test

Time series · reference distribution: χ²(h)

When to use it

Check whether a series, or the residuals of a model, still have autocorrelation over several lags.

Null hypothesis

The autocorrelations up to lag h are all zero (white noise).

Assumptions

Test statistic

Q = n(n + 2) \sum_{k=1}^{h} \dfrac{\hat{\rho}_k^2}{n - k}

How to report it

Q(10) = 12.4, p = .26

In R and Python

R
Box.test(residuals, lag = 10, type = "Ljung-Box")
Python
from statsmodels.stats.diagnostic import acorr_ljungbox
acorr_ljungbox(residuals, lags=[10])

In Python, stats is scipy.stats and np is numpy.

Variants and alternatives

Where it sits in the catalog

Time series. For observations ordered in time, where neighboring values tend to be correlated: they test stationarity and autocorrelation.

In the decision tree

  1. What do you want to do? Analyze a time series
  2. What do you want to know? Whether there is still autocorrelation, or it is white noise

Open the decision tree