bsvars / bsvarSIGNs

Bayesian SVARs with Sign, Zero, and Narrative Restrictions
http://bsvars.org/bsvarSIGNs/
Other
10 stars 2 forks source link

Difficulty drawing valid Q matrix #5

Closed adamwang15 closed 9 months ago

adamwang15 commented 10 months ago

We have a minimum working example of sign restrictions on impulse response functions, but it is very difficult to have valid draws of Q, which is strange since only horizon 0 is considered.

set.seed(123)
data(oil)

sign_irf <-
  array(matrix(c(-1, -1, 1, 1, 1, 1, 1, -1, 1), nrow = 3), dim = c(3, 3, 1))
specification <-
  specify_bsvarSIGN$new(oil, p = 12, sign_irf = sign_irf)

burn_in <- estimate.BSVARSIGN(specification, 101, thin = 100)
posterior <- estimate.PosteriorBSVARSIGN(burn_in, 10, thin = 1)

# test
posterior$posterior$B # only one draw is valid
posterior$posterior$B[, , 1] |> solve()

#             [,1]      [,2]       [,3]
# [1,] -0.99836620 0.8753184  0.4946759
# [2,] -0.05624569 3.6964931 -6.0691198
# [3,]  4.72269479 4.7975231  1.4027944
adamwang15 commented 9 months ago

Splitting a long loop into several functions and avoiding break/continue solved the problem. Lesson learned: good coding practice is important!

donotdespair commented 9 months ago

Oh! That's fantastic! Thanks for the update!