library(bgms)
data_adhd = ADHD[ADHD$group == 1, -1]
data_adhd = data_adhd[, 1:5]
data_no_adhd = ADHD[ADHD$group == 0, -1]
data_no_adhd = data_no_adhd[, 1:5]Group Comparison
This page has not yet passed technical or readability review.
Comparing networks across two independent groups using bgmCompare(). This example uses the ADHD dataset bundled with bgms.
Data
The ADHD dataset contains binary symptom ratings for 355 children. Column 1 is a group indicator: 1 = ADHD diagnosis (n = 146), 0 = no diagnosis (n = 209). We split on this column and analyze the first five Inattentive items in each group.
Fit the comparison model
bgmCompare() estimates whether edge weights and category thresholds differ between the two groups.
fit = bgmCompare(x = data_adhd, y = data_no_adhd, seed = 1234)Posterior summaries
The summary shows baseline effects and group differences. coef() provides posterior means and inclusion probabilities for both.
summary(fit)
coef(fit)Identifying network differences
Posterior inclusion probabilities indicate how plausible it is that a given parameter differs between groups. These convert to Bayes factors in the same way as for single-group models.
Interpretation
Extract the group-specific pairwise effects and plot the network for the ADHD group using qgraph (Epskamp et al., 2012).
library(qgraph)
adhd_network = matrix(0, 5, 5)
adhd_network[lower.tri(adhd_network)] = coef(fit)$pairwise_effects_groups[, 1]
adhd_network = adhd_network + t(adhd_network)
colnames(adhd_network) = colnames(data_adhd)
rownames(adhd_network) = colnames(data_adhd)
qgraph(adhd_network,
theme = "TeamFortress",
maximum = 1,
fade = FALSE,
color = c("#f0ae0e"), vsize = 10, repulsion = .9,
label.cex = 1, label.scale = "FALSE",
labels = colnames(data_adhd)
)Diagnostics
summary(fit)$pairwiseSee the MCMC Diagnostics guide for interpretation.