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 Cauchy prior with scale difference_scale and 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 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 ADHD data contain 19 symptom ratings with a group column. Compare the two groups (run in advance here; this takes several minutes):

library(bgms)
fit = bgmCompare(
  x = ADHD[, -1],
  group_indicator = ADHD$group,
  variable_type = "ordinal",
  chains = 2,
  seed = 1234
)

The summary(fit)$indicator table reports, for each threshold and each partial association, the posterior probability that the contrast parameters are included — that is, that the groups differ on that parameter. With the default bernoulli_prior(0.5), the difference Bayes factor is again the posterior odds:

ind = summary(fit)$indicator
rows = ind$parameter %in% c("motor-seat (pairwise)",
                            "avoid-closeatt (pairwise)",
                            "forget-talks (pairwise)")
diffs = ind[rows, c("parameter", "mean")]
diffs$BF10 = diffs$mean / (1 - diffs$mean)
print(diffs, digits = 3, row.names = FALSE)
                 parameter  mean    BF10
 avoid-closeatt (pairwise) 0.843   5.390
   forget-talks (pairwise) 0.269   0.367
     motor-seat (pairwise) 0.999 999.000
  • motor-seat: an inclusion probability of 0.999 gives \(\text{BF}_{10} \approx 1000\) — strong evidence that the partial association between these two symptoms differs between the groups.
  • avoid-closeatt: \(\text{BF}_{10} \approx 5\) — moderate evidence for a group difference.
  • forget-talks: an inclusion probability of about 0.27 gives \(\text{BF}_{01} \approx 2.7\) — the data lean toward invariance, but the evidence is weak.

Prior guidance

  • difference_scale = 1 (default): scale of the Cauchy slab on the contrast parameters. This matches the default scale of the baseline interaction_prior (cauchy_prior(scale = 1)).
  • difference_prior = bernoulli_prior(0.5) (default): each difference has a fixed prior inclusion probability of 0.5. Pass beta_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). Setting bernoulli_prior(p) with p = 0.5 makes 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, when main_difference_selection = TRUE) follows a separate Beta-Bernoulli using the within-cluster alpha and beta. See Edge Clustering and SBM Prior for the formulation; cluster summaries are accessible via extract_sbm().

References

Marsman, M., Waldorp, L. J., Sekulovski, N., & Haslbeck, J. M. B. (2025). Bayes factor tests for group differences in ordinal and binary graphical models. Psychometrika, 90(5), 1809–1842. https://doi.org/10.1017/psy.2025.10060
Rouder, J. N., Morey, R. D., Speckman, P. L., & Province, J. M. (2012). Default Bayes factors for ANOVA designs. Journal of Mathematical Psychology, 56(5), 356–374. https://doi.org/10.1016/j.jmp.2012.08.001
Rouder, J. N., Speckman, P. L., Sun, D., & Morey, R. D. (2009). Bayesian \(t\) tests for accepting and rejecting the null hypothesis. Psychonomic Bulletin & Review, 16(2), 225–237. https://doi.org/10.3758/PBR.16.2.225