Learn R Programming

bpvars

An R package for Forecasting with Bayesian Panel Vector Autoregressions

Provides Bayesian estimation and forecasting of dynamic panel data using Bayesian Panel Vector Autoregressions with hierarchical prior distributions. The model includes country-specific VARs that share a global prior distribution. Under this prior expected value, each country’s system follows a global VAR with country-invariant parameters. Further flexibility is provided by the hierarchical prior structure that retains the Minnesota prior interpretation for the global VAR and features estimated prior covariance matrices, shrinkage, and persistence levels. Bayesian forecasting is developed for models including exogenous variables, allowing conditional forecasts given the future trajectories of some variables and restricted forecasts assuring that rates are forecasted to stay positive and less than 100. The package implements the model specification, estimation, and forecasting routines, facilitating coherent workflows and reproducibility. Beautiful plots, informative summary functions, and extensive documentation complement all this. An extraordinary computational speed is achieved thanks to employing frontier econometric and numerical techniques and algorithms written in C++. The bpvars package is aligned regarding objects, workflows, and code structure with the R packages bsvars by Woźniak (2024) and bsvarSIGNs by Wang & Woźniak (2024), and they constitute an integrated toolset.

Features

Forecasting with Bayesian Panel Vector Autoregressions

  • The model in the bpvars package features a country-specific Vector Autoregressive equation for the country-specific:

    • dependent variables Yc,
    • lagged dependent variables Xc,
    • error terms Ec,
    • autoregressive parameters Ac, and
    • error term covariance matrix Sc.
         Yc = Xc Ac + Ec         (VAR equation)
    Ec | Xc ~ MN(0, I, Sc)       (error term normality)
  • The error terms feature a zero-mean matrix-variate normal distribution with row-specific covariance matrix Sc and column-specific covariance equal to the identity matrix of order T, denoted by I.

  • The Hierarchical Panel VAR model features a sophisticated hierarchical prior structure that grants the model flexibility, interpretability, and improved forecasting performance.

  • The country-specific parameters follow a prior distribution that, at its mean value, represents a global VAR model with a global autoregressive parameter matrix A and a global error term covariance matrix S:

       Yc = Xc A + Ec          (VAR equation)
  Ec | Xc ~ MN(0, I, S)        (error term normality)

Simple workflows

  • Specify the models using the specify_bvarPANEL$new() function
  • Estimate the models using the estimate() method
  • Predict the future using the forecast() method
  • Compute forecast error variance decompositions using function compute_variance_decompositions()
  • Use plot() and summary() methods to gain the insights into the core of the empirical problem.

Fast and efficient computations

  • Extraordinary computational speed is obtained by combining
    • the application of frontier econometric and numerical techniques, and
    • the algorithms written in cpp
  • It combines the best of two worlds: the ease of data analysis with R and fast cpp algorithms
  • The algorithms used here are very fast. But still, Bayesian estimation might take a little time. Look at our beautiful progress bar in the meantime:
**************************************************|
bpvars: Forecasting with Bayesian Hierarchical    |
            Panel Vector Autoregressions          |
**************************************************|
 Progress of the MCMC simulation for 10000 draws
    Every draw is saved via MCMC thinning
 Press Esc to interrupt the computations
**************************************************|
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
*************************************

The hexagonal logo

This beautiful logo can be reproduced in R using this file.

Resources

Start your Bayesian analysis of data

The beginnings are as easy as ABC:

library(bpvars)                                     # load the package

spec = specify_bvarPANEL$new(                           # specify the model
  ilo_dynamic_panel                                     # data
)

burn = estimate(spec, S = 10000)                        # run the burn-in
post = estimate(burn, S = 10000)                        # estimate the model

fore = forecast(                                        # forecast the model 
  post,                                                 # estimation output
  horizon = 6                                           # forecast horizon
)

plot(fore, "COL", main = "Forecasts for Colombia")
summary(fore, "COL")$variable2

post |>                                                 # estimation output
  compute_variance_decompositions(horizon = 6) |>       # compute variance decompositions
  plot(which_c = "COL")                                 # plot variance decompositions

The bpvars package supports a simplified workflow using the |> pipe:

ilo_dynamic_panel |>                                    # data
  specify_bvarPANEL$new() |>                            # specify the model
  estimate(S = 10000) |>                                # run the burn-in
  estimate(S = 10000) -> post                           # estimate the model

post |> forecast(                                       # forecast the model 
  horizon = 6                                           # forecast horizon
) |> plot("COL", main = "Forecasts for Colombia")

Now, you’re ready to analyse your model and forecasts!

Installation

The first time you install the package

You must have a cpp compiler. Follow the instructions from Section 1.3. by Eddelbuettel & François (2023). In short, for Windows: install RTools, for macOS: install Xcode Command Line Tools, and for Linux: install the standard development packages.

Once that’s done:

Just open your R and install the package by running:

instal.packages("bpvars")

To install the package from its developer’s repository just type:

devtools::install_github("bsvars/bpvars")

Development

The package is under intensive development. Your help is most welcome! Please, have a look at our issues to learn what we’re working on. Thank you!

About the author

Tomasz is a Bayesian econometrician and a Senior Lecturer at the University of Melbourne. He develops methodology for empirical macroeconomic analyses and programs in R and C++ using Rcpp.

Copy Link

Version

Install

install.packages('bpvars')

Version

1.0

License

GPL (>= 3)

Maintainer

Tomasz Woźniak

Last Published

December 11th, 2025

Functions in bpvars (1.0)

estimate.PosteriorBVARPANEL

Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression using Gibbs sampler
estimate.BVARPANEL

Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression using Gibbs sampler
estimate.PosteriorBVARGROUPPANEL

Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression with fixed or estimated country grouping
estimate.BVARGROUPPANEL

Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression with fixed or estimated country grouping
forecast.PosteriorBVARGROUPPANEL

