An R package for Forecasting with Bayesian Hierarchical Panel Vector Autoregressions
Provides Bayesian estimation and forecasting of dynamic panel data using Bayesian Hierarchical Panel Vector Autoregressions (VARs). 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 bvarPANELs 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.
-
The model in the bvarPANELs 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 = Ac Xc + Ec (VAR equation) Ec | Xc ~ MN(0, Sc, I) (error term normality)
- dependent variables
-
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 matrixI
. -
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 matrixS
:
Yc = A Xc + Ec (VAR equation)
Ec | Xc ~ MN(0, S, I) (error term normality)
- See more details in this presentation
- 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()
andsummary()
methods to gain the insights into the core of the empirical problem.
- 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:
**************************************************|
bvarPANELs: 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%
[----|----|----|----|----|----|----|----|----|----|
*************************************
This beautiful logo can be reproduced in R using this file.

- a reference manual
- a website of the family of packages bsvars.org
- presentations:
- for the International Labour Organization given March 2025 featuring bvarPANELs 0.2]
The beginnings are as easy as ABC:
library(bvarPANELs) # load the package
spec = specify_bvarPANEL$new( # specify the model
ilo_dynamic_panel, # data
exogenous = ilo_exogenous_variables, # exogenous variables
stationary = c(FALSE, FALSE, FALSE, TRUE), # stationarity (determines prior mean)
type = c("real", "rate", "rate", "rate") # variable types
)
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
exogenous_forecast = ilo_exogenous_forecasts, # forecasts for exogenous variables
conditional_forecast = ilo_conditional_forecasts # gdp projections
)
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 bvarPANELs package supports a simplified workflow using the |>
pipe:
ilo_dynamic_panel |> # data
specify_bvarPANEL$new( # specify the model
exogenous = ilo_exogenous_variables, # exogenous variables
stationary = c(FALSE, FALSE, FALSE, TRUE), # stationarity (determines prior mean)
type = c("real", "rate", "rate", "rate") # variable types
) |>
estimate(S = 10000) |> # run the burn-in
estimate(S = 10000) -> post # estimate the model
post |> forecast( # forecast the model
horizon = 6, # forecast horizon
exogenous_forecast = ilo_exogenous_forecasts, # forecasts for exogenous variables
conditional_forecast = ilo_conditional_forecasts # gdp projections
) |> plot("COL", main = "Forecasts for Colombia")
Now, you’re ready to analyse your model!
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.
Just open your R and install the package from its developer’s repository by typing:
devtools::install_github("bsvars/bvarPANELs")
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!
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 cpp using Rcpp.