Learn R Programming

portes (version 6.0)

Hosking: The Modified Multivariate Portmanteau Test, Hosking (1980)

Description

The modified multivariate portmanteau test suggested by Hosking (1980).

Usage

Hosking(obj,lags=seq(5,30,5),fitdf=0,sqrd.res=FALSE)

Value

The multivariate test statistic suggested by Hosking (1980) and its associated p-values for different lags based on the asymptotic chi-square distribution with k^2(lags-fitdf) degrees of freedom.

Arguments

obj

a univariate or multivariate series with class "numeric", "matrix", "ts", or ("mts" "ts"). It can be also an object of fitted time-series model with class "ar", "arima0", "Arima", ("ARIMA forecast ARIMA Arima"), "lm", ("glm" "lm"), or "varest". obj may also an object with class "list" (see details and following examples).

lags

vector of lag auto-cross correlation coefficients used for Hosking test.

fitdf

Default is zero for testing the randomness of a given sequence with class "numeric", "matrix", "ts", or ("mts" "ts"). In general fitdf equals to the number of estimated parameters in the fitted model. If obj is an object with class "ar", "arima0", "Arima", "varest", ("ARIMA forecast ARIMA Arima"), or "list" then no need to enter the value of fitdf as it will be automatically determined. For obj with other classes, the fitdf is needed for degrees of freedom of asymptotic chi-square distribution.

sqrd.res

if TRUE then apply the test on the squared values. This checks for Autoregressive Conditional Heteroscedastic, ARCH, effects. When sqrd.res = FALSE, then apply the test on the usual residuals.

Author

Esam Mahdi and A.I. McLeod.

Details

However the portmanteau test statistic can be applied directly on the output objects from the built in R functions ar(), ar.ols(), ar.burg(), ar.yw(), ar.mle(), arima(), arim0(), Arima(), auto.arima(), lm(), glm(), and VAR(), it works with output objects from any fitted model. In this case, users should write their own function to fit any model they want, where they may use the built in R functions garch(), garchFit(), fracdiff(), tar(), etc. The object obj represents the output of this function. This output must be a list with at least two outcomes: the fitted residual and the fitdf of the fitted model (list(res = ..., fitdf = ...)). See the following example with the function FitModel().

References

Hosking, J. R. M. (1980). "The Multivariate Portmanteau Statistic". Journal of American Statistical Association, 75, 602-608.

See Also

Box.test, BoxPierce, LjungBox, MahdiMcLeod, LiMcLeod, portest, GetResiduals.

Examples

Run this code
x <- rnorm(100)
Hosking(x)                              ## univariate test
x <- cbind(rnorm(100),rnorm(100))
Hosking(x)                              ## multivariate test
##
##
## 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 (fitdf will be automatically applied)
Hosking(fit,lags,fitdf = 2)                          ## Correct (no need to specify fitdf)
Hosking(fit,lags)                                    ## Correct
## Apply the test statistic on the residuals
res <- ts((fit$resid)[-(1:2), ])
Hosking(res,lags,fitdf = 2)                          ## Correct
Hosking(res,lags)                                    ## Wrong (fitdf is needed!)  
##
##
## Write a function to fit a model: Apply portmanteau test on fitted obj with class "list"
FitModel <- function(data){
    fit <- ar.ols(data, intercept = TRUE, order.max = 2)
    fitdf <- 2
    res <- res <- ts((fit$resid)[-(1:2), ]) 
 list(res=res,fitdf=fitdf)
}
data(WestGerman)
DiffData <- matrix(numeric(3 * 91), ncol = 3)
  for (i in 1:3) 
    DiffData[, i] <- diff(log(WestGerman[, i]), lag = 1)
Fit <- FitModel(DiffData)
Hosking(Fit) 

Run the code above in your browser using DataLab