An R package for Bayesian Estimation of Structural Vector Autoregressive Models
Provides fast and efficient procedures for Bayesian analysis of Structural Vector Autoregressions. This package estimates a wide range of models, including homo-, heteroskedastic, and non-normal specifications. Structural models can be identified by adjustable exclusion restrictions, time-varying volatility, or non-normality. They all include a flexible three-level equation-specific local-global hierarchical prior distribution for the estimated level of shrinkage for autoregressive and structural parameters. Additionally, the package facilitates predictive and structural analyses such as impulse responses, forecast error variance and historical decompositions, forecasting, verification of heteroskedasticity, non-normality, and hypotheses on autoregressive parameters, as well as analyses of structural shocks, volatilities, and fitted values. Beautiful plots, informative summary functions, and extensive documentation including the vignette by Woźniak (2024) complement all this. The implemented techniques align closely with those presented in Lütkepohl, Shang, Uzeda, & Woźniak (2024), Lütkepohl & Woźniak (2020), and Song & Woźniak (2021). The bsvars package is aligned regarding objects, workflows, and code structure with the R package bsvarSIGNs by Wang & Woźniak (2024), and they constitute an integrated toolset.
- All the models in the bsvars package consist of the Vector
Autoregressive equation, with autoregressive parameters
A
and error termsE
, and the structural equation with a structural matrixB
and shocksU
Y = AX + E (VAR equation)
BE = U (structural equation)
- The models are identified via exclusion restrictions, heteroskedasticity, or non-normality
- The autoregressive parameters
A
and the structural matrixB
feature a three-level local-global hierarchical prior that estimates the equation-specific level of shrinkage - In five models the structural shocks are conditionally normal with
zero mean and diagonal covariance matrix with variances that are:
- equal to one, that is, time invariant
- time-varying following non-centred Stochastic Volatility
- time-varying following centred Stochastic Volatility
- time-varying with stationary Markov Switching
- time-varying with sparse Markov Switching where the number of volatility regimes is estimated
- In three more models non-normal structural shocks follow
- a joint Student-t distribution with estimated degrees-of-freedom parameter
- a finite mixture of normal components and component-specific variances
- a sparse mixture of normal components and component-specific variances where the number of states is estimated
- Specify the models using
specify_bsvar_*
functions, for instance,specify_bsvar_sv$new()
- Estimate the models using the
estimate()
method - Predict the future using the
forecast()
method - Provide structural analyses using impulse responses, forecast
error variance decompositions, historical decompositions, and
structural shocks using functions
compute_impulse_responses()
,compute_variance_decompositions()
,compute_historical_decompositions()
, andcompute_structural_shocks()
respectively - Analyse the fitted values, time-varying volatility, and volatility
regimes using functions
compute_fitted_values()
,compute_conditional_sd()
, andcompute_regime_probabilities()
respectively - Use
plot()
andsummary()
methods to gain the insights into the core of the empirical problem. - Verify heteroskedasticity, non-normality, and hypotheses on
autoregressive parameters using functions
verify_volatility()
andverify_autoregression()
- Extraordinary computational speed is obtained by combining
- the application of frontier econometric and numerical techniques, and
- the implementation using compiled code written in cpp
- It combines the best of two worlds: the ease of data analysis with R and fast cpp algorithms
- The algorithms used here are very fast. But still, Bayesian estimation might take a little time. Look at our beautiful progress bar in the meantime:
**************************************************|
bsvars: Bayesian Structural Vector Autoregressions|
**************************************************|
Gibbs sampler for the SVAR-SV model |
Non-centred SV model is estimated |
**************************************************|
Progress of the MCMC simulation for 1000 draws
Every 10th draw is saved via MCMC thinning
Press Esc to interrupt the computations
**************************************************|
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
*************************************
This beautiful logo can be reproduced in R using this file.
- a vignette by Woźniak (2024)
- a reference manual
- a website of the family of packages bsvars.org
- bsvars on CRAN
- presentations:
- for Bayesian Econometrics students at the University of Melbourne given in October 2024 featuring bsvars 3.1
- for the QuantEcon lab at the Australian National University given in August 2024 featuring bsvars 3.1 and bsvarSIGNs 1.0.1
- at Monash University given in August 2024 featuring bsvars 3.1 and bsvarSIGNs 1.0
- for Workshops for Ukraine given in August 2024 featuring bsvars 3.1
- for Macroeconometrics students at the University of Melbourne given in May 2024 featuring bsvars 2.1.0
The beginnings are as easy as ABC:
library(bsvars) # upload the package
data(us_fiscal_lsuw) # upload data
spec = specify_bsvar_sv$new(us_fiscal_lsuw, p = 4) # specify the model
burn_in = estimate(spec, 1000) # run the burn-in
out = estimate(burn_in, 50000) # estimate the model
fore = forecast(out, horizon = 8) # forecast 2 years ahead
plot(fore) # plot the forecast
irfs = compute_impulse_responses(out, 8) # compute impulse responses
plot(irfs) # plot the impulse responses
The bsvars package supports a simplified workflow using the |>
pipe:
library(bsvars) # upload the package
data(us_fiscal_lsuw) # upload data
us_fiscal_lsuw |>
specify_bsvar_sv$new(p = 4) |> # specify the model
estimate(S = 1000) |> # run the burn-in
estimate(S = 50000) -> out # estimate the model
out |> forecast(horizon = 8) |> plot() # compute and plot forecasts
out |> compute_impulse_responses(8) |> plot() # compute and plot impulse responses
Now, you’re ready to analyse your model!
You must have a cpp compiler. Follow the instructions from Section 1.3. by Eddelbuettel & François (2023). In short, for Windows: install RTools, for macOS: install Xcode Command Line Tools, and for Linux: install the standard development packages.
Just open your R and type:
install.packages("bsvars")
The developer’s version of the package with the newest features can be installed by typing:
devtools::install_github("bsvars/bsvars")
The package is under intensive development. Your help is most welcome! Please, have a look at the roadmap, discuss package features and applications, or report a bug. Thank you!
Tomasz is a Bayesian econometrician and a Senior Lecturer at the University of Melbourne. He develops methodology for empirical macroeconomic analyses and programs in R and cpp using Rcpp.