Learn R Programming

BVAR (version 0.2.2)

bvar: Hierarchical Bayesian Vector Autoregression

Description

Hierarchical Bayesian estimation of Vector Autoregression (VAR) models in the fashion of Giannone et al. (2015). Options for the priors and mh arguments are provided via the functions bv_priors and bv_metropolis. Several methods facilitate analysis, including summary.bvar, plot.bvar, predict.bvar and irf.bvar.

Usage

bvar(
  data,
  lags,
  n_draw = 10000,
  n_burn = 5000,
  n_thin = 1,
  priors = bv_priors(),
  mh = bv_mh(),
  fcast = NULL,
  irf = NULL,
  verbose = TRUE,
  ...
)

# S3 method for bvar print(x, ...)

Arguments

data

Numeric matrix or dataframe. Note that observations need to be ordered from earliest to latest one.

lags

Integer scalar. Number of lags to apply to the data.

n_draw

Integer scalar. Number of total iterations for the model to cycle through.

n_burn

Integer scalar. Number of iterations to discard.

n_thin

Integer scalar. Provides the option of reducing the number of stored iterations to every n_thin'th one. The number of saved iterations thus equals \((n_draw - n_burn) / n_thin\).

priors

bv_priors object containing priors and their settings. See bv_priors.

mh

bv_metropolis object with settings regarding the acceptance rate of the Metropolis-Hastings step. See bv_mh.

fcast

bv_fcast object of forecast options set with bv_fcast. Ideally forecasts are calculated ex-post using predict.bvar. May be set to NULL to skip forecasting.

irf

bv_irf object with options regarding impulse responses and forecast error variance decompositions. Ideally computed ex-post using irf.bvar. Set via bv_irf or skipped when set to NULL.

verbose

Logical scalar. Whether to print intermediate results and progress.

...

Not used.

x

A bvar object.

Value

Returns a bvar object with the following elements:

  • beta - Numeric array with saved draws from the posterior distribution of the VAR coefficients. See coef.bvar.

  • sigma - Numeric array with saved draws from the posterior distribution of the model's VCOV-matrix. See vcov.bvar.

  • hyper - Numeric matrix with saved draws from the posterior distributions of the hierarchical priors' hyperparameters.

  • ml - Numeric vector with the values of the posterior marginal likelihood corresponding to each draw of hyperparameters and associated VAR coefficients.

  • optim - List with outputs from optim, which is used to find suitable starting values.

  • prior - bv_priors object. See bv_priors.

  • call - Call to the function. See match.call.

  • meta - List with meta information such as number of variables, accepted draws, number of iterations, et cetera.

  • variables - Character vector with the column names of data.

  • fcast - bvar_fcast object with posterior forecast draws, quantiles as well as the forecast's setup from the fcast argument.

  • irf - bvar_irf object with posterior impulse response and their quantiles, forecast error variance decomposition draws, as well as the setup from the irf argument.

References

Giannone, D., Lenza, M., & Primiceri, G. E. (2015). Prior Selection for Vector Autoregressions. Review of Economics and Statistics, 97, 436-451. https://doi.org/10.1162/REST_a_00483.

See Also

bv_priors; bv_mh; bv_fcast; bv_irf; predict.bvar; irf.bvar; plot.bvar;

Examples

Run this code
# NOT RUN {
# Access a subset of the fred_qd dataset and transform it to be stationary
data("fred_qd")
data <- fred_qd[, c("CPIAUCSL", "UNRATE", "FEDFUNDS")]
data[5:nrow(data), 1] <- diff(log(data[, 1]), lag = 4) * 100
data <- data[5:nrow(data), ]

# Compute VAR using 2 lags and a ridiculously low number of draws
x <- bvar(data = data, lags = 1,
          n_draw = 500, n_burn = 400, n_thin = 2, verbose = FALSE)

# }
# NOT RUN {
# Check out some of the outputs generated
plot(x)
predict(x)
plot(predict(x))
irf(x)
plot(irf(x))
# }

Run the code above in your browser using DataLab