# Structural graphs from margin lists (3-way: A, B, C)
mutual(3, factors = c("A", "B", "C")) |> assoc_graph()
joint(3, factors = c("A", "B", "C")) |> assoc_graph()
conditional(3, factors = c("A", "B", "C")) |> assoc_graph()
saturated(3, factors = c("A", "B", "C")) |> assoc_graph()
# Adjacency matrix form
conditional(3, factors = c("A", "B", "C")) |> assoc_graph(result = "matrix")
# From a fitted loglm model (Berkeley admissions)
if (FALSE) {
mod <- MASS::loglm(~ (Admit + Gender) * Dept, data = UCBAdmissions)
assoc_graph(mod)
plot(assoc_graph(mod), main = "Berkeley: [AD] [GD]")
}
# From glm models (Dayton Survey: cigarette, alcohol, marijuana, sex, race)
data(DaytonSurvey)
# Mutual independence + sex*race: one edge only
mod.SR <- glm(Freq ~ . + sex*race, data = DaytonSurvey, family = poisson)
assoc_graph(mod.SR)
plot(assoc_graph(mod.SR), main = "Mutual indep. + [SR]")
# [AM][AC][MC][AR][AS][RS]: {race, sex} indep {marijuana, cigs} | alcohol
mod.cond <- glm(Freq ~ (cigarette + alcohol + marijuana)^2 +
(alcohol + sex + race)^2,
data = DaytonSurvey, family = poisson)
# define groups for the model
gps <- list(c("cigarette", "marijuana"),
"alcohol",
c("sex", "race"))
assoc_graph(mod.cond)
plot(assoc_graph(mod.cond),
groups = gps,
layout = igraph::layout_nicely,
main = "{R,S} indep {M,C} | A")
# Weighted graph: partial chi-squared
g <- assoc_graph(mod.cond, measure = "chisq")
g
plot(g, edge.label = TRUE,
groups = gps,
layout = igraph::layout_nicely,
main = "Partial chi-squared weights")
# Cramer's V (marginal)
g2 <- assoc_graph(mod.cond, measure = "cramer")
g2
plot(g2, edge.label = TRUE,
groups = gps,
layout = igraph::layout_nicely,
main = "Cramer's V weights")
Run the code above in your browser using DataLab