| term | estimate |
|---|---|
| (Intercept) | 26.64 |
| Race1Black | 3.14 |
| Gendermale | 0.16 |
| Race1Black:Gendermale | -3.6 |
Week 2: Causal Inference & Social Epi
September 15, 2025
Benefits of explicitly conceptualizing a hypothetical intervention
Why should we care SDoH, even those with small “effect sizes”?
| # Intervened | # Cases | # Cases if Intervened | # Cases Prevented |
|---|---|---|---|
| 1,000 | 100 | ||
| 10,000 | 1,000 | ||
| 100,000 | 10,000 |
| # Intervened | # Cases | # Cases if Intervened | # Cases Prevented |
|---|---|---|---|
| 1,000 | 100 | 98 | 2 |
| 10,000 | 1,000 | 980 | 20 |
| 100,000 | 10,000 | 9,800 | 200 |
Identification assumptions
Consequences of ill-defined exposures
Under the identification assumptions, let’s connect the counterfactual outcome to the factual outcome
Unobservable causal estimand is reduced to observable statistical estimand
pacman::p_load(tidyverse, broom, tinytable, NHANES) # load packages
# Using regression
NHANES |> mutate(Race1 = factor(Race1, ordered = F) |>
relevel(Race1, ref = "White")) |>
filter(Race1 %in% c("Black","White")) |>
lm(formula = BMI~ Race1*Gender) |> tidy() |>
select(term, estimate) |>
tt() |>
format_tt(digits = 2)
# Manual pair-wise comparison
NHANES |> group_by(Race1, Gender) |>
summarize(mean = mean(BMI, na.rm = T)) |>
filter(Race1 %in% c("Black","White")) |>
tt(digits = 4)Using regression
| term | estimate |
|---|---|
| (Intercept) | 26.64 |
| Race1Black | 3.14 |
| Gendermale | 0.16 |
| Race1Black:Gendermale | -3.6 |
Race1Black: \(3.14\)
Manual pair-wise comparison
| Race1 | Gender | mean |
|---|---|---|
| Black | female | 29.78 |
| Black | male | 26.34 |
| White | female | 26.64 |
| White | male | 26.8 |
\(E[Y|A=2]\)
# Generate synthetic data for left plot
set.seed(123)
n1 <- 30
n2 <- 25
n3 <- 35
n4 <- 20
# Data for A=1
a1_data <- data.frame(
A = rep(1, n1),
Y = c(runif(10, 10, 30), runif(20, 12, 28))
)
# Data for A=2
a2_data <- data.frame(
A = rep(2, n2),
Y = c(runif(8, 20, 30), runif(17, 30, 38))
)
# Data for A=3
a3_data <- data.frame(
A = rep(3, n3),
Y = c(runif(15, 30, 50), runif(20, 45, 58))
)
# Data for A=4
a4_data <- data.frame(
A = rep(4, n4),
Y = c(runif(10, 40, 55), runif(10, 55, 63))
)
# Combine data
plot1_data <- rbind(a1_data, a2_data, a3_data, a4_data)
# Create plot
library(ggplot2)
ggplot(plot1_data, aes(x = A, y = Y)) +
geom_point(size = 2, alpha = 0.8) +
scale_x_continuous(breaks = 1:4, limits = c(0.5, 4.5)) +
scale_y_continuous(breaks = seq(10, 60, 10), limits = c(5, 65)) +
theme_minimal() +
theme(
axis.title = element_text(size = 18),
axis.text = element_text(size = 18),
plot.margin = margin(20, 20, 20, 20)
) +
labs(x = "A", y = "Y")mean.a2 <- mean(a2_data$Y)
# Create plot
ggplot(plot1_data, aes(x = A, y = Y)) +
geom_point(size = 2, alpha = 0.8) +
geom_point(size = 5, shape = 23, fill = "#be2f3a", aes(x = 2, y = mean.a2)) +
scale_x_continuous(breaks = 1:4, limits = c(0.5, 4.5)) +
scale_y_continuous(breaks = seq(10, 60, 10), limits = c(5, 65)) +
theme_minimal() +
theme(
axis.title = element_text(size = 18),
axis.text = element_text(size = 18),
plot.margin = margin(20, 20, 20, 20)
) +
labs(x = "A", y = "Y")\(E[Y|A=5]\)
# Generate synthetic data for right plot (more spread out)
set.seed(456)
# Create data with increasing trend
a_values <- runif(100, 0, 8)
y_values <- 2 + 4.5 * a_values + rnorm(100, 0, 3)
y_values <- pmax(y_values, -2) # Ensure no negative values too extreme
plot2_data <- data.frame(A = a_values, Y = y_values)
# Remove observations with A = 5 (within tolerance)
plot2_data <- plot2_data[abs(plot2_data$A - 5) > 1, ]
# Create plot
ggplot(plot2_data, aes(x = A, y = Y)) +
geom_point(size = 2, alpha = 0.8) +
scale_x_continuous(breaks = 0:8, limits = c(-0.5, 8.5)) +
scale_y_continuous(breaks = seq(0, 40, 10), limits = c(-5, 45)) +
theme_minimal() +
theme(
axis.title = element_text(size = 18),
axis.text = element_text(size = 18),
plot.margin = margin(20, 20, 20, 20)
) +
labs(x = "A", y = "Y")# Create plot
ggplot(plot2_data, aes(x = A, y = Y)) +
geom_point(size = 2, alpha = 0.8) +
geom_smooth(method = "lm", se = F, color = "#457b9d") +
geom_point(size = 5, shape = 23, fill = "#be2f3a", aes(x = 5, y = 25)) +
scale_x_continuous(breaks = 0:8, limits = c(-0.5, 8.5)) +
scale_y_continuous(breaks = seq(0, 40, 10), limits = c(-5, 45)) +
theme_minimal() +
theme(
axis.title = element_text(size = 18),
axis.text = element_text(size = 18),
plot.margin = margin(20, 20, 20, 20)
) +
labs(x = "A", y = "Y")You get meaningless “numbers” with:
Solutions to the bias-variance trade-off
Always distinguish these steps when you learn, read, and respond
Challenges
Claim: Move to the right of the proposed spectrum of social exposures
Alternative approaches for ill-defined social exposures
Possible interpretations
PH784 (Shiba) 2025/9/15
Social Epidemiologic Questions
We will discuss the intersection of these two in Week 5