Forecasting using Hierarchical Panel Vector Autoregressions
estimate.BVARs

Bayesian estimation of a Bayesian Hierarchical Vector Autoregressions for cubic data using Gibbs sampler
forecast.PosteriorBVARGROUPPRIORPANEL

Forecasting using Hierarchical Panel Vector Autoregressions
estimate.PosteriorBVARs

Bayesian estimation of a Bayesian Hierarchical Vector Autoregressions for cubic data using Gibbs sampler
estimate.PosteriorBVARGROUPPRIORPANEL

Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression with fixed or estimated country grouping for global priors
estimate.BVARGROUPPRIORPANEL

Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression with fixed or estimated country grouping for global priors
forecast_poos_recursively.BVARPANEL

Bayesian recursive pseudo-out-of-sample forecasting
forecast_poos_recursively.BVARs

Bayesian recursive pseudo-out-of-sample forecasting
ilo_exogenous_forecasts

Data containing future observations for 189 United Nations countries from 2025 to 2029 to be used to forecast with models with ilo_exogenous_variables
ilo_dynamic_panel_missing

A 4-variable annual system for forecasting labour market outcomes for 189 countries to 2024 containing only actual observations
forecast.PosteriorBVARPANEL

Forecasting using Hierarchical Panel Vector Autoregressions
ilo_dynamic_panel

A 4-variable annual system for forecasting labour market outcomes for 189 countries from 1991 to 2024
forecast_poos_recursively

Bayesian recursive pseudo-out-of-sample forecasting
forecast.PosteriorBVARs

Forecasting using Hierarchical Vector Autoregressions for Dynamic Panel Data
reexports

Objects exported from other packages
specify_bvarGroupPANEL

R6 Class representing the specification of the BVARGROUPPANEL model
specify_panel_data_matrices

R6 Class Representing DataMatricesBVARPANEL
specify_bvarGroupPriorPANEL

R6 Class representing the specification of the BVARGROUPPRIORPANEL model
specify_bvarPANEL

R6 Class representing the specification of the BVARPANEL model
specify_bvars

R6 Class representing the specification of the BVARs model
ilo_exogenous_variables_missing

A 3-variable annual system for of dummy observations for 2008, 2020, and 2021 to be used in the estimation of the Panel VAR model for 189 countries to 2024 containing observations for matching periods from ilo_dynamic_panel_missing
ilo_exogenous_variables

A 3-variable annual system for of dummy observations for 2008, 2020, and 2021 to be used in the estimation of the Panel VAR model for 189 countries from 1991 to 2024
forecast_poos_recursively.BVARGROUPPANEL

Bayesian recursive pseudo-out-of-sample forecasting
forecast_poos_recursively.BVARGROUPPRIORPANEL

Bayesian recursive pseudo-out-of-sample forecasting
plot.ForecastsPANEL

Plots fitted values of dependent variables
plot.PosteriorFEVDPANEL

Plots forecast error variance decompositions
specify_prior_bvars

R6 Class Representing PriorBVARs
specify_starting_values_bvarGroupPANEL

R6 Class Representing StartingValuesBVARGROUPPANEL
specify_posterior_bvarGroupPANEL

R6 Class Representing PosteriorBVARGROUPPANEL
specify_poosf_exercise

R6 Class Representing specification of the pseudo-out-of-sample forecasting exercise
specify_posterior_bvarGroupPriorPANEL

R6 Class Representing PosteriorBVARGROUPPRIORPANEL
specify_posterior_bvarPANEL

R6 Class Representing PosteriorBVARPANEL
specify_posterior_bvars

R6 Class Representing PosteriorBVARs
specify_prior_bvarPANEL

R6 Class Representing PriorBVARPANEL
specify_starting_values_bvars

R6 Class Representing StartingValuesBVARs
summary.ForecastsPANEL

Provides posterior summary of country-specific Forecasts
summary.PosteriorFEVDPANEL

Provides posterior summary of forecast error variance decompositions
summary.PosteriorBVARs

Provides posterior estimation summary for Bayesian Vector Autoregressions for dynamic panel data
summary.PosteriorBVARPANEL

Provides posterior estimation summary for Bayesian Hierarchical Panel Vector Autoregressions
specify_starting_values_bvarPANEL

R6 Class Representing StartingValuesBVARPANEL
summary.PosteriorBVARGROUPPRIORPANEL

Provides posterior estimation summary for Bayesian Hierarchical Panel Vector Autoregressions with group-specific global prior
summary.PosteriorBVARGROUPPANEL

Provides posterior estimation summary for Bayesian Hierarchical Panel Vector Autoregressions
specify_starting_values_bvarGroupPriorPANEL

R6 Class Representing StartingValuesBVARGROUPPRIORPANEL
compute_forecast_performance

Computes forecasting performance measures for recursive pseudo-out-of-sample forecasts
country_grouping_subregionbroad

A vector with country grouping by subregion for 189 countries
compute_variance_decompositions.PosteriorBVARPANEL

Computes posterior draws of the forecast error variance decomposition
compute_forecast_performance.ForecastsPANELpoos

Computes forecasting performance measures for recursive pseudo-out-of-sample forecasts
compute_variance_decompositions.PosteriorBVARGROUPPANEL

Computes posterior draws of the forecast error variance decomposition
compute_variance_decompositions.PosteriorBVARs

Computes posterior draws of the forecast error variance decomposition
country_grouping_subregiondetailed

A vector with country grouping by detailed subregion for 189 countries
country_grouping_region

A vector with country grouping by region for 189 countries
country_grouping_incomegroup

A vector with country grouping by income group for 189 countries
bpvars-package

Forecasting with Bayesian Panel Vector Autoregressions