Running examples in ‘portes-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: BoxPierce
> ### Title: The Univariate-Multivariate Box and Pierce Portmanteau Test
> ### Aliases: BoxPierce
> ### Keywords: Portmanteau Test
> 
> ### ** Examples
> 
> x <- rnorm(100)
> BoxPierce(x)                              ## univariate test
 lags statistic df   p-value
    5  3.365573  5 0.6438184
   10  5.656600 10 0.8432421
   15  6.411116 15 0.9719842
   20 10.784097 20 0.9516304
   25 14.805770 25 0.9458056
   30 18.070877 30 0.9573747
> x <- cbind(rnorm(100),rnorm(100))
> BoxPierce(x)                              ## multivariate test      
 lags statistic  df   p-value
    5  21.57526  20 0.3639953
   10  46.56519  40 0.2203640
   15  68.17104  60 0.2192425
   20  80.06079  80 0.4770587
   25  93.89001 100 0.6531214
   30 109.78629 120 0.7374883
> ##
> ##
> ## Annual flow of the river Nile at Aswan - 1871 to 1970
> fit <- arima(Nile, c(1, 0, 1))
> lags <- c(5, 10, 20)
> ## Apply the univariate test statistic on the fitted model 
> BoxPierce(fit, lags)            ## Correct (no need to specify order) 
 lags statistic df   p-value
    5  1.278883  3 0.7341534
   10  9.002228  8 0.3421081
   20 12.767895 18 0.8051730
> BoxPierce(fit, lags, order = 2) ## Correct 
 lags statistic df   p-value
    5  1.278883  3 0.7341534
   10  9.002228  8 0.3421081
   20 12.767895 18 0.8051730
> ## Apply the test statistic on the residuals and set order = 2 
> res <- resid(fit)
> BoxPierce(res, lags)             ## Wrong (order is needed!)  
 lags statistic df   p-value
    5  1.278883  5 0.9370895
   10  9.002228 10 0.5318922
   20 12.767895 20 0.8871190
> BoxPierce(res, lags, order = 2)  ## Correct 
 lags statistic df   p-value
    5  1.278883  3 0.7341534
   10  9.002228  8 0.3421081
   20 12.767895 18 0.8051730
> ##
> ##
> ## Quarterly, west German investment, income, and consumption from 1960 Q1 to 1982 Q4 
> 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)                ## Correct (no need to specify order)
 lags statistic df   p-value
    5  29.13889 27 0.3541968
   10  66.82771 72 0.6502032
> ## Apply the test statistic on the residuals where order = 2
> res <- ts((fit$resid)[-(1:2), ])
> BoxPierce(res,lags)                ## Wrong (order is needed!)  
 lags statistic df   p-value
    5  29.13889 45 0.9678196
   10  66.82771 90 0.9679689
> BoxPierce(res,lags,order = 2)      ## Correct 
 lags statistic df   p-value
    5  29.13889 27 0.3541968
   10  66.82771 72 0.6502032
> ##
> ##
> ## Monthly log stock returns of Intel corporation data: Test for ARCH Effects 
> monthintel <- as.ts(monthintel)
> BoxPierce(monthintel)                         ## Usual test 
 lags statistic df    p-value
    5  4.666889  5 0.45786938
   10 14.364748 10 0.15699489
   15 23.120348 15 0.08161787
   20 24.000123 20 0.24238680
   25 29.617977 25 0.23891229
   30 31.943703 30 0.37015020
> BoxPierce(monthintel,squared.residuals=TRUE)  ## Test for ARCH effects
 lags statistic df      p-value
    5  40.78073  5 1.039009e-07
   10  49.57872 10 3.189915e-07
   15  81.90133 15 3.131517e-11
   20  86.50575 20 3.006796e-10
   25  87.54737 25 7.161478e-09
   30  88.55017 30 1.087505e-07
> ##
> ##
> ## Test for seasonality
> ## Accidental Deaths in the US 1973 - 1978
> seasonal.arima <- arima(USAccDeaths, order = c(0,1,1), seasonal = list(order = c(0,1,1)))
> BoxPierce(seasonal.arima, lags = 5, season = 12)
 lags statistic df  p-value
    5 0.5845238  3 0.899966
> ## Quarterly U.K. economic time series from 1957 Q3 to 1967 Q4
> cd <- EconomicUK[,1]
> cd.fit <- arima(cd,order=c(0,1,0),seasonal=list(order=c(0,1,1),period=4))
> BoxPierce(cd.fit, lags = c(5,10), season = 4)
 lags statistic df   p-value
    5  1.307341  4 0.8601288
   10  1.918594  9 0.9926904
> ##
> ##
> #### Write a function to fit a model: Apply portmanteau test on fitted obj with class "list"
> ## Example 1 
> require("FitAR")
Loading required package: FitAR
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘FitAR’
> FitModel <- function(data){
+     fit <- FitAR(z=data,p=2)
+     p <- length(fit$phiHat)
+     order <- p
+     res <- fit$res 
+  list(res=res,order=order)
+ }
> Fit <- FitModel(Nile)
Error in FitAR(z = data, p = 2) : could not find function "FitAR"
Calls: FitModel
Execution halted