Description Usage Arguments Value Examples
Estimate VAR by random forest
1 |
data |
a data.frame, and all variables is endogenous variables in VAR. |
indx |
if |
pmax |
a max lag order, default value is 5. |
p |
a fixed lag order. When |
s |
a horizon in local projections, default is 1. Gnerally don't change it. |
An list:
fit_rfAn object of class rfsrc, grow
from the package randomForestSRC
,
and it has minimum OOB MSE in 1:pmax
.
poptimal lag order,and it has minimum OOB MSE.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | library(magrittr)
B1 <- matrix(c(0.2, 0.1, 0.2, 0.3,0.3,0.4,0.2,0.1), 2)
sim_dt <- tsDyn::VAR.sim(B1, n = 200, lag = 2,include = 'none',show.parMat = T) %>%
as.data.frame()
colnames(sim_dt) <- c('y1','y2')
# fit a VAR with max lag order equal 5
fit <- VARrf(sim_dt, pmax = 5)
# fit a VAR with fixed lag order equal 4
fit <- VARrf(sim_dt, p = 4)
# IRF
picdata <- IRFrf(data = sim_dt, pmax = 5, s = 12, shockvar = 1)
ggplot(data = picdata, aes(x = s, y = y1)) + geom_line() +
geom_hline(yintercept = 0) + theme_bw()
# Generalized IRF
IRFrf_gen(data = sim_dt[1:20,], pmax = 3, s = 5, shockvar = 1, ncores = 7)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.