
Forecasting using Structural Vector Autoregression
Source:R/forecast.R
      forecast.PosteriorBSVARHMSH.RdSamples 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 'PosteriorBSVARHMSH'
forecast(
  posterior,
  horizon = 1,
  exogenous_forecast = NULL,
  conditional_forecast = NULL
)Arguments
- posterior
- posterior estimation outcome - an object of class - PosteriorBSVARHMSHobtained by running the- estimatefunction.
- 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 contain- numericor- NAvalues. The entries with- NAvalues correspond to the values that are forecasted conditionally on the realisations provided as- numericvalues.
Value
A list of class Forecasts containing the
draws from the predictive density and for heteroskedastic models the draws
from the predictive density of structural shocks conditional standard
deviations and data. The output elements include:
- forecasts
- an - NxTxSarray with the draws from predictive density
- Y
- an \(NxT\) matrix with the data on dependent variables 
- forecast_mean
- an - NxTxSarray with the mean of the predictive density
- forecast_covariance
- an - NxTxSarray with the covariance of the predictive density
Author
Tomasz Woźniak wozniak.tom@pm.me
Examples
# specify the model and set seed
specification  = specify_bsvar_hmsh$new(us_fiscal_lsuw)
#> 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-stationaryHMSH model
#> **************************************************|
#>  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-stationaryHMSH model
#> **************************************************|
#>  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 |>
############################################################
us_fiscal_lsuw |>
  specify_bsvar_hmsh$new(M = 2) |>
  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-stationaryHMSH model
#> **************************************************|
#>  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-stationaryHMSH model
#> **************************************************|
#>  Progress of the MCMC simulation for 10 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
  
# forecasting using a model with exogenous variables
############################################################
specification  = specify_bsvar_hmsh$new(us_fiscal_lsuw, M = 2, 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-stationaryHMSH model
#> **************************************************|
#>  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-stationaryHMSH model
#> **************************************************|
#>  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
                  )
summary(predictive)
#>  **************************************************|
#>  bsvars: Bayesian Structural Vector Autoregressions|
#>  **************************************************|
#>    Posterior summary of forecasts                  |
#>  **************************************************|
#> $variable1
#>        mean        sd 5% quantile 95% quantile
#> 1 -7.982262 1.0394494   -9.272714    -6.430139
#> 2 -7.477116 0.9817940   -8.903766    -6.122182
#> 3 -7.230960 1.1393994   -9.082372    -5.991413
#> 4 -7.137194 1.3680877   -9.437774    -5.760991
#> 5 -6.611118 0.6572325   -7.359778    -5.669542
#> 6 -6.137338 0.8468382   -7.454153    -5.163772
#> 7 -6.376454 1.0650773   -7.982984    -5.255412
#> 8 -6.371971 1.3232345   -8.170208    -4.585977
#> 
#> $variable2
#>         mean       sd 5% quantile 95% quantile
#> 1 -5.9699776 4.245784  -11.218018    0.4069556
#> 2 -3.8384101 4.079803   -9.651871    1.9176828
#> 3 -2.6257738 4.526450   -9.975411    2.2886644
#> 4 -1.9873390 5.401140  -10.965052    3.6747600
#> 5  0.3963471 2.424918   -2.109497    4.4996655
#> 6  2.6203472 2.902032   -2.107751    5.7435269
#> 7  2.0987672 4.192303   -3.575657    7.1473645
#> 8  2.5624028 5.326885   -2.763418   11.1034519
#> 
#> $variable3
#>        mean        sd 5% quantile 95% quantile
#> 1 -6.398940 0.7127870   -7.291759    -5.327026
#> 2 -6.063879 0.6878537   -7.038769    -5.072440
#> 3 -5.886106 0.7481419   -7.091283    -5.028855
#> 4 -5.817796 0.9193236   -7.251906    -4.793425
#> 5 -5.453251 0.5165030   -6.070065    -4.640510
#> 6 -5.116031 0.6075557   -6.067199    -4.445037
#> 7 -5.256471 0.8797898   -6.533044    -4.261579
#> 8 -5.221105 1.0237182   -6.304860    -3.758465
#> 
# workflow with the pipe |>
############################################################
us_fiscal_lsuw |>
  specify_bsvar_hmsh$new(M = 2, exogenous = us_fiscal_ex) |>
  estimate(S = 5) |> 
  estimate(S = 10) |> 
  forecast(
    horizon = 8,
    exogenous_forecast = us_fiscal_ex_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-stationaryHMSH model
#> **************************************************|
#>  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-stationaryHMSH model
#> **************************************************|
#>  Progress of the MCMC simulation for 10 draws
#>     Every draw is saved via MCMC thinning
#>  Press Esc to interrupt the computations
#> **************************************************|
