forecast.PosteriorBSVARSV: Forecasting using Bayesian Structural Vector Autoregression

View source: R/forecast.R

forecast.PosteriorBSVARSVR Documentation

Forecasting using Bayesian Structural Vector Autoregression

Description

Samples from the joint predictive density of all of the dependent variables for models at forecast horizons from 1 to horizon specified as an argument of the function.

Usage

## S3 method for class 'PosteriorBSVARSV'
forecast(
  object,
  horizon = 1,
  exogenous_forecast = NULL,
  conditional_forecast = NULL,
  ...
)

Arguments

object

posterior estimation outcome - an object of class PosteriorBSVARSV obtained by running the estimate 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 contain numeric or NA values. The entries with NA values correspond to the values that are forecasted conditionally on the realisations provided as numeric values.

...

not used

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 NxTxS array with the draws from predictive density

Y

an NxT matrix with the data on dependent variables

forecast_mean

an NxTxS array with the mean of the predictive density

forecast_covariance

an NxTxS array with the covariance of the predictive density

Author(s)

Tomasz Woźniak wozniak.tom@pm.me

Examples

specification  = specify_bsvar_sv$new(us_fiscal_lsuw)
burn_in        = estimate(specification, 5)
posterior      = estimate(burn_in, 5)
predictive     = forecast(posterior, 2)

# workflow with the pipe |>
############################################################
us_fiscal_lsuw |>
  specify_bsvar_sv$new() |>
  estimate(S = 5) |>
  estimate(S = 5) |>  
  forecast(horizon = 2) -> predictive
  
# conditional forecasting using a model with exogenous variables
############################################################
specification  = specify_bsvar_sv$new(us_fiscal_lsuw, exogenous = us_fiscal_ex)
burn_in        = estimate(specification, 5)
posterior      = estimate(burn_in, 5)

# forecast 2 years ahead
predictive     = forecast(
                    posterior, 
                    horizon = 8,
                    exogenous_forecast = us_fiscal_ex_forecasts,
                    conditional_forecast = us_fiscal_cond_forecasts
                  )
summary(predictive)

# workflow with the pipe |>
############################################################
us_fiscal_lsuw |>
  specify_bsvar_sv$new(exogenous = us_fiscal_ex) |>
  estimate(S = 5) |> 
  estimate(S = 5) |> 
  forecast(
    horizon = 8,
    exogenous_forecast = us_fiscal_ex_forecasts,
    conditional_forecast = us_fiscal_cond_forecasts
  ) |> plot()


bsvars documentation built on Aug. 22, 2026, 5:09 p.m.