x <- rnorm(100)
BoxPierce(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 
BoxPierce(fit, lags, order = 2)  ## Univariate Box-Pierce test
## Apply the test statistic on the residuals
res <- resid(fit)
BoxPierce(res, lags, order = 2)  ## Univariate Box-Pierce test
##############################################################
## Quarterly, west German investment, income, and consumption 
## from first quarter of 1960 to fourth quarter of 1982: 
##############################################################
data(WestGerman)
DiffData <- matrix(numeric(3 * 91), ncol = 3)
  for (i in 1:3) 
    DiffData[, i] <- diff(log(WestGerman[, i]), lag = 1)
fit <- ar.ols(DiffData, intercept = TRUE, order.max = 2)
lags <- c(5,10)
## Apply the test statistic on the fitted model 
BoxPierce(fit,lags,order = 2)  ## Multivariate Box-Pierce test
## Apply the test statistic on the residuals
res <- ts((fit$resid)[-(1:2), ])
BoxPierce(res,lags,order = 2)  ## Multivariate Box-Pierce test
##############################################################
## Monthly log stock returns of Intel corporation data
## Test for ARCH Effects 
##############################################################
monthintel <- as.ts(monthintel)
BoxPierce(monthintel,SquaredQ=FALSE) ## Test for usual residuals 
BoxPierce(monthintel,SquaredQ=TRUE)  ## Test for ARCH effectsRun the code above in your browser using DataLab