diff --git a/.Rbuildignore b/.Rbuildignore index 3a82aad..0a5ed1f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,6 @@ ^bsvarSIGNs\.Rproj$ ^\.Rproj\.user$ ^/inst/varia$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..c9f0165 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +permissions: read-all + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 2b050fe..1d87a65 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ rsconnect/ .DS_Store .quarto *.so +docs diff --git a/DESCRIPTION b/DESCRIPTION index ebceed0..fff47e5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,9 +3,9 @@ Type: Package Title: Bayesian Estimation of Structural Vector Autoregressions Identified by Sign, Zero, and Narrative Restrictions Version: 0.1.9000 Date: 2024-01-11 -Authors@R: c(person("Xiaolei", "Wang", , "adamwang15@gmail.com", role = c("aut", "cre")),person("Tomasz", "WoĆșniak", , "wozniak.tom@pm.me", role = c("aut"), comment = c(ORCID = "0000-0003-2212-2378"))) +Authors@R: c(person("Xiaolei", "Wang", , "adamwang15@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0009-0005-6192-9061")),person("Tomasz", "WoĆșniak", , "wozniak.tom@pm.me", role = c("aut"), comment = c(ORCID = "0000-0003-2212-2378"))) Maintainer: Xiaolei Wang -Description: Implements state-of-the-art algorithms for the Bayesian analysis of Structural Vector Autoregressions identified by sign, zero, and narrative restrictions. The core model is based on the flexible Vector Autoregression with the estimated hyper-parameters of the Minnesota prior as in Giannone, Lenza, Primiceri (2015) . The sign restrictions are implemented employing the methods outlined by Rubio-RamĂ­rez, Waggoner & Zha (2010) , while identification through sign and zero restrictions follows the approach developed by Arias, Rubio-RamĂ­rez, & Waggoner (2018) . Furthermore, our tool provides algorithms for identification via sign and narrative restrictions, in line with the methods introduced by AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018) . Users can also estimate a model with sign, zero, and narrative restrictions imposed at once. The package facilitates predictive and structural analyses using impulse responses, forecast error variance and historical decompositions, forecasting and conditional forecasting, as well as analyses of structural shocks and fitted values. All this is complemented by colourful plots, user-friendly summary functions, and comprehensive documentation. The `bsvarSIGNs` package is aligned regarding code structure, objects, and workflows with the R package 'bsvars' by WoĆșniak (2024) , and they constitute an integrated toolset. +Description: Implements state-of-the-art algorithms for the Bayesian analysis of Structural Vector Autoregressions identified by sign, zero, and narrative restrictions. The core model is based on a flexible Vector Autoregression with estimated hyper-parameters of the Minnesota prior as in Giannone, Lenza, Primiceri (2015) . The sign restrictions are implemented employing the methods proposed by Rubio-RamĂ­rez, Waggoner & Zha (2010) , while identification through sign and zero restrictions follows the approach developed by Arias, Rubio-RamĂ­rez, & Waggoner (2018) . Furthermore, our tool provides algorithms for identification via sign and narrative restrictions, in line with the methods introduced by AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018) . Users can also estimate a model with sign, zero, and narrative restrictions imposed at once. The package facilitates predictive and structural analyses using impulse responses, forecast error variance and historical decompositions, forecasting and conditional forecasting, as well as analyses of structural shocks and fitted values. All this is complemented by colourful plots, user-friendly summary functions, and comprehensive documentation. The `bsvarSIGNs` package is aligned regarding objects, workflows, and code structure with the R package 'bsvars' by WoĆșniak (2024) , and they constitute an integrated toolset. License: GPL (>= 3) Imports: R6, @@ -21,6 +21,8 @@ Depends: R (>= 2.10), bsvars Suggests: tinytest +URL: https://bsvars.github.io/bsvarSIGNs/ +BugReports: https://github.com/bsvars/bsvarSIGNs/issues Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.2 diff --git a/R/bsvarSIGNs-package.R b/R/bsvarSIGNs-package.R index cc935ec..947b454 100644 --- a/R/bsvarSIGNs-package.R +++ b/R/bsvarSIGNs-package.R @@ -24,10 +24,10 @@ #' #' @description Implements state-of-the-art algorithms for the Bayesian analysis #' of Structural Vector Autoregressions identified by sign, zero, and narrative -#' restrictions. The core model is based on the flexible Vector Autoregression -#' with the estimated hyper-parameters of the Minnesota prior as in +#' restrictions. The core model is based on a flexible Vector Autoregression with +#' estimated hyper-parameters of the Minnesota prior as in #' Giannone, Lenza, Primiceri (2015) . The sign -#' restrictions are implemented employing the methods outlined by +#' restrictions are implemented employing the methods proposed by #' Rubio-RamĂ­rez, Waggoner & Zha (2010) , #' while identification through sign and zero restrictions follows the approach #' developed by Arias, Rubio-RamĂ­rez, & Waggoner (2018) . @@ -40,8 +40,8 @@ #' forecasting and conditional forecasting, as well as analyses of structural #' shocks and fitted values. All this is complemented by colourful plots, #' user-friendly summary functions, and comprehensive documentation. The -#' `bsvarSIGNs` package is aligned regarding code structure, objects, and -#' workflows with the R package 'bsvars' by +#' `bsvarSIGNs` package is aligned regarding objects, workflows, and code +#' structure with the R package 'bsvars' by #' WoĆșniak (2024) , and they constitute an #' integrated toolset. #' @@ -127,17 +127,24 @@ #' WoĆșniak (2024) bsvars: Bayesian Estimation of Structural Vector Autoregressive Models. R package version 3.1, . #' #' @examples -#' # specify sign and zero restrictions on the impulse response +#' # investigate the effects of the optimism shock +#' data(optimism) +#' +#' # specify identifying restrictions: +#' # + no effect on productivity (zero restriction) +#' # + positive effect on stock prices (positive sign restriction) #' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) #' #' # specify the model -#' spec = specify_bsvarSIGN$new(optimism * 100, +#' specification = specify_bsvarSIGN$new(optimism * 100, #' p = 4, #' sign_irf = sign_irf) +#' +#' # estimate the model +#' posterior = estimate(specification, S = 100) #' -#' # estimate the hyper-parameters -#' spec$prior$estimate_hyper() +#' # compute and plot impulse responses +#' irf = compute_impulse_responses(posterior, horizon = 40) +#' plot(irf, probability = 0.68) #' -#' # estimate the model -#' post = estimate(spec, S = 1000) NULL diff --git a/README.Rmd b/README.Rmd index e48746c..fa15e39 100644 --- a/README.Rmd +++ b/README.Rmd @@ -22,74 +22,158 @@ An **R** package for Bayesian Estimation of Structural Vector Autoregressions Id [![R-CMD-check](https://github.com/bsvars/bsvarSIGNs/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bsvars/bsvarSIGNs/actions/workflows/R-CMD-check.yaml) -Implements state-of-the-art algorithms for the Bayesian analysis of Structural Vector Autoregressions identified by sign, zero, and narrative restrictions. The core model is based on the flexible Vector Autoregression with the estimated hyper-parameters of the Minnesota prior as in [Giannone, Lenza, Primiceri (2015)](http://doi.org/10.1162/REST_a_00483). The sign restrictions are implemented employing the methods outlined by [Rubio-RamĂ­rez, Waggoner & Zha (2010)](http://doi.org/10.1111/j.1467-937X.2009.00578.x), while identification through sign and zero restrictions follows the approach developed by [Arias, Rubio-RamĂ­rez, & Waggoner (2018)](http://doi.org/10.3982/ECTA14468). Furthermore, our tool provides algorithms for identification via sign and narrative restrictions, in line with the methods introduced by [AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018)](http://doi.org/10.1257/aer.20161852). Users can also estimate a model with sign, zero, and narrative restrictions imposed at once. The package facilitates predictive and structural analyses using impulse responses, forecast error variance and historical decompositions, forecasting and conditional forecasting, as well as analyses of structural shocks and fitted values. All this is complemented by colourful plots, user-friendly summary functions, and comprehensive documentation. The **bsvarSIGNs** package is aligned regarding code structure, objects, and workflows with the **R** package **bsvars** by [WoĆșniak (2024)](http://doi.org/10.32614/CRAN.package.bsvars), and they constitute an integrated toolset. +Implements state-of-the-art algorithms for the Bayesian analysis of Structural Vector Autoregressions identified by sign, zero, and narrative restrictions. The core model is based on a flexible Vector Autoregression with estimated hyper-parameters of the Minnesota prior as in [Giannone, Lenza, Primiceri (2015)](http://doi.org/10.1162/REST_a_00483). The sign restrictions are implemented employing the methods proposed by [Rubio-RamĂ­rez, Waggoner & Zha (2010)](http://doi.org/10.1111/j.1467-937X.2009.00578.x), while identification through sign and zero restrictions follows the approach developed by [Arias, Rubio-RamĂ­rez, & Waggoner (2018)](http://doi.org/10.3982/ECTA14468). Furthermore, our tool provides algorithms for identification via sign and narrative restrictions, in line with the methods introduced by [AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018)](http://doi.org/10.1257/aer.20161852). Users can also estimate a model with sign, zero, and narrative restrictions imposed at once. The package facilitates predictive and structural analyses using impulse responses, forecast error variance and historical decompositions, forecasting and conditional forecasting, as well as analyses of structural shocks and fitted values. All this is complemented by colourful plots, user-friendly summary functions, and comprehensive documentation. The **bsvarSIGNs** package is aligned regarding objects, workflows, and code structure with the **R** package **bsvars** by [WoĆșniak (2024)](http://doi.org/10.32614/CRAN.package.bsvars), and they constitute an integrated toolset. +## Features +#### Structural Vector Autoregressions -## 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)](https://cran.r-project.org/package=Rcpp/vignettes/Rcpp-FAQ.pdf). In short, for **Windows:** install [RTools](https://CRAN.R-project.org/bin/windows/Rtools/), for **macOS:** install [Xcode Command Line Tools](https://www.freecodecamp.org/news/install-xcode-command-line-tools/), and for **Linux:** install the standard developement packages. - -#### Once that's done: - -Just open your **R** and type: +- All the models in the **bsvarSIGNs** package consist of the Vector Autoregressive equation, with autoregressive parameters `A` and error terms `E`, and the structural equation with a structural matrix `B` and shocks `U` ``` -install.packages("bsvarSIGNs") + Y = AX + E (VAR equation) + BE = U (structural equation) ``` -The developer's version of the package with the newest features can be installed by typing: +- All the models feature a hierarchical Minnesota prior following the specification proposed by Giannone, Lenza, Primiceri (2015) +- The identification of the SVAR model is achieved by imposing: + - sign restrictions on the structural matrix $\mathbf{B}$, + - sign and zero restrictions on the zero-horizon impulse responses $\mathbf{\Theta}_0 = \mathbf{B}^{-1}$, + - sign restrictions on the impulse responses at other horizons $\mathbf{\Theta}_i$ for $i = 1, 2, \ldots$, + - sign restrictions on selected structural shocks $\mathbf{u}_t$, + - two types of sign restrictions on the historical decompositions. + +#### Simple workflows + +- Specify the models using `specify_bsvarSIGN$new()` function +- 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 using functions `compute_fitted_values()` and `compute_conditional_sd()` respectively +- Use `plot()` and `summary()` methods to gain the insights into the core of the empirical problem. + +#### Fast and efficient computations + +- Blazingly fast computations are 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: ``` -devtools::install_github("bsvars/bsvarSIGNs") +**************************************************| + bsvarSIGNs: Bayesian Structural VAR with sign, | + zero and narrative restrictions | +**************************************************| + Progress of simulation for 1000 independent draws + Press Esc to interrupt the computations +**************************************************| +0% 10 20 30 40 50 60 70 80 90 100% +[----|----|----|----|----|----|----|----|----|----| +*********************************** ``` -## Development +#### The hexagonal logo -The package is under intensive development. Your help is most welcome! Please, have a look at the [roadmap](https://github.com/bsvars/bsvarSIGNs/milestones) and [report a bug](https://github.com/bsvars/bsvarSIGNs/issues). Thank you! +This beautiful logo can be reproduced in R using [this file](https://github.com/donotdespair/naklejki/blob/master/bsvarSIGNs/bsvarSIGNs.R). + +

