LjungBoxTest(FitAR)R Documentation

Ljung-Box test for randomness

Description

The Ljung-Box Portmanteau test for the goodness of fit of ARIMA models is implemented.

Usage

LjungBoxTest(res, k=0, lag.max=30, StartLag=10, SquaredQ=FALSE)

Arguments

res residuals
k number of ARMA parameters, default k=0
lag.max maximum lag, default MaxLag=30
StartLag test is done for lags m=StartLag:MaxLag, default StartLag=10
SquaredQ if TRUE, use squared residuals for ARCH test, default Squared=FALSE

Details

This test is described in detail in Wei (2006, p.153, eqn. 7.5.1).

Value

A matrix with columns labelled m, Qm, pvalue, where m is the lag and Qm is the Ljung-Box Portmanteau statistic and pvalue its p-value. A powerful test for ARCH and other nonlinearities is obtained by using squared values of the series to be tested (McLeod & Li, 1983). Note that if Squared=TRUE is used the data "res" is centered by sample mean correction before squaring.

Note

This test may also be used to test a time series for randomness taking k=0. Another useful test for randomness is the runs test, RunsTest. The runs test may be more powerful for detecting some types of nonlinearity.

Author(s)

A.I. McLeod

References

W.W.S. Wei (2006, 2nd Ed.), Time Series Analysis: Univariate and Multivariate Methods. A.I. McLeod. & W.K. Li (1983), Diagnostic checking ARMA time series models using squared-residual autocorrelations, Journal of Time Series Analysis 4, 269-273.

See Also

Box.test

Examples

#test goodness-of-fit of AR(2) model fit to log(lynx)
data(lynx)
z<-log(lynx)
ans<-FitAR(z, 1:2)
#notice that the test is also available as a component of the output of FitAR (FitARLS also)
ans$LjungBox
#a plot of the test is produced
plot(ans)
#doing the test manually
res<-resid(ans)
LjungBoxTest(res, k=2, lag.max=20, StartLag=5)

#test for subset case
z<-log(lynx)
pvec<-SelectModel(z, SubsetModel="z", method="BIC", lag.max=10, Best=1)
ans<-FitAR(z, pvec)
plot(ans)
res<-resid(ans)
LjungBoxTest(res, k=length(pvec), lag.max=20, StartLag=11)
#test for ARCH effect,
LjungBoxTest(res,SquaredQ=TRUE)


[Package FitAR version 1.0 Index]