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
- On the residuals of an ARMA model, subtract the estimated parameters from the df
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
- Box-Pierce, the original and less accurate version
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
- What do you want to do? Analyze a time series
- What do you want to know? Whether there is still autocorrelation, or it is white noise