# 7.1.m & 7.1.n - Log odds diff =/= diff in probabilities
# 7.1.m: three equal +.10 changes in probability, shown as odds and log-odds
pp <- data.frame(p0 = c(.05, .45, .85), p1 = c(.15, .55, .95))
podds <- "How odds change for + 0.10 increase in probability"
plo <- "How log-odds change for a + 0.10 increase in probability"
curves <- bind_rows(
data.frame(panel = podds, p = seq(0, .95, .005)) |> mutate(y = p / (1 - p)),
data.frame(panel = plo, p = seq(.01, .99, .005)) |> mutate(y = qlogis(p)))
steps <- bind_rows(
pp |> mutate(panel = podds, y0 = p0 / (1 - p0), y1 = p1 / (1 - p1)),
pp |> mutate(panel = plo, y0 = qlogis(p0), y1 = qlogis(p1))) |>
mutate(label = sprintf("+%4.2f", y1 - y0))
curves$panel <- factor(curves$panel, levels = c(podds, plo))
steps$panel <- factor(steps$panel, levels = c(podds, plo))
ggplot() +
geom_line(data = curves, aes(x = p, y = y), color = "red") +
geom_segment(data = steps, aes(x = p0, xend = p1, y = y0, yend = y0),
color = "steelblue", linetype = "dashed") +
geom_segment(data = steps, aes(x = p1, xend = p1, y = y0, yend = y1),
color = "steelblue", linewidth = 1.2) +
geom_point(data = steps, aes(x = p0, y = y0), color = "steelblue") +
geom_point(data = steps, aes(x = p1, y = y1), color = "steelblue") +
geom_text(data = steps, aes(x = p1, y = y1, label = label), color = "steelblue",
hjust = 1.1, vjust = -.4, size = 3) +
facet_wrap(~ panel, scales = "free_y", labeller = label_wrap_gen(35)) +
scale_x_continuous(breaks = seq(0, 1, .2)) +
labs(title = "[7.1.m] Change in log odds / odds does not equal change in probability",
caption = "Each blue triangle is the same +.10 change in probability.",
x = "Probability", y = "Odds (left) and log-odds (right)")