Created
September 24, 2025 10:22
-
-
Save carlislerainey/507332fe1f30ea097f3513ad2d195404 to your computer and use it in GitHub Desktop.
Illustrating {marginaleffects} with turnout
This file contains hidden or 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
| # load packages | |
| library(tidyverse) | |
| library(marginaleffects) | |
| # data | |
| devtools::install_github("jrnold/ZeligData") | |
| turnout <- ZeligData::turnout | |
| # fit model | |
| f <- vote ~ age + educate + income + race | |
| fit <- glm(f, family = binomial, data = turnout) | |
| # ev as age ranges from 18 to 90; others at mean/mode | |
| predictions(fit, datagrid(age = 18:90)) | |
| # fd as age moves across iqr; others at every observed value | |
| comparisons(fit, variables = list(age = "iqr")) | |
| # avg of the fds above | |
| avg_comparisons(fit, variables = list(age = "iqr")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment