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.
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 difference parameters, one for each of the \(G - 1\) orthogonal contrasts. The coefficients \(c_{gk}\) come from an orthonormal projection matrix 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}\). 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). 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 group difference parameters. For each pairwise interaction, a binary indicator \(\gamma_{ij}\) governs whether the difference is included in the model:
- When \(\gamma_{ij} = 0\) (spike), the difference is exactly zero — all groups have the same partial association.
- When \(\gamma_{ij} = 1\) (slab), the difference receives a Cauchy prior with scale
difference_scaleand is estimated from the data.
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 group difference 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 difference parameters.$main_effects_groups: group-specific posterior mean thresholds.$indicator: posterior inclusion probabilities for the group differences.
Prior guidance
difference_scale = 1(default): scale of the Cauchy prior for the difference parameters. This matches the current defaultpairwise_scale(1) for baseline partial associations.difference_prior = "Bernoulli"(default): each difference has a fixed prior inclusion probability. Set to"Beta-Bernoulli"to place a beta hyperprior on the inclusion probability, which provides automatic multiplicity correction — important when the number of potential group differences is large (Marsman et al., 2025).difference_probability = 0.5(default): prior probability that any given difference is nonzero. Whendifference_probability = 0.5, the prior odds equal one and the Bayes factor simplifies to the posterior odds.