# upload data
data(optimism)
# specify the model and set seed
set.seed(123)
# + 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)
specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf)
# estimate the model
posterior = estimate(specification, 10)
# sample from predictive density 1 year ahead
predictive = forecast(posterior, 4)
# workflow with the pipe |>
############################################################
set.seed(123)
optimism |>
specify_bsvarSIGN$new(sign_irf = sign_irf) |>
estimate(S = 20) |>
forecast(horizon = 4) -> predictive
# conditional forecasting 2 quarters ahead conditioning on
# provided future values for the Gross Domestic Product
############################################################
cf = matrix(NA , 2, 5)
# # conditional forecasts equal to the last consumption observation
cf[,3] = tail(optimism, 1)[3]
predictive = forecast(posterior, 2, conditional_forecast = cf)
# workflow with the pipe |>
############################################################
set.seed(123)
optimism |>
specify_bsvarSIGN$new(sign_irf = sign_irf) |>
estimate(S = 10) |>
forecast(horizon = 2, conditional_forecast = cf) -> predictive
Run the code above in your browser using DataLab