Skip to contents

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, and include exclusion restrictions on autoregressive parameters. 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 and hypotheses on autoregressive parameters, and analyses of structural shocks, volatilities, and fitted values. Beautiful plots, informative summary functions, and extensive documentation including the vignette by Woźniak (2024) <doi:10.48550/arXiv.2410.15090> complement all this. The implemented techniques align closely with those presented in Lütkepohl, Shang, Uzeda, & Woźniak (2024) <doi:10.48550/arXiv.2404.11057>, Lütkepohl & Woźniak (2020) <doi:10.1016/j.jedc.2020.103862>, Song & Woźniak (2021) <doi:10.1093/acrefore/9780190625979.013.174>, and Woźniak & Droumaguet (2015) <doi:10.13140/RG.2.2.19492.55687>. The 'bsvars' package is aligned regarding objects, workflows, and code structure with the R package 'bsvarSIGNs' by Wang & Woźniak (2024) <doi:10.32614/CRAN.package.bsvarSIGNs>, and they constitute an integrated toolset.

Details

Models. All the SVAR models in this package are specified by two equations, including the reduced form equation: $$Y = AX + E$$ where \(Y\) is an NxT matrix of dependent variables, \(X\) is a KxT matrix of explanatory variables, \(E\) is an NxT matrix of reduced form error terms, and \(A\) is an NxK matrix of autoregressive slope coefficients and parameters on deterministic terms in \(X\).

The structural equation is given by: $$BE = U$$ where \(U\) is an NxT matrix of structural form error terms, and \(B\) is an NxN matrix of contemporaneous relationships.

Finally, all of the models share the following assumptions regarding the structural shocks U, namely, joint conditional normality given the past observations collected in matrix X, and temporal and contemporaneous independence. The latter implies zero correlations and autocorrelations.

The various SVAR models estimated differ by the specification of structural shocks variances. The different models include:

  • homoskedastic model with unit variances

  • heteroskedastic model with stationary Markov switching in the variances

  • heteroskedastic model with non-centred Stochastic Volatility process for variances

  • heteroskedastic model with centred Stochastic Volatility process for variances

  • a model with Student-t distributed structural shocks with estimated equation-specific degrees-of-freedom parameter

  • non-normal model with a finite mixture of normal components and component-specific variances

  • heteroskedastic model with sparse Markov switching in the variances where the number of heteroskedastic components is estimated

  • non-normal model with a sparse mixture of normal components and component-specific variances where the number of heteroskedastic components is estimated

Prior distributions. All the models feature a Minnesota prior for autoregressive parameters in matrix \(A\) and a generalised-normal distribution for the structural matrix \(B\). Both of these distributions feature a 3-level equation-specific local-global hierarchical prior that make the shrinkage estimation flexible improving the model fit and its forecasting performance.

Estimation algorithm. The models are estimated using frontier numerical methods making the Gibbs sampler fast and efficient. The sampler of the structural matrix follows Waggoner & Zha (2003), whereas that for autoregressive parameters follows Chan, Koop, Yu (2022). The specification of Markov switching heteroskedasticity is inspired by Song & Woźniak (2021), and that of Stochastic Volatility model by Kastner & Frühwirth-Schnatter (2014). The estimation algorithms for particular models are scrutinised in Lütkepohl, Shang, Uzeda, & Woźniak (2024) and Woźniak & Droumaguet (2024) and some other inferential and identification problems are considered in Lütkepohl & Woźniak (2020).

Note

This package is currently in active development. Your comments, suggestions and requests are warmly welcome!

References

Chan, J.C.C., Koop, G, and Yu, X. (2024) Large Order-Invariant Bayesian VARs with Stochastic Volatility. Journal of Business & Economic Statistics, 42, doi:10.1080/07350015.2023.2252039 .

Kastner, G. and Frühwirth-Schnatter, S. (2014) Ancillarity-Sufficiency Interweaving Strategy (ASIS) for Boosting MCMC Estimation of Stochastic Volatility Models. Computational Statistics & Data Analysis, 76, 408–423, doi:10.1016/j.csda.2013.01.002 .

Lütkepohl, H., Shang, F., Uzeda, L., and Woźniak, T. (2024) Partial Identification of Heteroskedastic Structural VARs: Theory and Bayesian Inference. University of Melbourne Working Paper, 1–57, doi:10.48550/arXiv.2404.11057 .

Lütkepohl, H., and Woźniak, T., (2020) Bayesian Inference for Structural Vector Autoregressions Identified by Markov-Switching Heteroskedasticity. Journal of Economic Dynamics and Control 113, 103862, doi:10.1016/j.jedc.2020.103862 .

Song, Y., and Woźniak, T. (2021) Markov Switching Heteroskedasticity in Time Series Analysis. In: Oxford Research Encyclopedia of Economics and Finance. Oxford University Press, doi:10.1093/acrefore/9780190625979.013.174 .

