Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized linear regression #896

Merged
merged 34 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8df1ed4
notes from glm workshop
rosemm Jul 19, 2023
8f46bb3
Flesh out explanation of continuous and unbounded, and add box on pro…
rosemm Jul 28, 2023
a7f4608
Update metadata, add quick review of linear models
rosemm Dec 7, 2023
7f51f87
Flesh out linear models review
rosemm Dec 8, 2023
4c68c8a
Start example with code
rosemm Feb 16, 2024
ec50c60
Finish example
rosemm Feb 16, 2024
06187ae
Add R code used in module and missing image file
rosemm Feb 16, 2024
8e2405d
Put in metadata, improve quiz questions
rosemm Feb 16, 2024
8058d86
Add missing metadata
rosemm Feb 16, 2024
7332b12
Correct version number after super handy autochecker caught my mistake!
rosemm Feb 16, 2024
47a9826
Update data example to sepsis
rosemm Mar 21, 2024
8a6f6ba
Replace example data
rosemm Mar 22, 2024
1d01d94
Reordering sections for improved flow (hopefully!)
rosemm Mar 25, 2024
7d562e7
Reorder generalized linear regression (#914)
drelliche Mar 26, 2024
af09c26
Rearrange example content and add quiz on outcome variables
rosemm Apr 1, 2024
eb865a0
Add brief explanation of terms in linear model
rosemm Apr 1, 2024
51a30df
Add more explanation before linear model sepsis example
rosemm Apr 1, 2024
6a420f8
Rework "probability and odds" section as "talking about chance", reor…
rosemm Apr 1, 2024
10aaf40
improve hyperlink text
rosemm Apr 8, 2024
8f40826
Improve hyperlink text
rosemm Apr 8, 2024
0318109
Tweaking punctuation for clarity
rosemm Apr 11, 2024
d4d4555
Tweaking punctuation for clarity
rosemm Apr 11, 2024
803573f
Tweaking wording for clarity
rosemm Apr 11, 2024
304c6c7
Tweaking wording for clarity
rosemm Apr 11, 2024
95b05e7
Tweaking wording for clarity
rosemm Apr 11, 2024
2f7f1ef
Tweaking punctuation for clarity
rosemm Apr 11, 2024
8eea87c
Clarifying
rosemm Apr 11, 2024
83a2eef
Improve quiz answer
rosemm Apr 11, 2024
1cb4250
Tweaking punctuation for clarity
rosemm Apr 11, 2024
135eb01
Tweaking wording for clarity
rosemm Apr 11, 2024
ac5bba3
Tweaking punctuation for clarity
rosemm Apr 11, 2024
d96b369
clarify convergence
franzenr Apr 11, 2024
1e2c779
update answser explanation for clarity
franzenr Apr 12, 2024
3b097d0
Merge branch 'main' into generalized_linear_regression
rosemm Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions generalized_linear_regression/example_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# show the relationship between probability, odds, and logits
logit_demo <- data.frame(Logit = c(-Inf, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, Inf)) |>
mutate(Odds = exp(Logit),
Probability = ifelse(Odds < Inf, Odds / (1 + Odds), 1))
knitr::kable(logit_demo, digits = 3)

library(tidyverse)
# set the random seed so results replicate exactly with the random number generators
set.seed(24601)

# sample size
n <- 100

# random sampling of 0 and 1 for trisomy_21_dx
# sample from a normal distribution for BPD/FL, but use a higher mean if trisomy_21_dx == 1
data <- data.frame(trisomy_21_dx = sample(x = c(0,0,0,1),
size = n,
replace = TRUE)) |>
mutate(`BPD/FL` = ifelse(trisomy_21_dx == 1,
rnorm(n, mean = 1.6, sd = .2),
rnorm(n, mean = 1.5, sd = .2)))


base_plot <- ggplot(data, aes(y=trisomy_21_dx, x=`BPD/FL`)) +
geom_point() +
theme_bw() +
labs(y = "Trisomy 21 Dx")

# try plotting the data with just a linear model
base_plot +
stat_smooth(method = "lm")
ggsave("linear_prediction.png", width = 5, height = 5, units = "in")

base_plot +
stat_smooth(method = "glm", method.args = list(family = "binomial"))
ggsave("logit_prediction.png", width = 5, height = 5, units = "in")



Loading
Loading