GithubHelp home page GithubHelp logo

bsvars / bsvartvps Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 9.0 351 KB

Bayesian Estimation of Heteroskedastic Structural Vector Autoregressions with Markov-Switching and Time-Varying Identification of the Structural Matrix

License: Other

R 14.59% C 4.12% C++ 81.29%
bayesian r-package rstats bsvars structural-vector-autoregressions markov-switching stochastic-volatility global-local-prior time-varying-identification

bsvartvps's Introduction

bsvars bsvars website

An R package for Bayesian Estimation of Structural Vector Autoregressive Models

CRAN version R-CMD-check

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 and hypotheses on autoregressive parameters, and analyses of structural shocks, volatilities, and fitted values. Beautiful plots, informative summary functions, and extensive documentation complement all this. The implemented techniques align closely with those presented in Lütkepohl, Shang, Uzeda, & Woźniak (2024), Lütkepohl & Woźniak (2020), Song & Woźniak (2021), and Woźniak & Droumaguet (2015).

Features

Structural Vector Autoregressions

  • All the models in the bsvars package consist of the Vector Autoregressive equation, with autoregressive parameters A and error terms E, and the structural equation with structural shocks U
    Y = AX + E           (VAR equation)
   BE = U                (structural equation)
  • The models are identified via exclusion restrictions, heteroskedasticity, or non-normality
  • Autoregressive parameters A and the structural matrix B are 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
    • 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 two more models non-normal structural shocks following
    • 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

Simple workflows

  • Specify the models using specify_bsvar_*() functions, for instance, specify_bsvar()
  • 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(), and compute_structural_shocks() respectively
  • Analyse the fitted values, time-varying volatility, and volatility regimes using functions compute_fitted_values(), compute_conditional_sd(), and compute_regime_probabilities() respectively
  • Use plot() and summary() methods to gain the insights into the core of the empirical problem.

Fast and efficient computations

  • Extraordinary computational speed is obtained by combining
    • the implementation of frontier econometric techniques, and
    • 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%
[----|----|----|----|----|----|----|----|----|----|
*************************************

The hexagonal logo

This beautiful logo can be reproduced in R using this file.

bsvars website

Start your Bayesian analysis of data

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

Starting from bsvars version 2.0.0 a simplified workflow using the |> pipe is possible:

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

Now, you’re ready to analyse your model!

Installation

The first time you install the package

You must have a cpp compiler. Follow the instructions from Section 1.3. by Eddelbuettel & François (2023). In short:

Windows: install RTools.

macOS: install Xcode Command Line Tools.

Linux: install the standard developement packages.

Once that’s done:

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_git("https://github.com/bsvars/bsvars.git")

Development

The package is under intensive development. Your help is welcome! Please, have a look at the roadmap, discuss package features and applications, or report a bug. Thank you!

About the author

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.

bsvartvps's People

Contributors

donotdespair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bsvartvps's Issues

Implement models with 3-level local global hierarchical priors for `B` and `A`

Prior shrinkage structure

for B matrix

$$ B_n | \gamma_{Bn} \sim\mathcal{N}_{r_n}(0, \gamma _{Bn} I _{r_n}) $$

$$ \gamma _{Bn} | \underline{s} _{Bn} \sim\mathcal{IG}2 (\underline{s} _{Bn}, \underline{\nu} _{B}) $$

$$ \underline{s} _{Bn} | \underline{s} _{B} \sim\mathcal{G} (\underline{s} _{B}, \underline{a} _{B}) $$

$$ \underline{s} _{B} \sim\mathcal{IG}2 (\underline{s} _{BB}, \underline{\nu} _{BB} ) $$

for A matrix

$$ A_n | \gamma_{An} \sim\mathcal{N}_{K}(\underline{A} _n, \gamma _{An} I _{K}) $$

$$ \gamma _{An} | \underline{s} _{An} \sim\mathcal{IG}2 (\underline{s} _{An}, \underline{\nu} _{A}) $$

$$ \underline{s} _{An} | \underline{s} _{A} \sim\mathcal{G} (\underline{s} _{A}, \underline{a} _{A}) $$

$$ \underline{s} _{A} \sim\mathcal{IG}2 (\underline{s} _{AA}, \underline{\nu} _{AA} ) $$

TO-DO LIST

  • rename the functions and classes from S5 to TVI
  • TVI-SVAR-SV
  • MS-SVAR-SV
  • MS-TVI-SVAR-SV

consider also hommoskedastic models

  • TVI-SVAR
  • MS-SVAR
  • MS-TVI-SVAR

Regime-specific impulse response functions

  • revise bsvars functions and create bsvar_ir1
  • ir for MS models
  • R wrappers with arrays
  • ir for S4 models single-multiple regimes
  • documentation
  • examples
  • plot with dependencies on HDInterval hdi?

vignette

Hey @aschnuecker I am planning roadmap #8 for this package and included a vignette already here. No rush, though, until we finalise the manuscript. :)

include dataset

Hey @aschnuecker I am planning roadmap #8 for this package and included a mention of the dataset. No rush, though, until we finalise the manuscript. :)

reporting conditional second moments

cpp functions and R methods

  • SF standard deviations
  • RF standard deviations
  • RF covariances
  • RF correlations

for all the models

  • MS-TVI-SVAR-SV
  • TVI-SVAR-SV
  • MS-SVAR-SV
  • MS-TVI-SVAR
  • TVI-SVAR
  • MS-SVAR

features

  • thinning
  • methods for PosteriorCovariances

Roadmap

  • impulse response computations
  • assign classes for Bayesian model estimation output
  • impulse response plot
  • conditional variance compute and plot
  • state probabilities compute and plot
  • compute_S5_component_density
  • plots for component probabilities
  • drop_sv and drag_sv functions to simplify the estimation output
  • functions to thin_MCMC and split to with and without SV estimates
  • HERE: B matrix draws normalisation via normalise method
  • HERE: develop normalise. functions for separate classes

prepare `specify_` classes

Models

  • PosteriorBSVARSVMSTVI
  • PosteriorBSVARSVMS
  • PosteriorBSVARSVTVI
  • PosteriorBSVARMSTVI
  • PosteriorBSVARMS
  • PosteriorBSVARTVI

defensve programming for Gibbs sampler

  • change sample_* functions so they do not update by reference
  • include the bsvars functions that need to be changed as in the point above
  • implement exemptions handling in Gibbs samplers using try {} catch (...) {}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.