Waggoner, D.F., and Zha, T., (2003) A Gibbs sampler for structural vector autoregressions. Journal of Economic Dynamics and Control, 28, 349–366, doi:10.1016/S0165-1889(02)00168-9 .

Woźniak, T., and Droumaguet, M., (2024) Bayesian Assessment of Identifying Restrictions for Heteroskedastic Structural VARs.

Author

Tomasz Woźniak wozniak.tom@pm.me

Examples

# upload data
data(us_fiscal_lsuw)    # upload dependent variables
data(us_fiscal_ex)      # upload exogenous variables

# specify the model and set seed
set.seed(123)
specification  = specify_bsvar_sv$new(us_fiscal_lsuw, p = 1, exogenous = us_fiscal_ex)
#> The identification is set to the default option of lower-triangular structural matrix.

# run the burn-in
burn_in        = estimate(specification, 5)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 5 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|

# estimate the model
posterior      = estimate(burn_in, 10)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 10 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|

# compute impulse responses one year ahead
irf           = compute_impulse_responses(posterior, horizon = 2)

# compute forecast error variance decomposition one year ahead
fevd           = compute_variance_decompositions(posterior, horizon = 4)

# workflow with the pipe |>
############################################################
set.seed(123)
us_fiscal_lsuw |>
  specify_bsvar_sv$new(p = 1, exogenous = us_fiscal_ex) |>
  estimate(S = 5) |> 
  estimate(S = 10) |> 
  compute_variance_decompositions(horizon = 4) -> fevds
#> The identification is set to the default option of lower-triangular structural matrix.
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 5 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 10 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|

# conditional forecasting using a model with exogenous variables
############################################################
data(us_fiscal_ex_forecasts)      # upload exogenous variables future values
data(us_fiscal_cond_forecasts)    # upload a matrix with projected ttr

set.seed(123)
us_fiscal_lsuw |>
  specify_bsvar_sv$new(p = 1, exogenous = us_fiscal_ex) |>
  estimate(S = 5) |> 
  estimate(S = 10) -> posterior
#> The identification is set to the default option of lower-triangular structural matrix.
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 5 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 10 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
  
 posterior |> forecast(
    horizon = 8,
    exogenous_forecast = us_fiscal_ex_forecasts,
    conditional_forecast = us_fiscal_cond_forecasts
  ) -> predictive
  
  predictive |> summary()
#>  **************************************************|
#>  bsvars: Bayesian Structural Vector Autoregressions|
#>  **************************************************|
#>    Posterior summary of forecasts                  |
#>  **************************************************|
#> $variable1
#>        mean sd 5% quantile 95% quantile
#> 1 -8.914237  0   -8.914237    -8.914237
#> 2 -8.908921  0   -8.908921    -8.908921
#> 3 -8.903604  0   -8.903604    -8.903604
#> 4 -8.898288  0   -8.898288    -8.898288
#> 5 -8.892971  0   -8.892971    -8.892971
#> 6 -8.887655  0   -8.887655    -8.887655
#> 7 -8.882338  0   -8.882338    -8.882338
#> 8 -8.877022  0   -8.877022    -8.877022
#> 
#> $variable2
#>        mean         sd 5% quantile 95% quantile
#> 1 -9.807578 0.02620802   -9.851238    -9.779322
#> 2 -9.810974 0.04133350   -9.869271    -9.760496
#> 3 -9.814198 0.04761576   -9.875812    -9.753942
#> 4 -9.813673 0.06063877   -9.891039    -9.737388
#> 5 -9.813226 0.07618672   -9.913654    -9.718430
#> 6 -9.822374 0.08913250   -9.940681    -9.718759
#> 7 -9.812894 0.08245051   -9.921437    -9.688456
#> 8 -9.800520 0.09376893   -9.917567    -9.669746
#> 
#> $variable3
#>        mean         sd 5% quantile 95% quantile
#> 1 -6.918741 0.16196022   -7.091722    -6.638308
#> 2 -7.103088 0.07985092   -7.204332    -6.990256
#> 3 -7.039501 0.15427734   -7.251881    -6.813179
#> 4 -7.050201 0.18270698   -7.308895    -6.808690
#> 5 -6.928176 0.14053971   -7.141007    -6.735026
#> 6 -6.947533 0.10699443   -7.084129    -6.787344
#> 7 -6.927049 0.14183971   -7.144199    -6.772969
#> 8 -6.927177 0.20875749   -7.177887    -6.613856
#> 
  predictive |> plot(probability = 0.68)

  
# estimation of a model with exogeneity restrictions on the  autoregressive matrix
############################################################
set.seed(123)
A = matrix(TRUE, 3, 7)
A[1,3] = A[1,6] = FALSE
us_fiscal_lsuw |>
  specify_bsvar_sv$new(p = 2, A = A) |>
  estimate(S = 5) |> 
  estimate(S = 10) -> posterior
