bvar: Hierarchical Bayesian vector autoregression

View source: R/10_bvar.R

bvarR Documentation

Hierarchical Bayesian vector autoregression

Description

Used to estimate hierarchical Bayesian Vector Autoregression (VAR) models in the fashion of Giannone, Lenza and Primiceri (2015). Priors are adjusted and added via bv_priors. The Metropolis-Hastings step can be modified with bv_mh.

Usage

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

Arguments

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.

verbose

Logical scalar. Whether to print intermediate results and progress.

...

Not used.

Details

The model can be expressed as:

y_t = a_0 + A_1 y_{t-1} + ... + A_p y_{t-p} + \epsilon_t

See Kuschnig and Vashold (2021) and Giannone, Lenza and Primiceri (2015) for further information. Methods for a bvar object and its derivatives can be used to:

  • predict and analyse scenarios;

  • evaluate shocks and the variance of forecast errors;

  • visualise forecasts and impulse responses, parameters and residuals;

  • retrieve coefficents and the variance-covariance matrix;

  • calculate fitted and residual values;

Note that these methods generally work by calculating quantiles from the posterior draws. The full posterior may be retrieved directly from the objects. The function str can be very helpful for this.

Value

Returns a list of class bvar with the following elements:

  • beta - Numeric array with draws from the posterior of the VAR coefficients. Also see coef.bvar.

  • sigma - Numeric array with draws from the posterior of the variance-covariance matrix. Also see vcov.bvar.

  • hyper - Numeric matrix with draws from the posterior of the hierarchically treated hyperparameters.

  • ml - Numeric vector with the marginal likelihood (with respect to the hyperparameters), that determines acceptance probability.

  • optim - List with outputs of optim, which is used to find starting values for the hyperparameters.

  • prior - Prior settings from bv_priors.

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

  • meta - List with meta information. Includes the number of variables, accepted draws, number of iterations, and data.

  • variables - Character vector with the column names of data. If missing, variables are named iteratively.

  • explanatories - Character vector with names of explanatory variables. Formatting is akin to: "FEDFUNDS-lag1".

  • fcast - Forecasts from predict.bvar.

  • irf - Impulse responses from irf.bvar.

Author(s)

Nikolas Kuschnig, Lukas Vashold

References

Giannone, D. and Lenza, M. and Primiceri, G. E. (2015) Prior Selection for Vector Autoregressions. The Review of Economics and Statistics, 97:2, 436-451, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1162/REST_a_00483")}.

Kuschnig, N. and Vashold, L. (2021) BVAR: Bayesian Vector Autoregressions with Hierarchical Prior Selection in R. Journal of Statistical Software, 14, 1-27, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v100.i14")}.

See Also

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

Examples

# 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)

# Estimate a BVAR using one lag, default settings and very few draws
x <- bvar(data, lags = 1, n_draw = 1000L, n_burn = 200L, verbose = FALSE)

# Calculate and store forecasts and impulse responses
predict(x) <- predict(x, horizon = 8)
irf(x) <- irf(x, horizon = 8, fevd = FALSE)

## Not run: 
# Check convergence of the hyperparameters with a trace and density plot
plot(x)
# Plot forecasts and impulse responses
plot(predict(x))
plot(irf(x))
# Check coefficient values and variance-covariance matrix
summary(x)

## End(Not run)

BVAR documentation built on March 31, 2023, 11:59 p.m.