Learn R Programming

portes (version 1.04)

LjungBox: Ljung and Box Portmanteau Test

Description

The Ljung-Box (1978) modified portmanteau test.

Usage

LjungBox(obj,lags=seq(5,30,5),order=0,SquaredQ=FALSE)

Arguments

obj
a fitted time-series model with any of the classes "ar", "Arima", "arima0", "FitAR", or "FitFGN" or a residuals with class "ts", "numeric", "matrix"<
lags
vector of lag values.
order
$p+q$, where ($p$,$q$) is the ARMA or the VARMA order.
SquaredQ
TRUE, apply the test to the squared values. This is needed to check the Autoregressive Conditional Heteroscedastic, ARCH, effects. When SquaredQ = FALSE, apply for the usual residuals.

Value

  • The Ljung and Box test statistic with the associated p-values for different lags based on asymptotic chi-square distribution.

References

Ljung, G.M. and Box, G.E.P (1978). "On a Measure of Lack of Fit in Time Series Models". Biometrika, 65, 297-303.

See Also

acf, Box.test, BoxPierce, Hosking, LiMcLeod, GVStat, portes, Get.Resid

Examples

Run this code
x <- rnorm(100)
LjungBox(x)
##############################################################
## Measurements of the annual flow of the river Nile at Aswan 
## from the years 1871 to 1970:
##############################################################
fit <- arima(Nile, c(2, 0, 0))
lags <- c(5, 10, 20)
## Apply the test statistic on the fitted model 
LjungBox(fit, lags, order = 2)  ## Univariate LjungBox test
## Apply the test statistic on the residuals
res <- resid(fit)
LjungBox(res, lags, order = 2)  ## Univariate LjungBox test  
##############################################################
## Monthly log stock returns of Intel corporation data
## Test for ARCH Effects 
##############################################################
monthintel <- as.ts(monthintel)
LjungBox(monthintel,SquaredQ=FALSE) ## Test for usual residuals   
LjungBox(monthintel,SquaredQ=TRUE)  ## Test for ARCH effects

Run the code above in your browser using DataLab