Ljung–Box test

From HandWiki
Short description: Statistical test

The Ljung–Box test en (audio) (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,[1][2] 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.[3]

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.

Formal definition

The Ljung–Box test may be defined as:

[math]\displaystyle{ H_0 }[/math]: The data are independently distributed (i.e. the correlations in the population from which the sample is taken are 0, so that any observed correlations in the data result from randomness of the sampling process).
[math]\displaystyle{ H_a }[/math]: The data are not independently distributed; they exhibit serial correlation.

The test statistic is:[2]

[math]\displaystyle{ Q = n(n+2)\sum_{k=1}^h\frac{\hat{\rho}^2_k}{n-k} }[/math]

where n is the sample size, [math]\displaystyle{ \hat{\rho}_k }[/math] is the sample autocorrelation at lag k, and h is the number of lags being tested. Under [math]\displaystyle{ H_0 }[/math] the statistic Q asymptotically follows a [math]\displaystyle{ \chi^2_{(h)} }[/math]. For significance level α, the critical region for rejection of the hypothesis of randomness is:

[math]\displaystyle{ Q \gt \chi_{1-\alpha,h}^2 }[/math]

where [math]\displaystyle{ \chi_{1-\alpha,h}^2 }[/math] is the (1 − α)-quantile[4] of the chi-squared distribution with h degrees of freedom.

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 [math]\displaystyle{ h - p - q }[/math].[5]

Box–Pierce test

The Box–Pierce test uses the test statistic, in the notation outlined above, given by[1]

[math]\displaystyle{ Q_\text{BP} = n \sum_{k=1}^h \hat{\rho}^2_k, }[/math]

and it uses the same critical region as defined above.

Simulation studies have shown that the distribution for the Ljung–Box statistic is closer to a [math]\displaystyle{ \chi^2_{(h)} }[/math] distribution than is the distribution for the Box–Pierce statistic for all sample sizes including small ones.[citation needed]

Implementations in statistics packages

  • R: the Box.test function in the stats package[6]
  • Python: the acorr_ljungbox function in the statsmodels package[7]
  • Julia: the Ljung–Box tests and the Box–Pierce tests in the HypothesisTests package[8]

See also


  1. 1.0 1.1 Box, G. E. P.; Pierce, D. A. (1970). "Distribution of Residual Autocorrelations in Autoregressive-Integrated Moving Average Time Series Models". Journal of the American Statistical Association 65 (332): 1509–1526. doi:10.1080/01621459.1970.10481180. 
  2. 2.0 2.1 G. M. Ljung; G. E. P. Box (1978). "On a Measure of a Lack of Fit in Time Series Models". Biometrika 65 (2): 297–303. doi:10.1093/biomet/65.2.297. 
  3. Davies, Neville; Newbold, Paul (1979). "Some power studies of a portmanteau test of time series model specification.". Biometrika 66 (1): 153–155. doi:10.1093/biomet/66.1.153. https://academic.oup.com/biomet/article-abstract/66/1/153/223702. 
  4. Brockwell, Peter J.; Davis, Richard A.; Davis, R. J. (2002-03-08). Introduction to Time Series and Forecasting. Taylor & Francis. p. 36. ISBN 978-0-387-95351-9. https://archive.org/details/introductiontoti00broc. 
  5. Davidson, James (2000). Econometric Theory. Blackwell. p. 162. ISBN 978-0-631-21584-4. https://books.google.com/books?id=shWtvsFbxlkC&pg=PA162. 
  6. "R: Box–Pierce and Ljung–Box Tests". https://stat.ethz.ch/R-manual/R-devel/library/stats/html/box.test.html. 
  7. "Python: Ljung–Box Tests". https://www.statsmodels.org/dev/generated/statsmodels.stats.diagnostic.acorr_ljungbox.html. 
  8. "Time series tests". https://juliastats.org/HypothesisTests.jl/latest/time_series/. 

Further reading

External links

 This article incorporates public domain material from the National Institute of Standards and Technology website https://www.nist.gov.