+bsvars website +

-## Example -A replication of [Arias, Rubio-RamĂ­rez, & Waggoner (2018)](http://doi.org/10.3982/ECTA14468). +## Examples -```r +Replication of the results by [Arias, Rubio-RamĂ­rez, & Waggoner (2018)](http://doi.org/10.3982/ECTA14468). + +```{r, eval=FALSE, echo=TRUE} +# investigate the effects of the optimism shock data(optimism) -# optimism shock -# no effect on productivity + positive effect on stock prices +# specify identifying restrictions: +# + no effect on productivity (zero restriction) +# + positive effect on stock prices (positive sign restriction) sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +# specify the model specification = specify_bsvarSIGN$new(optimism * 100, p = 4, sign_irf = sign_irf) +# estimate the model posterior = estimate(specification, S = 100) + +# compute and plot impulse responses irf = compute_impulse_responses(posterior, horizon = 40) plot(irf, probability = 0.68) ``` -A replication of [AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018)](http://doi.org/10.1257/aer.20161852). - +Replication of the results by [AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018)](http://doi.org/10.1257/aer.20161852). -```r +```{r, eval=FALSE, echo=TRUE} +# investigate the effects of the contractionary monetary policy shock data(monetary) -# contractionary monetary policy shock +# specify identifying restrictions: +# + sign restrictions on the impulse responses at horizons from 0 to 4 sign_irf = matrix(NA, 6, 6) sign_irf[, 1] = c(NA, -1, -1, NA, -1, 1) sign_irf = array(sign_irf, dim = c(6, 6, 5)) -# the shock is positive in October 1979 +# + narrative sign restriction: the shock is positive in October 1979 sign_narrative = t(c(1, 1, NA, 1, 166, 0)) +# specify the model specification = specify_bsvarSIGN$new(monetary * 100, p = 12, sign_irf = sign_irf, sign_narrative = sign_narrative) +# estimate the model posterior = estimate(specification, S = 100) + +# compute and plot impulse responses irf = compute_impulse_responses(posterior, horizon = 60) plot(irf, probability = 0.68) ``` + +## 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)](https://cran.r-project.org/package=Rcpp/vignettes/Rcpp-FAQ.pdf). In short, for **Windows:** install [RTools](https://CRAN.R-project.org/bin/windows/Rtools/), for **macOS:** install [Xcode Command Line Tools](https://www.freecodecamp.org/news/install-xcode-command-line-tools/), and for **Linux:** install the standard development packages. + +#### Once that's done: + +Just open your **R** and type: +``` +install.packages("bsvarSIGNs") +``` +The developer's version of the package with the newest features can be installed by typing: +``` +devtools::install_github("bsvars/bsvarSIGNs") +``` + +## Development + +The package is under intensive development. Your help is most welcome! Please, have a look at the [roadmap](https://github.com/bsvars/bsvarSIGNs/milestones) and [report a bug](https://github.com/bsvars/bsvarSIGNs/issues). Thank you! + +## About the authors + +**Xiaolei** is a PhD candidate at the University of Melbourne. He is interested in Bayesian econometrics and time series analysis and is the author and maintainer of the **bsvarSIGNs** package. + + + + + +**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**. + + + + + + + + + + diff --git a/README.md b/README.md index 75ed3f2..22e1553 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ Autoregressions Identified by Sign, Zero, and Narrative Restrictions Implements state-of-the-art algorithms for the Bayesian analysis of Structural Vector Autoregressions identified by sign, zero, and -narrative restrictions. The core model is based on the flexible Vector -Autoregression with the estimated hyper-parameters of the Minnesota -prior as in [Giannone, Lenza, Primiceri +narrative restrictions. The core model is based on a flexible Vector +Autoregression with estimated hyper-parameters of the Minnesota prior as +in [Giannone, Lenza, Primiceri (2015)](http://doi.org/10.1162/REST_a_00483). The sign restrictions are -implemented employing the methods outlined by [Rubio-RamĂ­rez, Waggoner & +implemented employing the methods proposed by [Rubio-RamĂ­rez, Waggoner & Zha (2010)](http://doi.org/10.1111/j.1467-937X.2009.00578.x), while identification through sign and zero restrictions follows the approach developed by [Arias, Rubio-RamĂ­rez, & Waggoner @@ -32,83 +32,210 @@ decompositions, forecasting and conditional forecasting, as well as analyses of structural shocks and fitted values. All this is complemented by colourful plots, user-friendly summary functions, and comprehensive documentation. The **bsvarSIGNs** package is aligned -regarding code structure, objects, and workflows with the **R** package +regarding objects, workflows, and code structure with the **R** package **bsvars** by [WoĆșniak (2024)](http://doi.org/10.32614/CRAN.package.bsvars), and they constitute an integrated toolset. -## 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)](https://cran.r-project.org/package=Rcpp/vignettes/Rcpp-FAQ.pdf). -In short, for **Windows:** install -[RTools](https://CRAN.R-project.org/bin/windows/Rtools/), for **macOS:** -install [Xcode Command Line -Tools](https://www.freecodecamp.org/news/install-xcode-command-line-tools/), -and for **Linux:** install the standard developement packages. - -#### Once that’s done: - -Just open your **R** and type: - - install.packages("bsvarSIGNs") - -The developer’s version of the package with the newest features can be -installed by typing: - - devtools::install_github("bsvars/bsvarSIGNs") - -## Development - -The package is under intensive development. Your help is most welcome! -Please, have a look at the -[roadmap](https://github.com/bsvars/bsvarSIGNs/milestones) and [report a -bug](https://github.com/bsvars/bsvarSIGNs/issues). Thank you! - -## Example - -A replication of [Arias, Rubio-RamĂ­rez, & Waggoner +## Features + +#### Structural Vector Autoregressions + +- All the models in the **bsvarSIGNs** package consist of the Vector + Autoregressive equation, with autoregressive parameters `A` and error + terms `E`, and the structural equation with a structural matrix `B` + and shocks `U` + + + + Y = AX + E (VAR equation) + BE = U (structural equation) + +- All the models feature a hierarchical Minnesota prior following the + specification proposed by Giannone, Lenza, Primiceri (2015) +- The identification of the SVAR model is achieved by imposing: + - sign restrictions on the structural matrix $\mathbf{B}$, + - sign and zero restrictions on the zero-horizon impulse responses + $\mathbf{\Theta}_0 = \mathbf{B}^{-1}$, + - sign restrictions on the impulse responses at other horizons + $\mathbf{\Theta}_i$ for $i = 1, 2, \ldots$, + - sign restrictions on selected structural shocks $\mathbf{u}_t$, + - two types of sign restrictions on the historical decompositions. + +#### Simple workflows + +- Specify the models using `specify_bsvarSIGN$new()` function +- 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 using functions + `compute_fitted_values()` and `compute_conditional_sd()` respectively +- Use `plot()` and `summary()` methods to gain the insights into the + core of the empirical problem. + +#### Fast and efficient computations + +- Blazingly fast computations are 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: + + + + **************************************************| + bsvarSIGNs: Bayesian Structural VAR with sign, | + zero and narrative restrictions | + **************************************************| + Progress of simulation for 1000 independent draws + 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](https://github.com/donotdespair/naklejki/blob/master/bsvarSIGNs/bsvarSIGNs.R). + +

