Learn R Programming

bayesianVARs

Estimation of Bayesian vectorautoregressions with/without stochastic volatility.

Implements several modern hierarchical shrinkage priors and their semi-global refinements allowing for structured shrinkage. Amongst them Dirichlet-Laplace prior (DL), hierarchical Minnesota prior (HM), Horseshoe prior (HS), normal-gamma prior (NG), $R^2$-induced-Dirichlet-decomposition prior (R2D2) and stochastic search variable selection prior (SSVS).

Concerning the error-term, the user can either specify an order-invariant factor structure or an order-variant cholesky structure.

Installation

Install CRAN version:

install.packages("bayesianVARs")

Install latest development version directly from GitHub:

devtools::install_github("luisgruber/bayesianVARs")

Usage

The main workhorse to conduct Bayesian inference for vectorautoregression models in this package is the function bvar().

Some features:

  • Prediction, plotting, extraction of model parameters and extraction of fitted values with the usual generic functions predict(), plot(), coef(), vcov() and fitted().
  • Configure prior distributions with helper functions specify_prior_phi() and specify_prior_sigma().
  • Computation and simulation of impulse response functions withirf() and specification of structural restrictions with helper function specify_structural_restrictions().

Demonstration

set.seed(537)
# load package
library(bayesianVARs)

# Load data
train_data <-100 * usmacro_growth[1:237,c("GDPC1", "PCECC96", "GPDIC1", "AWHMAN", "GDPCTPI", "CES2000000008x", "FEDFUNDS", "GS10", "EXUSUKx", "S&P 500")]
test_data <-100 * usmacro_growth[238:241,c("GDPC1", "PCECC96", "GPDIC1", "AWHMAN", "GDPCTPI", "CES2000000008x", "FEDFUNDS", "GS10", "EXUSUKx", "S&P 500")]
                                   
# Estimate model using default prior settings
mod <- bvar(train_data, lags = 2L, draws = 2000, burnin = 1000, sv_keep = "all")

# Out of sample prediction and log-predictive-likelihood evaluation
pred <- predict(mod, ahead = 1:4, LPL = TRUE, Y_obs = test_data)

# Visualize in-sample fit plus out-of-sample prediction intervals
plot(mod, predictions = pred)

Documentation

browseVignettes(package = "bayesianVARs")
# If installing directly from GitHub, one has to explicitely request vignettes, e.g. with
# devtools::install_github("luisgruber/bayesianVARs", dependencies = TRUE, build_vignettes = TRUE)

Copy Link

Version

Install

install.packages('bayesianVARs')

Monthly Downloads

753

Version

0.1.6

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Luis Gruber

Last Published

January 28th, 2026

Functions in bayesianVARs (0.1.6)

print.summary.bayesianVARs_predict

Print method for summary.bayesianVARs_predict objects
print.bayesianVARs_bvar

Pretty printing of a bvar object
print.summary.bayesianVARs_bvar

Print method for summary.bayesianVARs_bvar objects
residuals.bayesianVARs_bvar

Extract Model Residuals
plot.bayesianVARs_predict

Fan chart
plot.bayesianVARs_residuals

Visualization of the residuals of an estimated VAR.
posterior_heatmap

Posterior heatmaps for matrix valued parameters
predict.bayesianVARs_bvar

Predict method for Bayesian VARs
print.bayesianVARs_predict

Print method for bayesianVARs_predict objects
specify_prior_phi

Specify prior on PHI
stable_bvar

Stable posterior draws
summary.bayesianVARs_predict

Summary method for bayesianVARs_predict objects
summary.bayesianVARs_draws

Summary statistics for bayesianVARs posterior draws.
vcov.bayesianVARs_bvar

Extract posterior draws of the (time-varying) variance-covariance matrix for a VAR model
usmacro_growth

Data from the US-economy
[.bayesianVARs_coef

Extract or Replace Parts of a bayesianVARs_coef object
specify_prior_sigma

Specify prior on Sigma
specify_structural_restrictions

Set identifying restrictions for the structural VAR parameters.
[.bayesianVARs_draws

Extract or Replace Parts of a bayesianVARs_draws object
summary.bayesianVARs_bvar

Summary method for bayesianVARs_bvar objects
pairs_predict

Pairwise visualization of out-of-sample posterior predictive densities.
plot.bayesianVARs_bvar

Plot method for bayesianVARs_bvar
plot.bayesianVARs_irf

Impulse Responses Plot
plot.bayesianVARs_fitted

Visualization of in-sample fit of an estimated VAR.
fitted.bayesianVARs_bvar

Simulate fitted/predicted historical values for an estimated VAR model
extractB0

Retrieve the structural parameter \(\boldsymbol{B}_0\) samples from an IRF object.
my_gig

Draw from generalized inverse Gaussian
irf

Impulse response functions
coef

Extract VAR coefficients
bvar

Markov Chain Monte Carlo Sampling for Bayesian Vectorautoregressions