Created
October 11, 2022 15:10
-
-
Save andrewheiss/c96c5a6da8d81d276d32a98a37bca5ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(patchwork) | |
library(latex2exp) | |
logit_df <- tibble(x = seq(0, 100, length.out = 101), | |
logits = seq(-4, 4, length.out = 101)) |> | |
mutate(odds = exp(logits)) |> | |
mutate(probs = plogis(logits)) | |
p1 <- ggplot(logit_df, aes(x = x, y = probs)) + | |
geom_line(size = 1, color = "darkred") + | |
labs(title = "Probabilities", | |
subtitle = "Can't be modeled linearly; too curvy and bound between 0–1", | |
x = NULL, | |
y = TeX("$\\pi$")) + | |
theme_minimal() + | |
theme(plot.title = element_text(face = "bold"), | |
axis.title.y = element_text(angle = 0, hjust = 0), | |
panel.grid.minor = element_blank()) | |
p2 <- ggplot(logit_df, aes(x = x, y = odds)) + | |
geom_line(size = 1, color = "goldenrod") + | |
labs(title = "Odds", | |
subtitle = "No longer bound between 0–1, but still too curvy for linear models", | |
x = NULL, | |
y = TeX("$\\frac{\\pi}{1 - \\pi}$")) + | |
theme_minimal() + | |
theme(plot.title = element_text(face = "bold"), | |
axis.title.y = element_text(angle = 0, hjust = 0), | |
panel.grid.minor = element_blank()) | |
p3 <- ggplot(logit_df, aes(x = x, y = logits)) + | |
geom_line(size = 1, color = "dodgerblue") + | |
labs(title = "Log odds (logits)", | |
subtitle = "Linear models are comfy and happy here", | |
x = NULL, | |
y = TeX("$log \\left( \\frac{\\pi}{1 - \\pi} \\right)$")) + | |
theme_minimal() + | |
theme(plot.title = element_text(face = "bold"), | |
axis.title.y = element_text(angle = 0, hjust = 0), | |
panel.grid.minor = element_blank()) | |
p1 / p2 / p3 | |
ggsave("~/logit.png", width = 6, height = 7, dpi = 600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment