Overview
The bdsm package implements Bayesian model averaging (BMA) for dynamic panels with weakly exogenous regressors, addressing model uncertainty and reverse causality.
- Tools to estimate the entire model space and calculate Bayesian information criterion (BIC).
- Flexible model priors and comprehensive BMA statistics.
- Functions to visualize prior and posterior model probabilities.
- Support for parallel computing to handle large model spaces.
Installation
You can install the released version of bdsm from CRAN with:
install.packages("bdsm")
Or the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("mateuszwyszynski/bdsm")
Getting Started
Prepare your data in the required format and use the package functions to estimate model spaces, perform Bayesian model averaging, and visualize results.
Examples
Data Preparation
Your data should be in the following format:
install.packages("hexSticker")- A time column (e.g.,
year). - An entity column (e.g.,
country). - A dependent variable column (e.g.,
gdp). - Remaining columns as potential regressors.
library(magrittr)
set.seed(20)
# Features are scaled and demeaned,
# then centralized around the mean within cross-sections (fixed time effects)
data_prepared <- bdsm::economic_growth[, 1:5] %>%
bdsm::feature_standardization(
excluded_cols = c(country, year, gdp)
) %>%
bdsm::feature_standardization(
group_by_col = year,
excluded_cols = country,
scale = FALSE
)
Estimating the Model Space
The function optim_model_space() estimates all possible models (each possible subset of regressors) via maximum likelihood:
model_space <- bdsm::optim_model_space(
df = data_prepared,
dep_var_col = gdp, # Dependent variable
timestamp_col = year,
entity_col = country,
init_value = 0.5
)
Performing Bayesian Model Averaging
Run bma() to obtain posterior model probabilities, posterior inclusion probabilities (PIPs), and other BMA statistics:
bma_results <- bdsm::bma(model_space, df = data_prepared, round = 3)
# Inspect the BMA summary
bma_results[[1]] # BMA stats under binomial prior
Visualizing Prior and Posterior Probabilities
Use model_pmp() to show prior vs. posterior model probabilities:
pmp_graphs <- bdsm::model_pmp(bma_results, top = 3) # Show top 3 models
Contributions and Issues
We welcome bug reports, feature requests, and contributions. Feel free to open an issue or pull request on GitHub.