# \donttest{
# select minimal or full example #
is_min = TRUE
n.boot = ifelse(is_min, 50, 5000)
# prepare the data, estimate and test the VAR model #
set.seed(23211)
library("vars")
data("Canada")
exogen = cbind(qtrend=(1:nrow(Canada))^2) # quadratic trend
R.vars = VAR(Canada, p=2, type="both", exogen=exogen)
R.norm = rboot.normality(x=R.vars, n.boot=n.boot, n.cores=1)
# density plot #
library("ggplot2")
R.data = data.frame(t(R.norm$sim[ , "MULTI", ]))
R.args = list(df=2*R.vars$K)
F.density = ggplot() +
stat_density(data=R.data, aes(x=JB, color="bootstrap"), geom="line") +
stat_function(fun=dchisq, args=R.args, n=500, aes(color="theoretical")) +
labs(x="JB statistic", y="Density", color="Distribution", title=NULL) +
theme_bw()
plot(F.density)
# }
Run the code above in your browser using DataLab