par_bvar {BVAR} | R Documentation |
Parallel hierarchical Bayesian vector autoregression
Description
Wrapper for bvar
to simplify parallel computation via
parLapply
. Make sure to properly start and stop the
provided cluster.
Usage
par_bvar(
cl,
n_runs = length(cl),
data,
lags,
n_draw = 10000L,
n_burn = 5000L,
n_thin = 1L,
priors = bv_priors(),
mh = bv_mh(),
fcast = NULL,
irf = NULL
)
Arguments
cl |
A |
n_runs |
The number of parallel runs to calculate. Defaults to the length of cl, i.e. the number of registered nodes. |
data |
Numeric matrix or dataframe. Note that observations are expected to be ordered from earliest to latest, and variables in the columns. |
lags |
Integer scalar. Lag order of the model. |
n_draw , n_burn |
Integer scalar. The number of iterations to (a) cycle through and (b) burn at the start. |
n_thin |
Integer scalar. Every n_thin'th iteration is stored. For a given memory requirement thinning reduces autocorrelation, while increasing effective sample size. |
priors |
Object from |
mh |
Object from |
fcast |
Object from |
irf |
Object from |
Value
Returns a list of class bvar_chain
with bvar
objects.
See Also
Examples
library("parallel")
cl <- makeCluster(2L)
# Access a subset of the fred_qd dataset
data <- fred_qd[, c("CPIAUCSL", "UNRATE", "FEDFUNDS")]
# Transform it to be stationary
data <- fred_transform(data, codes = c(5, 5, 1), lag = 4)
# A singular run using one lag, default settings and very few draws
x <- bvar(data, lags = 1, n_draw = 1000L, n_burn = 200L, verbose = FALSE)
# Two parallel runs
y <- par_bvar(cl, n_runs = 2,
data = data, lags = 1, n_draw = 1000L, n_burn = 200L)
stopCluster(cl)
# Plot lambda for all of the runs
## Not run:
plot(x, type = "full", vars = "lambda", chains = y)
# Convert the hyperparameter lambda to a coda mcmc.list object
coda::as.mcmc(y, vars = "lambda")
## End(Not run)