#> The identification is set to the default option of lower-triangular structural matrix.
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 5 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#>  Gibbs sampler for the SVAR-SV model              |
#>    Non-centred SV model is estimated              |
#> **************************************************|
#>  Progress of the MCMC simulation for 10 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
posterior |> summary()
#>  **************************************************|
#>  bsvars: Bayesian Structural Vector Autoregressions|
#>  **************************************************|
#>    Posterior summary of the parameters             |
#>  **************************************************|
#> $B
#> $B$equation1
#>             mean         sd 5% quantile 95% quantile
#> B[1,1] 0.8281532 0.04628699   0.7601291     0.884352
#> 
#> $B$equation2
#>             mean       sd 5% quantile 95% quantile
#> B[2,1] -19.94384 1.077020   -21.31002    -18.46195
#> B[2,2]  36.81909 2.017702    33.99173     39.36692
#> 
#> $B$equation3
#>              mean        sd 5% quantile 95% quantile
#> B[3,1] -39.783541 3.2094247  -43.648314   -35.080221
#> B[3,2] -18.436292 2.0814790  -21.524541   -16.045719
#> B[3,3]   7.570582 0.5181408    6.961117     8.390481
#> 
#> 
#> $A
#> $A$equation1
#>                  mean         sd 5% quantile 95% quantile
#> lag1_var1  1.02734961 0.05062726  0.95969754   1.09129058
#> lag1_var1  0.01955853 0.06059090 -0.06825852   0.09418168
#> lag1_var2  0.00000000 0.00000000  0.00000000   0.00000000
#> lag2_var2 -0.14487932 0.05318257 -0.21121899  -0.07305876
#> lag2_var3 -0.01998247 0.05792600 -0.09320922   0.06192935
#> lag2_var3  0.00000000 0.00000000  0.00000000   0.00000000
#> const     -0.02017513 0.11791755 -0.13218487   0.16747109
#> 
#> $A$equation2
#>                  mean         sd  5% quantile 95% quantile
#> lag1_var1  0.09072031 0.06488892 -0.005152796   0.17750546
#> lag1_var1  1.35339977 0.04264534  1.298700659   1.41840697
#> lag1_var2  0.03551226 0.09025436 -0.077685938   0.17164693
#> lag2_var2 -0.13893082 0.06009426 -0.222892943  -0.05909279
#> lag2_var3 -0.39003460 0.03887292 -0.442629033  -0.33677553
#> lag2_var3 -0.04532772 0.09674371 -0.180966679   0.07676069
#> const     -0.30300248 0.10332803 -0.443786257  -0.15163619
#> 
#> $A$equation3
#>                  mean        sd 5% quantile 95% quantile
#> lag1_var1 -0.30973421 0.2683566 -0.67401042 -0.007648606
#> lag1_var1 -0.05380371 0.1795839 -0.30174752  0.147854668
#> lag1_var2  0.57381476 0.1684270  0.31401962  0.733430413
#> lag2_var2 -0.15527825 0.2245874 -0.41950154  0.164988786
#> lag2_var3  0.08827299 0.1876388 -0.14219006  0.349134221
#> lag2_var3  0.05649344 0.1766342 -0.19353992  0.236656146
#> const      0.33435161 0.2252866  0.04387097  0.641598297
#> 
#> 
#> $hyper
#> $hyper$B
#>                            mean         sd 5% quantile 95% quantile
#> B[1,]_shrinkage        20.64044   9.959616    9.037995     34.95205
#> B[2,]_shrinkage       200.03666  91.054811  104.434520    331.92063
#> B[3,]_shrinkage       224.16491  51.299994  170.887803    301.14505
#> B[1,]_shrinkage_scale 245.37057 145.022032  125.509743    498.36315
#> B[2,]_shrinkage_scale 448.04693 350.468391  140.556787   1078.20197
#> B[3,]_shrinkage_scale 457.84783 368.193590  148.327160   1128.63297
#> B_global_scale         32.02609  24.307723   12.148379     75.37094
#> 
#> $hyper$A
#>                            mean        sd 5% quantile 95% quantile
#> A[1,]_shrinkage       0.3820641 0.2637251   0.1615489    0.8236607
#> A[2,]_shrinkage       0.3071936 0.1660522   0.1287482    0.5366894
#> A[3,]_shrinkage       0.3500886 0.3221947   0.1422525    0.9004749
#> A[1,]_shrinkage_scale 3.9848936 1.5491911   1.9936165    6.1320778
#> A[2,]_shrinkage_scale 3.7675588 2.1672289   1.7290065    7.2092064
#> A[3,]_shrinkage_scale 3.7955356 1.0838053   2.2705629    5.0615578
#> A_global_scale        0.4986532 0.1097576   0.3818226    0.6729104
#> 
#>