Bayesian analysis of graphical models
The bgms package provides Bayesian estimation and edge selection for Markov random field models of mixed binary, ordinal, and continuous variables. The variable types in the data determine the model: an ordinal MRF for ordinal data, a Gaussian graphical model for continuous data, or a mixed MRF combining both. Posterior inference uses Markov chain Monte Carlo, combining a Metropolis approach for between-model moves (i.e., edge selection) with the No-U-Turn sampler for within-model parameter updates. The package supports both single-threaded and parallel chains, and uses a C++ backend for computational efficiency.
bgm()— estimate a graphical model in a one-sample design.bgmCompare()— compare graphical models between groups.
Both functions support edge selection via spike-and-slab priors,
yielding posterior inclusion probabilities for each edge. bgm() can
additionally model community structure, and bgmCompare() can test
for group differences in individual parameters.
Install from CRAN:
install.packages("bgms")Or install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("Bayesian-Graphical-Modelling-Lab/bgms")If you use bgms in your work, please cite:
- Marsman, M., van den Bergh, D., & Haslbeck, J. M. B. (2025).
Bayesian analysis of the ordinal Markov random field.
Psychometrika, 90(1), 146–182.
Related methodological papers:
-
Sekulovski, N., Keetelaar, S., Huth, K. B. S., Wagenmakers, E.-J., van Bork, R., van den Bergh, D., & Marsman, M. (2024). Testing conditional independence in psychometric networks: An analysis of three Bayesian methods. Multivariate Behavioral Research, 59, 913–933.
-
Marsman, M., Waldorp, L. J., Sekulovski, N., & Haslbeck, J. M. B. (2025). Bayes factor tests for group differences in ordinal and binary graphical models. Psychometrika, 90(5), 1809–1842.
-
Sekulovski, N., Arena, G., Haslbeck, J. M. B., Huth, K. B. S., Friel, N., & Marsman, M. (2025). A stochastic block prior for clustering in graphical models.
You can also retrieve the citation from R:
citation("bgms")Contributions are welcome. See CONTRIBUTING.md for how to get started.
This project follows the Contributor Covenant Code of Conduct.