This document provides a high-level introduction to the BGGM (Bayesian Gaussian Graphical Models) R package. It covers the package's purpose, core conceptual framework, main inference approaches, supported data types, and computational architecture. For detailed information on specific topics, see:
Sources: README.md1-50 DESCRIPTION1-62 paper.md1-109
BGGM is an R package that provides Bayesian inference methods for Gaussian graphical models (GGMs). A Gaussian graphical model represents conditional dependencies among variables as a network of partial correlations, where each edge reflects the relationship between two variables after controlling for all other variables in the model.
| Property | Value |
|---|---|
| Package Name | BGGM |
| Current Version | 2.1.6 |
| License | GPL-2 |
| Repository | https://github.com/rast-lab/BGGM |
| CRAN Page | https://cran.r-project.org/package=BGGM |
| Primary Language | R with C++ backend |
Key Contributors:
Sources: DESCRIPTION1-12 README.md5-12 paper.md10-22
Researchers across sciences (psychology, economics, climate science, genetics) need to understand conditional dependencies between variables. Traditional approaches either:
BGGM extends classical Gaussian graphical modeling by providing:
Sources: README.md14-34 paper.md26-44
BGGM organizes all methods around two fundamental approaches to Bayesian inference:
Focus: Posterior and posterior predictive distributions
Philosophy: Quantify uncertainty about parameters and make predictions
Key Functions:
estimate() - Fit model and obtain posterior samplesggm_compare_estimate() - Compare networks via posterior distributions of differencesggm_compare_ppc() - Compare networks via posterior predictive checksOutput: Posterior distributions, credible intervals, posterior means
Focus: Bayes factors for model comparison
Philosophy: Evaluate evidence for/against specific hypotheses
Key Functions:
explore() - Edge-by-edge Bayes factors without pre-specified hypothesesconfirm() - Test theory-driven (in)equality constraintsggm_compare_explore() - Group comparison via Bayes factorsggm_compare_confirm() - Test group-specific hypothesesOutput: Bayes factors, posterior hypothesis probabilities, evidence classifications
Sources: README.md14-20 README.Rmd31-35
Function Categories:
| Category | Functions | Purpose |
|---|---|---|
| Estimation | estimate() | Posterior-based network inference |
| Exploration | explore() | Data-driven edge discovery via BF |
| Confirmation | confirm() | Theory-driven hypothesis testing |
| Group Comparison | ggm_compare_*() (4 variants) | Multi-group network comparison |
| Selection | select() | Identify significant edges |
| Extraction | coef(), pcor_mat(), posterior_samples() | Extract model components |
| Advanced Analysis | predictability(), roll_your_own(), predict() | Extended inference |
| Visualization | plot() | Network and diagnostic plots |
| Missing Data | bggm_missing() | Integration with mice package |
Sources: README.md54-102 README.Rmd68-99
BGGM handles four data types through a unified latent variable framework:
| Type | Description | Model | Key Parameter | C++ Sampler |
|---|---|---|---|---|
| continuous | Gaussian data | Direct Wishart | type = "continuous" | _BGGM_Theta_continuous |
| binary | 0/1 coded data | Probit (latent truncated normal) | type = "binary" | _BGGM_mv_binary |
| ordinal | Ordered categories | Threshold model | type = "ordinal" | _BGGM_mv_ordinal_albert_BGGM_mv_ordinal_cowles |
| mixed | Combination | Semi-parametric copula | type = "mixed" | _BGGM_copula |
Users specify the data type via the type argument in main functions:
For non-continuous types, BGGM models latent Gaussian variables underlying the observed discrete data. Partial correlations represent relationships between these latent variables, not the observed categories directly. This approach:
Sources: README.md103-123 README.Rmd106-122 paper.md79-95
From DESCRIPTION23-57:
Core Imports:
BFpack (≥ 1.2.3) - Bayes factor computation for confirm()Rcpp (≥ 1.0.4.6) - R-C++ interfaceMASS, mvnfast - Statistical distributionsGGally, ggplot2, network, sna - VisualizationLinkingTo (C++):
RcppArmadillo - Matrix operationsRcppDist - Statistical distributions (Wishart)RcppProgress - User feedback during samplingSuggested (Optional):
mice - Missing data imputationnetworktools, assortnet - Network statisticstestthat - Testing frameworkSources: DESCRIPTION23-57 README.md94-101 paper.md97-99
BGGM uses S3 classes for fitted model objects:
All fitted objects share:
type - Data type ("continuous", "binary", "ordinal", "mixed")iter - Number of MCMC iterationsp - Number of variablescall - Original function callpcor_mat - Posterior mean partial correlation matrixestimate objects:
post_samp$pcors - Posterior samples (array: iter × p × p)analytic - Boolean flag for analytic solution (continuous only)formula - Optional control variable formulaexplore objects:
BF_01 - Bayes factor matrix (p × p) for null hypothesisprior_samp - Prior samples for Savage-Dickey ratioconfirm objects:
out_hyp_prob - Posterior hypothesis probabilitiesBF_matrix - Pairwise Bayes factors between hypotheseshypothesis - String specifying constraintsSources: README.md182-239 README.Rmd148-187
BGGM uses the matrix-F prior distribution for the precision matrix (inverse covariance). This prior:
prior_sd parameter (related to expected partial correlation magnitude)Users control the prior through prior_sd (or deprecated delta):
The relationship: delta = sqrt(prior_sd^(-2) - 1)
Valid range: 0 < prior_sd ≤ sqrt(1/2) ensures delta ≥ 1
Sources: README.md59-60 NEWS.md52-53 inst/REFERENCES.bib145-156
When type = "continuous" and n > p, BGGM offers an analytic solution based on the Wishart distribution:
Advantages:
Limitations:
type = "continuous"Use Cases:
Sources: README.md261-278 README.Rmd211-225
BGGM handles missing data through two mechanisms:
The bggm_missing() function interfaces with the mice package for multiple imputation:
Workflow:
mice::mice() → multiple datasetsestimate or explore object with pooled resultsSources: R/bggm_missing.R1-210 man/bggm_missing.Rd1-91
For continuous and mixed data, BGGM can impute missing values during MCMC sampling:
This treats missing values as additional parameters to be sampled.
Sources: README.md101 README.Rmd104
| Version | Key Changes |
|---|---|
| 2.1.6 | Ordinal sampler improvements: Stan-style latent centering, threshold initialization from empirical frequencies, improved stability for skewed data |
| 2.1.5 | Removed NPM library for CRAN compatibility |
| 2.1.4 | Improved search() function: adaptive sampling, better initialization |
| 2.1.3 | Adjusted prior_sd computation, replaced deprecated Armadillo functions |
| 2.1.2 | Critical fix: select() returned Fisher-z instead of correlations |
| 2.0.0 | Major rewrite with C++ backend, full support for binary/ordinal/mixed data, added roll_your_own(), convergence(), pcor_to_cor(), and more |
| 1.0.0 | Initial CRAN release |
Current Development Version: 2.1.6.9000
Sources: NEWS.md1-111 DESCRIPTION4-5
BGGM is unique in the R ecosystem for combining:
Comparison to other packages:
| Package | Language | Capabilities | Limitations vs. BGGM |
|---|---|---|---|
| sbgcop | Base R | Mixed data (copula) | No hypothesis testing, slower |
| BDgraph | C++ | Gaussian copula | No binary/ordinal support, no confirmatory testing |
| qgraph | R | Network visualization | Not Bayesian, no inference |
| bootnet | R | Network stability | Frequentist only |
BGGM's unique contributions:
Sources: README.md1025-1034 paper.md101-103
BGGM was built specifically for social-behavioral scientists, though methods apply broadly across:
Not designed for: High-dimensional data (p > n)
BGGM requires n ≥ p (more observations than variables), which is typical in social-behavioral research but rare in genetics/bioinformatics.
roll_your_own() for custom network statisticsSources: README.md1009-1017 paper.md40-43
To cite BGGM in publications:
Williams, D. R., & Mulder, J. (2020). BGGM: Bayesian Gaussian Graphical Models in R. Journal of Open Source Software, 5(51), 2111. https://doi.org/10.21105/joss.02111
Key methodological papers:
Sources: README.md1036-1290 inst/REFERENCES.bib35-156 paper.md23-109
Refresh this wiki