causality_predVAR: Out-of-sample Tests of Granger Causality using (Restricted)...

View source: R/causality_predVAR.R

causality_predVARR Documentation

Out-of-sample Tests of Granger Causality using (Restricted) Vector Autoregression

Description

Test for Granger causality using out-of-sample prediction errors from a vector autoregression (VAR), where the original VAR can be restricted (see Details). The tests include the MSE-t approach \insertCiteMcCracken_2007funtimes and MSE-correlation test as in Chapter 9.3 of \insertCiteGranger_Newbold_2016;textualfuntimes. The bootstrap is used to empirically derive distributions of the statistics.

Usage

causality_predVAR(
  y,
  p = NULL,
  cause = NULL,
  B = 500L,
  test = 0.3,
  cl = 1L,
  ...
)

Arguments

y

data frame or ts object for estimating VAR(p).

p

an integer specifying the order p in VAR. By default (if p is not specified), p is selected based on the information criterion ic (see ... arguments; default ic is AIC).

cause

name of the cause variable. If not specified, the first variable in y is treated as the dependent variable and the second is treated as the cause.

B

number of bootstrap replications. Default is 500.

test

a numeric value specifying the size of the testing set. If test < 1, the value is treated as a proportion of the sample size to be used as the testing set. Otherwise, test is treated as the number of the most recent values to be used as the testing set. Default is 0.3, which means that 30% of the sample is used for calculating out-of-sample errors. The testing set is always at the end of the time series.

cl

parameter to specify computer cluster for bootstrapping passed to the package parallel (default cl = 1, means no cluster is used). Possible values are:

  • cluster object (list) produced by makeCluster. In this case, a new cluster is not started nor stopped;

  • NULL. In this case, the function will detect available cores (see detectCores) and, if there are multiple cores (>1), a cluster will be started with makeCluster. If started, the cluster will be stopped after the computations are finished;

  • positive integer defining the number of cores to start a cluster. If cl = 1 (default), no attempt to create a cluster will be made. If cl > 1, a cluster will be started (using makeCluster) and stopped afterward (using stopCluster).

...

other arguments passed to the function for VAR estimation. The arguments include lag.restrict that is used to remove the first lags in the cause variable from consideration (use restricted VAR to avoid testing for short-term causality); default lag.restrict = 0L, i.e., no restrictions. Other possible arguments are as in the VAR function. Also, see Details and Examples.

Details

The arguments specified in ... are passed to the VAR function. Additionally, lag.restrict can be specified to remove short-term lags from consideration (lag.restrict is not an option in the original package vars). Note that if p is specified, lag.restrict must be smaller than p otherwise the default lag.restrict = 0 will be used. If lag.max is specified instead of p, VAR orders lag.restrict + 1, ..., lag.max will be considered using the training data and the order p will be automatically selected according to the information criterion (by default, AIC).

In the current implementation, the bootstrapped p-value is calculated using equation 4.10 of \insertCiteDavison_Hinkley_1997;textualfuntimes: p.value = (1 + n) / (B + 1), where n is the number of bootstrapped statistics smaller or equal to the observed statistic. In the fast bootstrap, n is the number of bootstrapped statistics greater or equal to 0.

This function uses symmetric VAR with the same orders p for modeling both Y to X. To select these orders more independently, consider using the function causality_pred.

Value

Two lists (one for the fast bootstrap, another for the bootstrap under the null hypothesis) each containing the following elements:

result

a table with the observed values of the test statistics and p-values.

cause

the cause variable.

p

the AR order used.

Author(s)

Vyacheslav Lyubchich

References

\insertAllCited

See Also

causality_pred

Examples

## Not run: 
# Example 1: Canada time series (ts object)
Canada <- vars::Canada
causality_predVAR(Canada[,1:2], cause = "e", lag.max = 5)
causality_predVAR(Canada[,1:2], cause = "e", lag.restrict = 3, lag.max = 15)

# Example 2 (run in parallel, initiate the cluster manually):
# Box & Jenkins time series
# of sales and a leading indicator, see ?BJsales

# Initiate a local cluster
cores <- parallel::detectCores()
cl <- parallel::makeCluster(cores)
parallel::clusterSetRNGStream(cl, 123) # to make parallel computations reproducible

D <- cbind(BJsales.lead, BJsales)
causality_predVAR(D, cause = "BJsales.lead", lag.max = 5, B = 1000, cl = cl)
causality_predVAR(D, cause = "BJsales.lead", lag.restrict = 3, p = 5, B = 1000, cl = cl)
parallel::stopCluster(cl)

## End(Not run)


funtimes documentation built on March 31, 2023, 7:35 p.m.