Skip to content

The R package bgms provides tools for Bayesian analysis of graphical models describing networks of binary, ordinal, continuous, and mixed variables (Marsman et al. 2025) . Supported model families include ordinal Markov random fields (MRFs), Gaussian graphical models (GGMs), and mixed MRFs that combine discrete and continuous variables in a single network. The likelihood is approximated via a pseudolikelihood, and Markov chain Monte Carlo (MCMC) methods are used to sample from the corresponding pseudoposterior distribution of model parameters.

The main entry points are:

  • bgm: estimation in a one-sample design. Use variable_type = "ordinal" for an MRF, "continuous" for a GGM, or a per-variable vector mixing "ordinal", "blume-capel", and "continuous" for a mixed MRF.

  • bgmCompare: estimation and group comparison in an independent-sample design.

Both functions support Bayesian effect selection with spike-and-slab priors.

  • In one-sample designs, bgm models the presence or absence of edges between variables. Posterior inclusion probabilities quantify the plausibility of each edge and can be converted into Bayes factors for conditional independence tests.

  • bgm can also model communities (clusters) of variables. The posterior distribution of the number of clusters provides evidence for or against clustering (Sekulovski et al. 2025) .

  • In independent-sample designs, bgmCompare estimates group differences in edge weights and category thresholds. Posterior inclusion probabilities quantify the evidence for differences and can be converted into Bayes factors for parameter equivalence tests (Marsman et al. 2025) .

Tools

The package also provides:

  1. Simulation of response data from MRFs with a Gibbs sampler (simulate_mrf).

  2. Posterior estimation and edge selection in one-sample designs (bgm).

  3. Posterior estimation and group-difference selection in independent-sample designs (bgmCompare).

Vignettes

For tutorials and worked examples, see:

References

Marsman M, van den Bergh D, Haslbeck JMB (2025). “Bayesian analysis of the ordinal Markov random field.” Psychometrika, 90(1), 146–182. doi:10.1017/psy.2024.4 .

Marsman M, Waldorp LJ, Sekulovski N, Haslbeck JMB (2025). “Bayes factor tests for group differences in ordinal and binary graphical models.” Psychometrika, 90(5), 1809–1842. doi:10.1017/psy.2025.10060 .

Sekulovski N, Arena G, Haslbeck JMB, Huth KBS, Friel N, Marsman M (2025). “A Stochastic Block Prior for Clustering in Graphical Models.” Retrieved from https://osf.io/preprints/psyarxiv/29p3m_v1. OSF preprint.

Author

Maintainer: Maarten Marsman m.marsman@uva.nl (ORCID)

Authors:

  • Don van den Bergh (ORCID)

Other contributors:

  • Nikola Sekulovski (ORCID) [contributor]

  • Giuseppe Arena (ORCID) [contributor]

  • Laura Groot [contributor]

  • Gali Geller [contributor]