13.2 Example: Admission decisions and gender
The UC Berkeley admission data illustrate how varying slopes can reveal or remove apparent associations — a classic case of Simpson's paradox.
13.2.1 Simpson's paradox
In the aggregate data, women appear less likely to be admitted. Within departments, the pattern often reverses or disappears. A varying slopes model by department reveals how the gender-admission association varies:
# Simulate Simpson's paradox: admission data
set.seed(42)
n_depts <- 6
# Departments vary in selectivity and gender bias
# Some departments favor males, some favor females, some are neutral
dept_intercept <- rnorm(n_depts, 0, 1.5)
dept_slope <- rnorm(n_depts, 0, 0.5) # gender effect varies by dept
# More women apply to selective (low intercept) departments
# This creates the paradox: aggregate shows women disadvantaged
n_per <- 100
d <- do.call(rbind, lapply(1:n_depts, function(j) {
male <- sample(c(0, 1), n_per, replace = TRUE, prob = c(0.7, 0.3)) # more women apply
logit_p <- dept_intercept[j] + dept_slope[j] * male
p <- 1 / (1 + exp(-logit_p))
admit <- rbinom(n_per, 1, p)
data.frame(dept = factor(j), male = male, admit = admit)
}))
# Aggregate model (ignores department)
m_agg <- glm(admit ~ male, family = binomial, data = d)
cat("Aggregate model (Simpson's paradox):\n")
cat(" male coefficient:", round(coef(m_agg)[2], 3), "\n")
# Varying slopes by department
library(lme4)
m_vary <- glmer(admit ~ male + (1 + male | dept), family = binomial, data = d)
cat("\nVarying slopes model:\n")
cat(" Fixed male effect:", round(fixef(m_vary)[2], 3), "\n")
cat(" Dept intercept SD:", round(attr(VarCorr(m_vary)$dept, "stddev")[1], 3), "\n")
cat(" Dept slope SD: ", round(attr(VarCorr(m_vary)$dept, "stddev")[2], 3), "\n")
cat(" Correlation: ", round(attr(VarCorr(m_vary)$dept, "correlation")[1, 2], 3), "\n")
# Department-specific effects
cat("\n Department-specific male effects:\n")
dept_slopes <- fixef(m_vary)[2] + ranef(m_vary)$dept[, 2]
for (j in 1:n_depts) {
cat(sprintf(" Dept %d: %.3f\n", j, dept_slopes[j]))
}
cat("\n The aggregate effect may differ from department effects!\n")13.2.2 Interpreting the varying slopes
# Visualize department-specific effects
set.seed(42)
n_depts <- 6
dept_intercept <- rnorm(n_depts, 0, 1.5)
dept_slope <- rnorm(n_depts, 0, 0.5)
n_per <- 100
d <- do.call(rbind, lapply(1:n_depts, function(j) {
male <- sample(c(0, 1), n_per, replace = TRUE, prob = c(0.7, 0.3))
logit_p <- dept_intercept[j] + dept_slope[j] * male
p <- 1 / (1 + exp(-logit_p))
admit <- rbinom(n_per, 1, p)
data.frame(dept = factor(j), male = male, admit = admit)
}))
library(lme4)
m <- glmer(admit ~ male + (1 + male | dept), family = binomial, data = d)
# Extract department effects
dept_int <- fixef(m)[1] + ranef(m)$dept[, 1]
dept_slp <- fixef(m)[2] + ranef(m)$dept[, 2]
# Plot: department-specific admission probabilities
plot(0, 0, type = "n", xlim = c(-0.5, 1.5), ylim = c(0, 1),
xlab = "Male (0 = female, 1 = male)", ylab = "P(admit)",
main = "Department-specific admission curves")
for (j in 1:n_depts) {
x_seq <- c(0, 1)
logit_p <- dept_int[j] + dept_slp[j] * x_seq
p <- 1 / (1 + exp(-logit_p))
lines(x_seq, p, col = j, lwd = 2)
}
legend("topright", legend = paste("Dept", 1:n_depts), col = 1:n_depts, lwd = 2,
cex = 0.8)
cat("Each department has its own admission curve.\n")
cat("Some favor males, some favor females, some are neutral.\n")
cat("The aggregate effect hides this variation.\n")Simpson's paradox is a pooling problem. Simpson's paradox is not really a paradox — it is a consequence of ignoring grouping structure. When groups differ in both the outcome and the predictor, the aggregate relationship can reverse the within-group relationship. The varying slopes model solves this by estimating department-specific effects. But it also tells us something deeper: the variation across departments is itself informative. If the gender effect varies a lot across departments, the "average" gender effect is not very meaningful. We need to understand why departments differ, not just what the average is.
Summary of Section 13.2
- Simpson's paradox: aggregate effect can reverse within-group effects.
- Varying slopes by department reveal how the gender-admission association varies.
- The covariance between intercepts and slopes captures how selectivity and bias relate.
- The variation across departments is as important as the average effect.
- Varying slopes solve the paradox by not pooling when they shouldn't.