library(bsvars)
data(us_fiscal_lsuw)
\[ \]
\[ \]
\[ \]
library(bsvars)
data(us_fiscal_lsuw)
us_fiscal_lsuw |>
specify_bsvar$new() |>
estimate(S = 1000) |>
estimate(S = 10000) -> post
post |> compute_impulse_responses(horizon = 12) |> plot()
post |> compute_variance_decompositions(horizon = 12) |> plot()
post |> compute_historical_decompositions() |> plot()
post |> compute_structural_shocks() |> plot()
post |> compute_conditional_sd() |> plot()
post |> forecast(horizon = 12) |> plot()
post |> verify_identification() |> summary()
library(bsvarSIGNs)
data(optimism)
optimism |>
specify_bsvarSIGN$new() |>
estimate(S = 10000) -> post
post |> compute_impulse_responses(horizon = 12) |> plot()
post |> compute_variance_decompositions(horizon = 12) |> plot()
post |> compute_historical_decompositions() |> plot()
post |> compute_structural_shocks() |> plot()
post |> compute_conditional_sd() |> plot()
post |> forecast(horizon = 12) |> plot()
\[\begin{align} \text{reduced form:}&&\mathbf{y}_t &= \mathbf{A}\mathbf{x}_t + \boldsymbol{\varepsilon}_t \\ \text{structural form:}&&\mathbf{B}_0\boldsymbol{\varepsilon}_t &= \mathbf{u}_t \\ \text{structural shocks:}&&\mathbf{u}_t\mid\mathbf{x}_t &\sim N\left( \mathbf{0}_N, \text{diag}\left(\boldsymbol{\sigma}_t^2\right) \right) \end{align}\]
\[\begin{align} &\\ \text{reduced form:}&&\mathbf{y}_t &= \mathbf{A}\mathbf{x}_t + \boldsymbol{\varepsilon}_t \\ \text{error term:}&&\boldsymbol{\varepsilon}_t\mid\mathbf{x}_t &\sim N\left( \mathbf{0}_N, \boldsymbol{\Sigma} \right)\\ \text{rotation:}&&\mathbf{Q} &\sim Haar \\ \text{structural form:}&&\left(\mathbf{A}, \boldsymbol{\Sigma}, \mathbf{Q}\right) &\rightarrow\left(\mathbf{A}, \mathbf{B}_0\right) \end{align}\]
\[\begin{align} &\\ \text{conditional variance:}&&\sigma_{n.t}^2 &= \exp\left\{\omega_n h_{n.t}\right\}\\ \text{log-volatility:}&&h_{n.t} &= \rho_n h_{n.t-1} + v_{n.t}\\ \text{volatility innovation:}&&v_{n.t}&\sim N\left(0,1\right)\\ \end{align}\]
verify_identification()
by checking \(H_0:\omega_n = 0\)\[\begin{align} &\\ \text{structural shocks:}&&\mathbf{u}_t\mid s_t \sim N\left( \mathbf{0}_N, \text{diag}\left(\boldsymbol{\sigma}_{s_t}^2\right) \right)\\ \text{prior:}&& M^{-1}\left(\boldsymbol{\sigma}_{1}^2, \dots, \boldsymbol{\sigma}_{M}^2\right) \sim Dirichlet(\underline{a}\boldsymbol\imath')\\ \text{latent process:}&& s_t\sim \text{Markov or independent} \end{align}\]
verify_identification()
by checking \(H_0:\boldsymbol{\sigma}_{1}^2, \dots, \boldsymbol{\sigma}_{M}^2 = 1\)\[\begin{align} &&&\\ \text{structural shocks:}&&\mathbf{u}_t\mid\mathbf{x}_t &\sim t\left( \mathbf{0}_N, \mathbf{I}_N, \nu \right) \end{align}\]
verify_identification()
by checking \(H_0:\nu \rightarrow\infty\)\[ SDDR = \frac{\Pr[H_0 | data]}{\Pr[H_1 | data]}= \frac{p(H_0 | data)}{p(H_0 )} \]
verify_identification()
verify_autoregression()
\[\begin{align} y_t = \begin{bmatrix} rgdp_t & cpi_t & CR_t & EX_t & aord_t \end{bmatrix}' \end{align}\]
\[\begin{align} x_t = \begin{bmatrix} rgdp_t^{(US)} & cpi_t^{(US)} & FFR_t \end{bmatrix}' \end{align}\]
\[\begin{align} \begin{bmatrix} B_{0.11}&0&0&0&0\\ B_{0.21}&B_{0.22}&0&0&0\\ B_{0.31}&B_{0.32}&B_{0.33}&0&0\\ B_{0.41}&B_{0.42}&B_{0.43}&B_{0.44}&0\\ B_{0.51}&B_{0.52}&B_{0.53}&B_{0.54}&B_{0.55} \end{bmatrix} \begin{bmatrix}rgdp_t \\ cpi_t \\ CR_t \\ EX_t\\ aord_t \end{bmatrix} &= \dots + \begin{bmatrix} u_t^{ad} \\ u_t^{as} \\ u_t^{mps} \\ u_t^{ex} \\ u_t^{aord} \end{bmatrix} \end{align}\]
library(bsvars)
load("soe.rda")
soe = as.matrix(soe)
TT = nrow(soe)
lag_order = 8
lag_exogenous = 4
T = TT - max(lag_order, lag_exogenous)
exogenous = matrix(NA, TT - lag_exogenous, 0)
for (i in 0:lag_exogenous) {
exogenous = cbind(exogenous, as.matrix(soe[(lag_exogenous - i + 1):(TT - i), 6:8]))
}
set.seed(1234)
spec = specify_bsvar_sv$new(
data = tail(soe[,1:5], T),
p = lag_order,
exogenous = tail(exogenous, T)
)
burn = estimate(spec, 1e4)
post = estimate(burn, 1e4)
**************************************************|
bsvars: Bayesian Structural Vector Autoregressions|
**************************************************|
Summary of identification verification |
H0: omega_n = 0 [homoskedasticity] |
H1: omega_n != 0 [heteroskedasticity] |
**************************************************|
log(SDDR) NSE Pr[H0|data] Pr[H1|data]
shock 1 -139.2079238 56.216891 3.489529e-61 1.0000000
shock 2 -77.3369956 60.430724 2.588031e-34 1.0000000
shock 3 -20.9795368 20.576286 7.739322e-10 1.0000000
shock 4 -0.2618337 0.524091 4.349130e-01 0.5650870
shock 5 -2.5202529 1.911860 7.445051e-02 0.9255495
**************************************************|
bsvars: Bayesian Structural Vector Autoregressions|
**************************************************|
Summary of hypothesis verification |
for autoregressive parameters |
**************************************************|
log(SDDR) NSE Pr[H0|data] Pr[H1|data]
156.8253 4.668342 1 7.791643e-69
\[\begin{align} \begin{bmatrix}rgdp_t \\ cpi_t \\ CR_t \\ EX_t\\ aord_t \end{bmatrix} &= \dots + \begin{bmatrix} -&*&*&*&*\\ -&*&*&*&*\\ +&*&*&*&*\\ *&*&*&*&*\\ *&*&*&*&*\\ \end{bmatrix}\begin{bmatrix} u_t^{mps} \\ u_t^{*} \\ u_t^{*} \\ u_t^{*} \\ u_t^{*} \end{bmatrix} \end{align}\]
sign_irf0 = matrix(c(-1, -1, 1, rep(NA, 22)), 5, 5)
sign_irf = array(NA, c(5, 5, 6))
for (i in 1:6) sign_irf[,,i] = sign_irf0
set.seed(1234)
spec = specify_bsvarSIGN$new(
data = tail(soe[,1:5], T),
p = lag_order,
exogenous = tail(exogenous, T),
sign_irf = sign_irf
)
post = estimate(spec, 1e4)
sign_irf0
[,1] [,2] [,3] [,4] [,5]
[1,] -1 NA NA NA NA
[2,] -1 NA NA NA NA
[3,] 1 NA NA NA NA
[4,] NA NA NA NA NA
[5,] NA NA NA NA NA