#Example 1
#Simple example using portes.
# 100 replications takes about 6 seconds on single cpu 2.67 GHz
ans<-arima(Nile, order=c(1,0,1))
portes(ans, NREP=100)
#
#Example 2
#Simulate a bivariate VARMA(1,0) process with length 300.
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.0,0,0),dim=c(k,k,1))
intercept <- c(10,12)
sigma <- matrix(c(1,0.71,0.71,2),k,k)
z<-simvarma(phi,theta=theta,sigma,intercept,n)
ans<-ar(z)
portes(ans, NREP=25) #NREP=25 is not enough for accurate p-values!
#
#Examples using snow or Rmpi. Takes a few minutes.
##############################################################
## The following script checks the residuals for randomness
## Model VAR(11) fitted to house data after subtracting the mean.
##
##
HouseData <- scale(house, scale = FALSE)
HOUSE.VAR11<-ar.ols(HouseData,aic=FALSE,intercept=FALSE,order.max=11)
res <- ts((HOUSE.VAR11$resid)[-(1:11), ])
#
## GVStat statistic on PC with one CPU (61.68 seconds)
portes(res)
#
## GVStat statistic on PC with 8 CPU's using "Rmpi" (10.44 seconds)
portes(res,statistic="GVStat",SpawnSlaves="Rmpi", nslaves=8)
#
## GVStat statistic on PC with 8 CPU's using "snow" (10.81 seconds)
portes(res,statistic="GVStat",SpawnSlaves="snow", nslaves=8)
##############################################################
## The following script generates Table 2 in Lin and McLeod (2008).
## It takes 1.96 minutes on PC with 8 CPU's using "Rmpi"
##
CRSP.AR5<- arima(CRSP, c(5,0,0))
NREP<- 1000
lags=c(10,20,30)
tb<-matrix(numeric(6*length(lags)),nrow=6)
tb[1,]<-portes(CRSP.AR5,lags=lags,statistic="GVStat",SpawnSlaves="Rmpi",
nslaves=8, NREP=NREP,InfiniteVarianceQ=TRUE)[,2]
tb[2,]<-portes(CRSP.AR5,lags=lags,statistic="LiMcLeod",SpawnSlaves="Rmpi",
nslaves=8, NREP=NREP,InfiniteVarianceQ=TRUE)[,2]
tb[3,]<-portes(CRSP.AR5,lags=lags,statistic="GVStat",SpawnSlaves="Rmpi",
nslaves=8, NREP=NREP)[,2]
tb[4,]<-portes(CRSP.AR5,lags=lags,statistic="LiMcLeod",SpawnSlaves="Rmpi",
nslaves=8, NREP=NREP)[,2]
tb[5,]<-GVStat(CRSP.AR5,lags,5)[,4]
tb[6,]<-LiMcLeod(CRSP.AR5,lags,5)[,4]
rn <- c("GVStat-MC-Stable","LiMcLeod-MC-Stable", "GVStat-MC-Normal",
"LiMcLeod-MC-Normal", "GVStat-asymptotic", "LiMcLeod-asymptotic")
dimnames(tb) <- list(rn, lags)
tb
#
#Output
# 10 20 30
#GVStat-MC-Stable 0.06393606 0.034965035 0.021978022
#LiMcLeod-MC-Stable 0.05494505 0.019980020 0.022977023
#GVStat-MC-Normal 0.06293706 0.014985015 0.001998002
#LiMcLeod-MC-Normal 0.04995005 0.001998002 0.001998002
#GVStat-asymptotic 0.29111084 0.057389935 0.007760695
#LiMcLeod-asymptotic 0.04858500 0.002316690 0.002643823
##############################################################
## Fit AR(2) to Nile river data on PC with 8 CPU's
##
##
NILE.AR2 <- FitAR(Nile, 2)
lags <- c(5, 10, 20)
##
## GVStat test on fitted model using "Rmpi" (5.9 seconds)
portes(res, lags, "GVStat",SpawnSlaves="Rmpi", nslaves=8)
#
## LiMcLeod test on residuals using "snow" (5.95 seconds)
res <- NILE.AR2$res
portes(NILE.AR2, lags, "LiMcLeod",SpawnSlaves="snow", nslaves=8)
##############################################################
## Test monthly log stock returns of Intel data for ARCH effects
## GVStat statistic on PC with 8 CPU's using "Rmpi"
## It takes 5.93 seconds to get the results
##
data(monthintel)
returns <- as.ts(monthintel)
lags <- c(5, 10, 40)
portes(returns,lags,"GVStat",SpawnSlaves="Rmpi",nslaves=8,SquaredQ=TRUE)
##############################################################
## Fit Fractional Gaussian Noise, FGN, to NileMin data in FGN package
## GVStat statistic on PC with 8 CPU's using "Rmpi"
##
library(FGN)
data(NileMin)
NILE.FGN <- FitFGN(NileMin)
lags <- c(5, 10, 20)
##
## GVStat statistic on fitted model (55 seconds)
portes(NILE.FGN, lags, "GVStat",SpawnSlaves="Rmpi", nslaves=8)
#
## GVStat statistic on residuals (6 seconds)
res <- NILE.FGN$res
portes(res, lags, "GVStat",SpawnSlaves="Rmpi", nslaves=8)
Run the code above in your browser using DataLab