+

+bsvars website +

+

+ +## Examples + +Replication of the results by [Arias, Rubio-RamĂ­rez, & Waggoner (2018)](http://doi.org/10.3982/ECTA14468). ``` r +# investigate the effects of the optimism shock data(optimism) -# optimism shock -# no effect on productivity + positive effect on stock prices +# specify identifying restrictions: +# + no effect on productivity (zero restriction) +# + positive effect on stock prices (positive sign restriction) sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +# specify the model specification = specify_bsvarSIGN$new(optimism * 100, p = 4, sign_irf = sign_irf) +# estimate the model posterior = estimate(specification, S = 100) + +# compute and plot impulse responses irf = compute_impulse_responses(posterior, horizon = 40) plot(irf, probability = 0.68) ``` -A replication of [AntolĂ­n-DĂ­az and Rubio-RamĂ­rez +Replication of the results by [AntolĂ­n-DĂ­az and Rubio-RamĂ­rez (2018)](http://doi.org/10.1257/aer.20161852). ``` r +# investigate the effects of the contractionary monetary policy shock data(monetary) -# contractionary monetary policy shock +# specify identifying restrictions: +# + sign restrictions on the impulse responses at horizons from 0 to 4 sign_irf = matrix(NA, 6, 6) sign_irf[, 1] = c(NA, -1, -1, NA, -1, 1) sign_irf = array(sign_irf, dim = c(6, 6, 5)) -# the shock is positive in October 1979 +# + narrative sign restriction: the shock is positive in October 1979 sign_narrative = t(c(1, 1, NA, 1, 166, 0)) +# specify the model specification = specify_bsvarSIGN$new(monetary * 100, p = 12, sign_irf = sign_irf, sign_narrative = sign_narrative) +# estimate the model posterior = estimate(specification, S = 100) + +# compute and plot impulse responses irf = compute_impulse_responses(posterior, horizon = 60) plot(irf, probability = 0.68) ``` + +## 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)](https://cran.r-project.org/package=Rcpp/vignettes/Rcpp-FAQ.pdf). +In short, for **Windows:** install +[RTools](https://CRAN.R-project.org/bin/windows/Rtools/), for **macOS:** +install [Xcode Command Line +Tools](https://www.freecodecamp.org/news/install-xcode-command-line-tools/), +and for **Linux:** install the standard development packages. + +#### Once that’s done: + +Just open your **R** and type: + + install.packages("bsvarSIGNs") + +The developer’s version of the package with the newest features can be +installed by typing: + + devtools::install_github("bsvars/bsvarSIGNs") + +## Development + +The package is under intensive development. Your help is most welcome! +Please, have a look at the +[roadmap](https://github.com/bsvars/bsvarSIGNs/milestones) and [report a +bug](https://github.com/bsvars/bsvarSIGNs/issues). Thank you! + +## About the authors + +**Xiaolei** is a PhD candidate at the University of Melbourne. He is +interested in Bayesian econometrics and time series analysis and is the +author and maintainer of the **bsvarSIGNs** package. + + + + + + + + + +**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**. + + + + + + + + + + + + + + + + + + + + diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..12aaf62 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,78 @@ +url: https://bsvars.github.io/bsvarSIGNs/ +template: + bootstrap: 5 +development: + mode: auto +navbar: + structure: + right: + - github + - twitter + - instagram + - mastodon + - bluesky + - email + components: + github: + icon: github + href: https://github.com/bsvars + aria-label: github + twitter: + icon: twitter + href: https://x.com/bsvars + aria-label: twitter + instagram: + icon: instagram + href: https://www.instagram.com/bsvarsoninsta/ + aria-label: instagram + mastodon: + icon: bi-mastodon + href: https://fosstodon.org/@bsvars + aria-label: mastodon + bluesky: + icon: cloud + href: https://bsky.app/profile/bsvars.bsky.social + aria-label: bluesky + email: + icon: envelope + href: mailto:bsvars@pm.me +reference: +- title: 'bsvarSIGNs: Bayesian Estimation of Structural Vector Autoregressions Identified + by Sign, Zero, and Narrative Restrictions' + desc: Browse package information +- contents: + - bsvarSIGNs-package + - bsvarSIGNs +- title: Data + desc: Upload sample data set +- contents: + - optimism + - monetary +- title: Model specification + desc: Choose a model to work with +- contents: matches("specify_") +- title: More detailed model specification + desc: Adjust or inspect the specified model +- contents: + - matches("specify_data") + - matches("specify_iden") + - matches("specify_prior") + - matches("specify_start") +- title: Estimation + desc: Run Bayesian estimation of your model and inspect the outputs +- contents: + - matches("estimate") + - matches("specify_posterior") +- title: Posterior summaries + desc: Analyse the posterior summaries of the posterior estimation outcomes +- contents: matches("summary") +- title: Forecasting + desc: Predict future values of your variables +- contents: matches("forecast") +- title: Structural analyses + desc: Compute interpretable outcomes +- contents: matches("compute") +- title: Plot your results + desc: Prepare beautiful and informative plots for your analyses +- contents: matches("plot") + diff --git a/man/bsvarSIGNs-package.Rd b/man/bsvarSIGNs-package.Rd index 131bbff..9cb6d04 100644 --- a/man/bsvarSIGNs-package.Rd +++ b/man/bsvarSIGNs-package.Rd @@ -8,10 +8,10 @@ by Sign, Zero, and Narrative Restrictions} \description{ Implements state-of-the-art algorithms for the Bayesian analysis of Structural Vector Autoregressions identified by sign, zero, and narrative -restrictions. The core model is based on the flexible Vector Autoregression -with the estimated hyper-parameters of the Minnesota prior as in +restrictions. The core model is based on a flexible Vector Autoregression with +estimated hyper-parameters of the Minnesota prior as in Giannone, Lenza, Primiceri (2015) . The sign -restrictions are implemented employing the methods outlined by +restrictions are implemented employing the methods proposed by Rubio-RamĂ­rez, Waggoner & Zha (2010) , while identification through sign and zero restrictions follows the approach developed by Arias, Rubio-RamĂ­rez, & Waggoner (2018) . @@ -24,8 +24,8 @@ impulse responses, forecast error variance and historical decompositions, forecasting and conditional forecasting, as well as analyses of structural shocks and fitted values. All this is complemented by colourful plots, user-friendly summary functions, and comprehensive documentation. The -`bsvarSIGNs` package is aligned regarding code structure, objects, and -workflows with the R package 'bsvars' by +`bsvarSIGNs` package is aligned regarding objects, workflows, and code +structure with the R package 'bsvars' by WoĆșniak (2024) , and they constitute an integrated toolset. } @@ -88,19 +88,26 @@ This package is currently in active development. Your comments, suggestions and requests are warmly welcome! } \examples{ -# specify sign and zero restrictions on the impulse response +# investigate the effects of the optimism shock +data(optimism) + +# specify identifying restrictions: +# + no effect on productivity (zero restriction) +# + positive effect on stock prices (positive sign restriction) sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) # specify the model -spec = specify_bsvarSIGN$new(optimism * 100, +specification = specify_bsvarSIGN$new(optimism * 100, p = 4, sign_irf = sign_irf) + +# estimate the model +posterior = estimate(specification, S = 100) -# estimate the hyper-parameters -spec$prior$estimate_hyper() +# compute and plot impulse responses +irf = compute_impulse_responses(posterior, horizon = 40) +plot(irf, probability = 0.68) -# estimate the model -post = estimate(spec, S = 1000) } \references{ AntolĂ­n-DĂ­az & Rubio-RamĂ­rez (2018) Narrative Sign Restrictions for SVARs, American Economic Review, 108(10), 2802-29, .