Group Comparison
The bgmCompare() function tests whether the network parameters differ between groups in networks of binary or ordinal variables (Marsman et al., 2025). It estimates both the shared network — the overall partial associations and category thresholds — and the group differences, using the same Bayesian framework as bgm(). A key advantage of this approach is its ability to distinguish three outcomes for each parameter: evidence that a parameter differs across groups, evidence that it is invariant, and absence of evidence — the data are simply not informative enough to decide.
Note that bgmCompare() currently supports binary and ordinal variables only; group comparison for networks with continuous or mixed variables is not yet available.
The model
The group comparison model separates overall effects from group differences. For each pair of variables \((i, j)\), the group-specific partial association in group \(g\) is constructed as
\[ \omega_{ij}^{(g)} = \omega_{ij} + \sum_{k=1}^{G-1} c_{gk}\,\delta_{ij}^{(k)} \]
where \(\omega_{ij}\) is the overall partial association — the value that would be obtained if all groups were combined — and \(\delta_{ij}^{(k)}\) are the contrast parameters, one for each of the \(G - 1\) orthogonal contrasts. The coefficients \(c_{gk}\) come from an orthonormal projection matrix (a fixed recipe that maps the contrast parameters to group-specific effects). Category thresholds are decomposed in the same way.
For two groups, the projection matrix reduces to \(c = (-\tfrac{1}{2},\; +\tfrac{1}{2})^\top\), so that \(\omega_{ij}^{(g)} = \omega_{ij} \pm \tfrac{1}{2}\,\delta_{ij}\) — the single contrast parameter is then simply a scaled group difference. This is the centered parameterization of the Bayesian independent-samples \(t\)-test (Rouder et al., 2009), where the overall effect and the group difference are separated. For more than two groups, the projection generalizes the idea to an ANOVA-like design with \(G - 1\) orthogonal contrasts (Rouder et al., 2012); the contrast parameters are then projections onto orthogonal basis directions, not pairwise group differences. In each case, making the differences explicit parameters — rather than computing them post hoc from separate group estimates — allows each difference to receive its own prior distribution and its own hypothesis test.
Defining groups
Groups can be specified in two ways:
Two separate datasets — pass x (Group 1) and y (Group 2):
fit = bgmCompare(x = data_group1, y = data_group2, seed = 1234)Group membership vector — pass a single dataset with a group indicator (two or more groups):
fit = bgmCompare(x = data, group_indicator = groups, seed = 1234)Difference selection
When difference_selection = TRUE (the default), spike-and-slab priors are placed on the contrast parameters. For each pairwise interaction, a binary indicator \(\gamma_{ij}\) — here indexing difference inclusion, not the edge inclusion it denotes in bgm() — governs whether the contrast parameters are included in the model:
- When \(\gamma_{ij} = 0\) (spike), the contrast parameters are exactly zero — all groups have the same partial association.
- When \(\gamma_{ij} = 1\) (slab), each contrast parameter receives a slab prior and is estimated from the data. The slab family is set by
difference_family—"Normal"(the default) or"Cauchy"— with scaledifference_scale.
By default, only pairwise interaction differences are selected (main_difference_selection = FALSE). Threshold differences are always included as free parameters. This default reflects that thresholds are typically nuisance parameters: their selection can interfere with pairwise selection under the Beta-Bernoulli prior, and group differences in thresholds are rarely the primary research question.
Bayes factors for group differences
The inclusion Bayes factor for a group difference has the same form as for edge selection (see Edge Selection):
\[ \text{BF}_{10} = \frac{p(\gamma_{ij} = 1 \mid \text{data})}{p(\gamma_{ij} = 0 \mid \text{data})} \bigg/ \frac{p(\gamma_{ij} = 1)}{p(\gamma_{ij} = 0)} \]
Values greater than one indicate evidence that the groups differ on the partial association between variables \(i\) and \(j\). Values less than one — equivalently, \(1/\text{BF}_{10}\) greater than one — indicate evidence that the parameter is invariant. Values close to one indicate that the data are uninformative: there is not enough evidence to decide whether the parameter differs between groups or not. This three-way distinction — evidence for a difference, evidence for equivalence, and absence of evidence — is the central advantage of the Bayesian approach to group comparison.
As with edge selection, the inclusion Bayes factor averages over all possible configurations of the remaining group differences. Testing whether the interaction between variables \(i\) and \(j\) differs across groups does not require assumptions about which other interactions differ — the test integrates over this uncertainty. See Other approaches to testing conditional independence and The Bayesian Approach for the formal derivation.
Interpreting the output
The summary() method reports posterior summaries for the shared parameters \(\omega_{ij}\) and the contrast parameters \(\delta_{ij}\), including posterior inclusion probabilities and Bayes factors.
The coef() method returns:
$pairwise_effects_groups: group-specific posterior mean partial associations, reconstructed from the overall effects and the projection of the contrast parameters.$main_effects_groups: group-specific posterior mean thresholds.$indicator: posterior inclusion probabilities for the group differences.
A worked example
The full comparison of the ADHD groups, run at the package defaults, is the worked analysis Comparing groups: the three-way verdicts on all 153 pairwise differences (5 supported, 148 undecided, none reaching evidence of equivalence at the default threshold), the strongest difference walked through its group-specific weights, and the reporting templates for both kinds of claim.
Prior guidance
difference_scale = 1(default): scale of the slab on the contrast parameters, whose family is set bydifference_family("Normal"by default,"Cauchy"as the heavier-tailed alternative). The default matches the scale of the baselineinteraction_prior(normal_prior(scale = 1)), and both matchbgm(), so a comparison and separate single-group fits place the same prior on a baseline interaction. Passdifference_family = "Cauchy"andinteraction_prior = cauchy_prior(scale = 1)to recover the pre-0.2.0.0 behavior. The choice matters most for differences the data cannot inform, such as thresholds of categories one group never observed: a Normal slab keeps such a difference within a moderate range, where a Cauchy slab lets it wander.difference_prior = bernoulli_prior(0.5)(default): each difference has a fixed prior inclusion probability of 0.5. Passbeta_bernoulli_prior(1, 1)to place a beta hyperprior on the inclusion probability instead — this provides automatic multiplicity correction, important when the number of potential group differences is large (Marsman et al., 2025). Settingbernoulli_prior(p)withp = 0.5makes the prior odds equal to one, so the Bayes factor simplifies to the posterior odds.difference_prior = sbm_prior(...): a stochastic block model on the off-diagonal differences, with cluster-structured inclusion probabilities. Useful when group differences are expected to concentrate within latent clusters of variables. The diagonal (main-effect difference inclusions, whenmain_difference_selection = TRUE) follows a separate Beta-Bernoulli using the within-clusteralphaandbeta. See Edge Clustering and SBM Prior for the formulation; cluster summaries are accessible viaextract_sbm().