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 cluster object obtained from makeCluster.

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 bv_priors with prior settings. Used to adjust the Minnesota prior, add custom dummy priors, and choose hyperparameters for hierarchical estimation.

mh

Object from bv_mh with settings for the Metropolis-Hastings step. Used to tune automatic adjustment of the acceptance rate within the burn-in period, or manually adjust the proposal variance.

fcast

Object from bv_fcast with forecast settings. Options include the horizon and settings for conditional forecasts i.e. scenario analysis. May also be calculated ex-post using predict.bvar.

irf

Object from bv_irf with settings for the calculation of impulse responses and forecast error variance decompositions. Options include the horizon and different identification schemes. May also be calculated ex-post using irf.bvar.

Value

Returns a list of class bvar_chain with bvar objects.

See Also

bvar; parLapply

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)

[Package BVAR version 1.0.5 Index]