Learn R Programming

BVAR (version 0.1.5)

bvar: Hierarchical Bayesian Vector Autoregression

Description

Hierarchical Bayesian estimation of VAR models in the fashion of Giannone et al. (2015).

Usage

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

Arguments

data

Numeric matrix or dataframe. 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. Option to reduce the number of stored iterations to every n_thinth one. The number of saved iterations will thus be (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. Forecast options set with bv_fcast. May be set to NULL to skip forecasting.

irf

bv_irf object. Options regarding impulse responses, set via bv_irf. May be set to NULL to skip the calculation of impulse responses.

verbose

Logical scalar. Whether to print intermediate results and progress.

...

Not used.

Value

Returns a bvar object with the following elements:

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

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

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

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

  • optim - List with outputs from optim.

  • 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.

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

  • irf - bvar_irf object with posterior impulse response draws, as well as the impulse response setup from irf.

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

Examples

Run this code
# NOT RUN {
# Access the fred_qd dataset and transform it
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
)

# Plot various outputs generated
# }
# NOT RUN {
plot(x)
bv_plot_fcast(x)
bv_plot_irf(x)
# }

Run the code above in your browser using DataLab