The Ljung–Box test (named for Greta M. Ljung and George E. P. Box) is a type of statistical test of whether any of a group of autocorrelations of a time series are different from zero. Instead of testing randomness at each distinct lag, it tests the "overall" randomness based on a number of lags, and is therefore a portmanteau test.
This test is sometimes known as the Ljung–Box Q test, and it is closely connected to the Box–Pierce test (which is named after George E. P. Box and David A. Pierce). In fact, the Ljung–Box test statistic was described explicitly in the paper that led to the use of the Box–Pierce statistic, and from which that statistic takes its name. The Box–Pierce test statistic is a simplified version of the Ljung–Box statistic for which subsequent simulation studies have shown poor performance.[1]
The Ljung–Box test is widely applied in econometrics and other applications of time series analysis. A similar assessment can be also carried out with the Breusch–Godfrey test and the Durbin–Watson test.
The Ljung–Box test may be defined as:
H0
Ha
The test statistic is:
Q=
| ||||
n(n+2)\sum | ||||
k}{n-k} |
\hat{\rho}k
H0
2 | |
\chi | |
(h) |
Q>
2 | |
\chi | |
1-\alpha,h |
where
2 | |
\chi | |
1-\alpha,h |
The Ljung–Box test is commonly used in autoregressive integrated moving average (ARIMA) modeling. Note that it is applied to the residuals of a fitted ARIMA model, not the original series, and in such applications the hypothesis actually being tested is that the residuals from the ARIMA model have no autocorrelation. When testing the residuals of an estimated ARIMA model, the degrees of freedom need to be adjusted to reflect the parameter estimation. For example, for an ARIMA(p,0,q) model, the degrees of freedom should be set to
h-p-q
The Box–Pierce test uses the test statistic, in the notation outlined above, given by
QBP=n
h | |
\sum | |
k=1 |
2 | |
\hat{\rho} | |
k, |
Simulation studies have shown that the distribution for the Ljung–Box statistic is closer to a
2 | |
\chi | |
(h) |
Box.test
function in the stats package[4]acorr_ljungbox
function in the statsmodels
package[5]HypothesisTests
package[6]