Functions to extract specific components from fitted bgms and bgmCompare objects. Executed examples on this page use a bgm() fit of the Wenchuan data (fit = bgm(Wenchuan, chains = 2, seed = 1234)).
Unless noted otherwise, extractor functions use one argument:
bgms_object: a fitted bgms or bgmCompare object.
extract_arguments
Retrieve the arguments used when fitting a model with bgm() or bgmCompare().
extract_arguments(bgms_object)
Returns a named list containing all arguments passed to the fitting function, including data dimensions, prior settings, and MCMC configuration.
extract_main_effects
Retrieve posterior mean main-effect parameters.
extract_main_effects(bgms_object)
The structure depends on the model type:
GGM (bgms): NULL. GGM models have no main effects.
OMRF (bgms): A numeric matrix (p x max_categories) of posterior mean category thresholds. Columns beyond the number of categories for a variable are NA.
Mixed MRF (bgms): A list with $discrete (threshold matrix) and $continuous (means matrix).
bgmCompare: A matrix with one row per post-warmup iteration, containing posterior samples of baseline main-effect parameters.
extract_pairwise_interactions
Retrieve posterior samples of partial association parameters.
extract_pairwise_interactions(bgms_object)
Returns a matrix with one row per post-warmup iteration and one column per edge. For bgmCompare, columns correspond to baseline partial association parameters.
extract_indicators
Retrieve posterior samples of inclusion indicators.
extract_indicators(bgms_object)
Returns a matrix with one row per post-warmup iteration and one column per indicator, containing binary (0/1) samples:
bgms: One column per edge. Requires edge_selection = TRUE.
bgmCompare: Columns for main-effect and pairwise difference indicators. Requires difference_selection = TRUE.
Here the intrusion–dreams edge is included in every posterior draw (probability 1), while intrusion–upset is included in about 60% of draws — the data do not clearly decide that edge. See Edge Selection for turning these into Bayes factors. - bgmCompare: Diagonal entries are main-effect inclusion probabilities; off-diagonal entries are pairwise difference inclusion probabilities. Requires difference_selection = TRUE.
extract_indicator_priors
Retrieve the prior specification used for inclusion indicators.
extract_indicator_priors(bgms_object)
Returns a named list describing the prior structure, including the prior type and hyperparameters:
bgms: Requires edge_selection = TRUE. Returns the prior type ("Bernoulli", "Beta-Bernoulli", or "Stochastic-Block") and associated hyperparameters.
bgmCompare: Requires difference_selection = TRUE. Returns the difference prior specification.
extract_group_params
Compute group-specific parameter estimates by combining baseline parameters and group differences.
extract_group_params(bgms_object)
bgms_object must be a fitted bgmCompare object.
Returns a list with main_effects_groups (main effects per group) and pairwise_effects_groups (pairwise effects per group).
extract_sbm
Retrieve posterior summaries from a model fitted with the Stochastic Block prior.
extract_sbm(bgms_object)
Works on both bgms and bgmCompare fits.
For bgms: requires edge_selection = TRUE and edge_prior = sbm_prior(...).
For bgmCompare: requires difference_selection = TRUE and difference_prior = sbm_prior(...). The clustering applies to the off-diagonal (pairwise) difference inclusions.
Returns a list with:
posterior_num_blocks — Posterior probabilities for each possible number of clusters.
posterior_mean_allocations — Posterior mean cluster allocations.
Retrieve effective sample size estimates for all parameters.
extract_ess(bgms_object)
Returns a named list with ESS values for each parameter type present in the model (e.g., main, pairwise, indicator). ESS values match coda::effectiveSize. For implementation details, see the Technical Manual.
Low values relative to the total number of retained draws signal slow mixing for that parameter; see MCMC Diagnostics for guidance.
extract_rhat
Retrieve R-hat convergence diagnostics for all parameters.
extract_rhat(bgms_object)
Returns a named list with R-hat values for each parameter type present in the model (e.g., main, pairwise, indicator). R-hat follows the Gelman-Rubin formula, matching coda::gelman.diag. For implementation details, see diagnostics in the Technical Manual.
extract_precision
Retrieve the posterior mean precision matrix.
extract_precision(bgms_object)
bgms_object must be a fitted bgms object (GGM or mixed MRF).
Returns a symmetric p x p matrix (or the continuous block submatrix for mixed MRFs) containing the posterior mean precision matrix \(\boldsymbol{\Theta}\).
extract_partial_correlations
Retrieve the posterior mean partial correlation matrix.
extract_partial_correlations(bgms_object)
bgms_object must be a fitted bgms object (GGM or mixed MRF).
Returns a symmetric matrix of partial correlations, computed by standardizing the precision matrix: \(\rho_{ij} = -\Theta_{ij} / \sqrt{\Theta_{ii}
\Theta_{jj}}\).
extract_log_odds
Retrieve the posterior mean log-odds matrix.
extract_log_odds(bgms_object)
bgms_object must be a fitted bgms object (OMRF or mixed MRF).
Returns a symmetric matrix of log adjacent-category odds ratios. For the ordinal MRF, \(\text{log-odds}_{ij} = 2 \omega_{ij}\).
Deprecated functions
extract_category_thresholds() — Renamed to extract_main_effects().
extract_edge_indicators() — Renamed to extract_indicators().
extract_pairwise_thresholds() — Renamed to extract_main_effects().