portest(obj,lags=seq(5,30,5),order=0,test=c("gvtest","BoxPierce",
"LjungBox","Hosking","LiMcLeod"),MonteCarlo=TRUE,nslaves=1,
NREP=1000,InfiniteVarianceQ=FALSE,SquaredQ=FALSE,SetSeed=TRUE)
obj
is an object of class "ar"
, "arima0"
, "Arima"
, "varest"
,
"FitAR"
, or "FitFGN"
then a portmanteau goodness-of-fit test is done on the fitted moBoxPierce
, gvtest
, Hosking
, LiMcLeod
, and LjungBox
and needed only when MonteCarlo = FALSE
is selected.TRUE
then apply the Monte-Carlo version of portmanteau statistic.
Otherwise, apply the asymptotic distribution.FALSE
, assumes innovations with finite variance.
Otherwise, innovations follow stable distribution with infinite variance.TRUE
then apply the test on the squared values.
This checks for Autoregressive Conditional Heteroscedastic, ARCH
, effects.
When SquaredQ = FALSE
, then apply the test on the usual resiTRUE
then set.seed
is initialized.gvtest
, BoxPierce
, LjungBox
,
Hosking
, and LiMcLeod
are implemented based on the Monte-Carlo techniques
and the approximation asymptotic distributions.
The null hypothesis assuming that the fitted model is an adequate
model and the residuals behave like white noise series.
The snow
package must be installed if one
decide to choose the argument MonteCarlo=TRUE
provided that
nslaves>1
.
This function can be used for testing the
adequacy in the nonseasonal fitted ARIMA
, VAR
,
and Fractional Gaussian Noise, FGN
, models.
Also, it can be used to check for randomness as well as for ARCH
effects.varima.sim
, ar
, arima0
, arima
,
Arima
, auto.arima
,
FitAR
, vars
, FitFGN
, BoxPierce
,
gvtest
, LjungBox
,
Hosking
, LiMcLeod
, fitstable
###############################################################
## Example 1
###############################################################
# Simple example using Monte-Carlotest in portes.
# 100 replications takes about 6 seconds on single cpu 2.67 GHz.
##
ans <- arima(Nile, order=c(1,0,1))
portest(ans, NREP=100)
##
###############################################################
## Example 2
###############################################################
# Simulate a bivariate VARIMA(1,c(0,0),1) process with length 300.
# Apply gvtest based on the two methods implemented in portes.
# 100 replications takes about 23.63 seconds on single cpu 2.67 GHz.
##about 6 seconds
k <- 2
n <- 300
Trunc.Series <- 50
phi <- array(c(0.5,0.4,0.1,0.5),dim=c(k,k,1))
theta <- array(c(0,0.25,0,0),dim=c(k,k,1))
d <- NA
sigma <- matrix(c(1,0.71,0.71,2),k,k)
z <- varima.sim(phi,theta,d,sigma,n)
ans <- ar(z)
portest(ans, MonteCarlo=FALSE) ## asymptotic distribution method
portest(ans, NREP=100) ## Monte-Carlo method
##
###############################################################
## Example 3
###############################################################
# Simulate a bivariate VARIMA(2,d,0) process with length 300.
## d is a vector (1,2)
## Fit VAR(2) using the function VAR in the package "vars"
# Apply gvtest based on the two methods implemented in portes.
# 100 replications takes about 30.17 seconds on single cpu 2.67 GHz.
##
library(vars)
k <- 2
n <- 300
Trunc.Series <- 50
phi <- array(c(0.5,0.4,0.1,0.5,0,0.25,0,0),dim=c(k,k,2))
theta <- NULL
d <- c(1,2)
sigma <- matrix(c(1,0.71,0.71,2),k,k)
z <- varima.sim(phi,theta,d,sigma,n)
ans <- VAR(z, p=2) ## inadequate fitted model
portest(ans, MonteCarlo=FALSE) ## asymptotic distribution method
portest(ans, NREP=100) ## Monte-Carlo method
##
###############################################################
## Example 4
###############################################################
## Checks the residuals for randomness using LjungBox test.
portest(rnorm(100),test="LjungBox")
##
###############################################################
## Example 5 - Using "snow" package
###############################################################
## Apply Hosking test on fitted VAR(2) model to WestGerman data.
##
library("snow")
data("WestGerman")
DiffData <- matrix(numeric(3 * 91), ncol = 3)
for (i in 1:3) DiffData[, i] <- diff(log(WestGerman[, i]), lag = 1)
Fit2 <- ar.ols(DiffData, aic=FALSE, order.max = 2, intercept = FALSE)
portest(Fit2,test="Hosking",nslaves=8) ## Monte-Carlo
portest(Fit2,test="Hosking",MonteCarlo=FALSE) ## asymptotic distribution
##
###############################################################
## Example 6 - Using "snow" package
###############################################################
## Test monthly log stock returns of Intel data for ARCH effects.
## gvtest statistic on PC with 8 CPU's using "snow".
## It takes 16.75 seconds based on the Monte-Carlo test.
##
data(monthintel)
returns <- as.ts(monthintel)
lags <- c(10, 20, 30, 40)
portest(returns,lags=lags,MonteCarlo=TRUE,nslaves=8,SquaredQ=TRUE)
##
###############################################################
## Example 7 - Using "snow" package
###############################################################
## Fit Fractional Gaussian Noise, FGN, to NileMin data in FGN package.
## Monte-Carlo of gvtest on 8 CPU's using "snow".
##
library(FGN)
data(NileMin)
NILE.FGN <- FitFGN(NileMin)
lags <- c(5, 10, 20)
##
## gvtest statistic on fitted model (55 seconds)
portest(NILE.FGN, lags=lags, nslaves=8)
##
## gvtest statistic on residuals (6 seconds)
res <- NILE.FGN$res
portest(res, lags=lags, nslaves=8)
##
Run the code above in your browser using DataLab