x <- rnorm(100)
gvtest(x)
##############################################################
## Measurements of the annual flow of the river Nile at Aswan
## from the years 1871 to 1970:
##############################################################
fit <- arima(Nile, c(1, 0, 1))
lags <- c(5, 10, 20, 30)
## Apply the univariate test statistic on the fitted model
gvtest(fit, lags) ## True
gvtest(fit, lags, order = 2) ## True
## Apply the test statistic on the residuals and set order = 2
res <- resid(fit)
gvtest(res, lags) ## Not True
gvtest(res, lags, order = 2) ## True
##############################################################
## 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 <- seq(5,30,5)
## Apply the test statistic on the fitted model
gvtest(fit,lags) ## True
## Apply the test statistic on the residuals where order = 2
res <- ts((fit$resid)[-(1:2), ])
gvtest(res,lags) ## Not True
gvtest(res,lags,order = 2) ## True
##############################################################
## Monthly log stock returns of Intel corporation data
## Test for ARCH Effects
##############################################################
monthintel <- as.ts(monthintel)
gvtest(monthintel) ## Usual test
gvtest(monthintel,SquaredQ=TRUE) ## Test for ARCH effects
Run the code above in your browser using DataLab