View source: R/causality_predVAR.R
causality_predVAR  R Documentation 
Test for Granger causality using outofsample prediction errors from a vector autoregression (VAR), where the original VAR can be restricted (see Details). The tests include the MSEt approach \insertCiteMcCracken_2007funtimes and MSEcorrelation test as in Chapter 9.3 of \insertCiteGranger_Newbold_2016;textualfuntimes. The bootstrap is used to empirically derive distributions of the statistics.
causality_predVAR(
y,
p = NULL,
cause = NULL,
B = 500L,
test = 0.3,
cl = 1L,
...
)
y 
data frame or 
p 
an integer specifying the order 
cause 
name of the cause variable. If not specified, the first variable in

B 
number of bootstrap replications. Default is 500. 
test 
a numeric value specifying the size of the testing set. If 
cl 
parameter to specify computer cluster for bootstrapping passed to
the package

... 
other arguments passed to the function for VAR estimation.
The arguments include 
The arguments specified in ...
are passed to the VAR
function.
Additionally, lag.restrict
can be specified to remove shortterm 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
.
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 
cause 
the cause variable. 
p 
the AR order used. 
Vyacheslav Lyubchich
causality_pred
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.