library(bgms)
data = ADHD[, 2:6]
head(data)Binary Network
This page has not yet passed technical or readability review.
An end-to-end analysis of binary data using the ordinal Markov random field. This example uses the ADHD dataset bundled with bgms.
Data
The ADHD dataset contains binary symptom ratings for 355 children. The first column is a group indicator (ADHD diagnosis); columns 2–19 are nine Inattentive and nine Hyperactive/Impulsive items scored as present (1) or absent (0). We drop the group column and analyze the first five Inattentive items.
Fit the model
Binary variables are a special case of ordinal data (two categories). bgm() fits an ordinal MRF with spike-and-slab edge selection by default.
fit = bgm(data, seed = 1234)Posterior summaries
summary(fit)
coef(fit)Edge selection
The posterior inclusion probabilities indicate the evidence for each edge:
coef(fit)$indicatorConvert to Bayes factors when the prior inclusion probability equals 0.5:
p = coef(fit)$indicator[1, 2]
BF_10 = p / (1 - p) # evidence for inclusion
1 / BF_10 # evidence for exclusionInterpretation
Threshold the inclusion probabilities at 0.5 and plot with qgraph (Epskamp et al., 2012).
library(qgraph)
median_probability_network = coef(fit)$pairwise
median_probability_network[coef(fit)$indicator < 0.5] = 0.0
qgraph(median_probability_network,
theme = "TeamFortress",
maximum = 1,
fade = FALSE,
color = c("#f0ae0e"), vsize = 10, repulsion = .9,
label.cex = 1, label.scale = "FALSE",
labels = colnames(data)
)Diagnostics
summary(fit)$pairwise
fit$nuts_diag$summarySee the MCMC Diagnostics guide for interpretation.