Samples from the joint predictive density of all of the dependent
variables for models from packages bsvars, bsvarSIGNs or
bvarPANELs at forecast horizons from 1 to horizon
specified as
an argument of the function.
Usage
# S3 method for class 'PosteriorBSVART'
forecast(
posterior,
horizon = 1,
exogenous_forecast = NULL,
conditional_forecast = NULL
)
Arguments
- posterior
posterior estimation outcome - an object of class
PosteriorBSVART
obtained by running theestimate
function.- horizon
a positive integer, specifying the forecasting horizon.
- exogenous_forecast
a matrix of dimension
horizon x d
containing forecasted values of the exogenous variables.- conditional_forecast
a
horizon x N
matrix with forecasted values for selected variables. It should only containnumeric
orNA
values. The entries withNA
values correspond to the values that are forecasted conditionally on the realisations provided asnumeric
values.
Value
A list of class Forecasts
containing the
draws from the predictive density and data. The output list includes element:
- forecasts
an
NxTxS
array with the draws from predictive density- Y
an \(NxT\) matrix with the data on dependent variables
Author
Tomasz Woźniak wozniak.tom@pm.me
Examples
# upload data
data(us_fiscal_lsuw)
# specify the model and set seed
set.seed(123)
specification = specify_bsvar_t$new(us_fiscal_lsuw, p = 1)
#> The identification is set to the default option of lower-triangular structural matrix.
# run the burn-in
burn_in = estimate(specification, 5)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 5 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
# estimate the model
posterior = estimate(burn_in, 10)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 10 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
# sample from predictive density 1 year ahead
predictive = forecast(posterior, 4)
# workflow with the pipe |>
############################################################
set.seed(123)
us_fiscal_lsuw |>
specify_bsvar_t$new(p = 1) |>
estimate(S = 5) |>
estimate(S = 10) |>
forecast(horizon = 4) -> predictive
#> The identification is set to the default option of lower-triangular structural matrix.
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 5 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 10 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
# conditional forecasting using a model with exogenous variables
############################################################
data(us_fiscal_ex_forecasts) # upload exogenous variables future values
data(us_fiscal_cond_forecasts) # upload a matrix with projected ttr
#' set.seed(123)
specification = specify_bsvar_t$new(us_fiscal_lsuw, exogenous = us_fiscal_ex)
#> The identification is set to the default option of lower-triangular structural matrix.
burn_in = estimate(specification, 5)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 5 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
posterior = estimate(burn_in, 10)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 10 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
# forecast 2 years ahead
predictive = forecast(
posterior,
horizon = 8,
exogenous_forecast = us_fiscal_ex_forecasts,
conditional_forecast = us_fiscal_cond_forecasts
)
summary(predictive)
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Posterior summary of forecasts |
#> **************************************************|
#> $variable1
#> mean sd 5% quantile 95% quantile
#> 1 -8.914237 0 -8.914237 -8.914237
#> 2 -8.908921 0 -8.908921 -8.908921
#> 3 -8.903604 0 -8.903604 -8.903604
#> 4 -8.898288 0 -8.898288 -8.898288
#> 5 -8.892971 0 -8.892971 -8.892971
#> 6 -8.887655 0 -8.887655 -8.887655
#> 7 -8.882338 0 -8.882338 -8.882338
#> 8 -8.877022 0 -8.877022 -8.877022
#>
#> $variable2
#> mean sd 5% quantile 95% quantile
#> 1 -9.837755 0.1021440 -9.982446 -9.702030
#> 2 -9.811925 0.2141586 -10.059346 -9.493666
#> 3 -9.791147 0.2803300 -10.116954 -9.353528
#> 4 -9.747606 0.2946255 -10.171010 -9.385011
#> 5 -9.738103 0.3640586 -10.325447 -9.350938
#> 6 -9.720222 0.3460256 -10.288509 -9.364275
#> 7 -9.716970 0.3100670 -10.236397 -9.365467
#> 8 -9.782993 0.3657178 -10.464212 -9.498823
#>
#> $variable3
#> mean sd 5% quantile 95% quantile
#> 1 -7.063645 0.04726872 -7.139990 -7.002274
#> 2 -6.996275 0.09733393 -7.077062 -6.844588
#> 3 -6.984982 0.08654321 -7.057481 -6.829573
#> 4 -6.940121 0.11152654 -7.049536 -6.777686
#> 5 -6.929928 0.12604763 -7.073341 -6.759790
#> 6 -6.931170 0.12960130 -7.066684 -6.764238
#> 7 -6.969629 0.15906562 -7.172552 -6.736426
#> 8 -6.978067 0.17145520 -7.218679 -6.728235
#>
# workflow with the pipe |>
############################################################
set.seed(123)
us_fiscal_lsuw |>
specify_bsvar_t$new(exogenous = us_fiscal_ex) |>
estimate(S = 5) |>
estimate(S = 10) |>
forecast(
horizon = 8,
exogenous_forecast = us_fiscal_ex_forecasts,
conditional_forecast = us_fiscal_cond_forecasts
) |> plot()
#> The identification is set to the default option of lower-triangular structural matrix.
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 5 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|
#> **************************************************|
#> bsvars: Bayesian Structural Vector Autoregressions|
#> **************************************************|
#> Gibbs sampler for the SVAR model |
#> with t-distributed structural skocks |
#> **************************************************|
#> Progress of the MCMC simulation for 10 draws
#> Every draw is saved via MCMC thinning
#> Press Esc to interrupt the computations
#> **************************************************|