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
PosteriorBSVARTobtained by running theestimatefunction.- horizon
a positive integer, specifying the forecasting horizon.
- exogenous_forecast
a matrix of dimension
horizon x dcontaining forecasted values of the exogenous variables.- conditional_forecast
a
horizon x Nmatrix with forecasted values for selected variables. It should only containnumericorNAvalues. The entries withNAvalues correspond to the values that are forecasted conditionally on the realisations provided asnumericvalues.
Value
A list of class Forecasts containing the
draws from the predictive density and data. The output list includes element:
- forecasts
an
NxTxSarray 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 -15.579180 14.40466 -39.78628 -9.2384785
#> 2 -14.290312 14.68680 -38.56107 -3.3988204
#> 3 -14.411195 14.65279 -37.81451 -0.5859383
#> 4 -14.429582 14.06395 -36.91634 -0.7314235
#> 5 -12.319945 14.60087 -35.62362 3.2207381
#> 6 -10.421125 15.29076 -34.83443 5.0889173
#> 7 -9.806943 14.94591 -33.21529 5.5777954
#> 8 -11.079387 13.49248 -33.04700 2.9185434
#>
#> $variable3
#> mean sd 5% quantile 95% quantile
#> 1 -7.038118 0.3890945 -7.501464 -6.505458
#> 2 -7.008949 0.5767666 -7.826390 -6.207933
#> 3 -7.011705 0.6301401 -7.747154 -6.014813
#> 4 -6.931871 0.7006148 -7.572090 -5.786567
#> 5 -6.831914 0.7459835 -7.506673 -5.610281
#> 6 -6.691680 0.8754448 -7.470477 -5.329140
#> 7 -6.676920 0.9332327 -7.506898 -5.204895
#> 8 -6.727653 1.1418083 -7.934651 -4.958699
#>
# 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
#> **************************************************|
