Created
April 20, 2024 10:03
-
-
Save carlislerainey/2bd0b8d0d80df2a3d1a0b25d1281dc2b to your computer and use it in GitHub Desktop.
Code to illustrate separation
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
# load packages | |
library(modelsummary) | |
# get latest version of {crdata} package, if updated | |
remotes::install_github("carlislerainey/crdata") | |
# load (and slightly wrangle) data from Barrilleaux and Rainey (2014) | |
br <- crdata::br2014 %>% | |
# recode from centered GOP gov. indicator to 0/1 Dem. gov. indicator | |
# (explanatory variables are centered about mean) | |
mutate(dem_governor = 1*(gop_governor < 0)) | |
# formula to reproduce Figure 2 on p. 446 of Barrilleaux and Rainey (2014). | |
# (I changed the GOP gov. indicator to a Dem. gov. indicator) | |
f <- oppose_expansion ~ dem_governor + percent_favorable_aca + gop_leg + | |
percent_uninsured + bal2012 + multiplier + percent_nonwhite + percent_metro | |
# logit model with separation (default precision) | |
fit <- glm(f, data = br, family = binomial) | |
# logit model with separation (default precision) | |
fit_maxprec <- glm(f, data = br, family = binomial, | |
control = glm.control(maxit = 1000, | |
epsilon = .Machine$double.eps)) | |
# make a table! | |
modelsummary(list("Default Precision" = fit, | |
"Max. Precision" = fit_maxprec), | |
shape = term ~ model + statistic, | |
fmt = fmt_sprintf("%.1f")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment