Box.test
Box-Pierce and Ljung-Box Tests

Description

Compute the Box-Pierce or Ljung-Box test on a time series. These test whether the autocorrelations in the data are different from zero.

Usage

Box.test(x, lag = 1, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0)

Arguments

x a vector or univariate time series.
lag the number of lags at which to estimate the auto-correlation.
type a character string, be one of "Box-Pierce" and "Ljung-Box", or simplified form of them.
fitdf a number used to compute degree of freedom.

Details

The Box-Pierce test is a simplified version of the Ljung-Box test.
Let n = length(x), rhoi = autocorrelation of x at lag i, k = lag, then the Box-Pierce test statistic is n * (rho1^2 + rho2^2 + ... + rhok^2) and the Ljung-Box test statistic is n*(n+2)*(rho1^2/(n-1) + rho2^2/(n-2) + ... + rhok^2/(n-k) Under the null hypothesis of no autocorrelation, the test statistics have a Chi-square distribution with lag degrees of freedom.
Value
Returns a list of class "htest" with following components:
statistic value of X-squared.
parameter value of degree of freedom.
p.value the p-value for the test, value of 1- cumulative probability value of X-squared.
method type of method.
data.name a character string, that is the name of x.
Differences between Spotfire Enterprise Runtime for R and Open-source R
Spotfire Enterprise Runtime for R uses the truncated to integer value of lag, as does Open-source R but Spotfire Enterprise Runtime for R also uses the truncated integer value in computing the degrees of freedom while R does uses the supplied lag value in computing the degrees of freedom. This is only an issue if the value specified for lag is not an integer.
Spotfire Enterprise Runtime for R will issue a warning if the combination of lag and fitdf result in a negative value for the degrees of freedom, Open-source R does not warn. In this situation, both Spotfire Enterprise Runtime for R and Open-source R will report NA for the test p-value.
References
Box, G. E. P. and Pierce, D. A. 1970. Distribution of residual correlations in autoregressive-integrated moving average time series models. Journal of the American Statistical Association. Volume 65. 1509-1526.
Harvey, A. C. 1993. Time Series Models. Second Edition. New York, NY: Harvester Wheatsheaf. 44-45.
Ljung, G. M. and Box, G. E. P. 1978. On a measure of lack of fit in time series models. Biometrika.
See Also
acf, pchisq.
Examples
x <- ts(1:10)
Box.test(x, lag = 2, type="Ljung")
Box.test(x, lag = 2, type="Ljung", fitdf = 1)

y<-runif(100) Box.test(y, lag = 1, type="Box-Pierce")

Package stats version 6.1.4-13
Package Index