I am trying to generate impulse responses for structural var using the BSVARS package for the already given model in the package by the following code available in GitHub. but I am getting an error. how do I rectify this error?
library(bsvars)
data(us_fiscal_lsuw)
specification = specify_bsvar_sv$new(us_fiscal_lsuw, p = 4)
set.seed(123)
burn_in = estimate_bsvar_sv(10, specification)
posterior = estimate_bsvar_sv(50, burn_in$get_last_draw())
# normalise the posterior
BB = posterior$last_draw$starting_values$B
B_hat = diag(sign(diag(BB))) %*% BB
bsvars::normalise_posterior(posterior, B_hat)
compute_impulse_responses <- function(posterior, horizon) {
stopifnot("Argument posterior must contain estimation output from the estimate function." = any(class(posterior)[1] == c("PosteriorBSVAR", "PosteriorBSVARMSH", "PosteriorBSVARMIX", "PosteriorBSVARSV")))
stopifnot("The posterior output must be normalised for the impulse responses to be interpretable." = posterior$is_normalised())
stopifnot("Argument horizon must be a positive integer number." = horizon > 0 & horizon %% 1 == 0)
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
N = dim(posterior_A)[1]
p = (dim(posterior_A)[2] - 1) / N
S = dim(posterior_A)[3]
qqq = .Call(`_bsvars_bsvars_ir`, posterior_B, posterior_A, horizon, p)
irfs = array(NA, c(N, N, horizon + 1, S))
for (s in 1:S) irfs[,,,s] = qqq[s][[1]]
class(irfs) = "PosteriorIR"
return(irfs)
}
irf = compute_impulse_responses(posterior, horizon = 8)
Error in compute_impulse_responses(posterior, horizon = 8) :
object '_bsvars_bsvars_ir' not found
at first i had problem with first if not argument but i rectified it. but i am encountering this error, which i am not sure what to do?
Error in compute_impulse_responses(posterior, horizon = 8) : object '_bsvars_bsvars_ir' not found