library(tidyverse)
library(haven)
library(hrbrthemes)
library(survey)
library(srvyr)
library(labelled)
library(sjmisc)
library(sjPlot)
library(gmodels)
library(gtsummary)
library(skimr)
library(ggblanket)
Appendix F — Skill Assignment 6: Logistic Regression Analysis
Find the sample assignment here.
F.1 Overall Discussion
F.1.1 Load Packages
F.1.2 Load Your Dataset
Need help? Go to chapter x in the webbook.
load("another_anes_pilot_smaller_2.RData")
F.1.3 Manage your data as needed
Need help? Go to chapter x in the webbook.
F.1.4 Final Regression Model
Need help? Go to chapter 4 in the webbook.
<- glm(roe_recode ~ ideo5 + urbanicity2_recode + pew_religimp, data = another_anes_pilot_smaller_2, family = "binomial", weights = another_anes_pilot_smaller_2$weight)
roe_glm summary(roe_glm)
Call:
glm(formula = roe_recode ~ ideo5 + urbanicity2_recode + pew_religimp,
family = "binomial", data = another_anes_pilot_smaller_2,
weights = another_anes_pilot_smaller_2$weight)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.41299 0.34234 4.127 3.67e-05 ***
ideo5Liberal 0.09176 0.41695 0.220 0.826
ideo5Moderate -0.98755 0.34309 -2.878 0.004 **
ideo5Conservative -2.86078 0.35038 -8.165 3.22e-16 ***
ideo5Very conservative -3.48971 0.39194 -8.904 < 2e-16 ***
ideo5Not sure 0.25586 0.74398 0.344 0.731
urbanicity2_recodeSuburb -0.06706 0.20903 -0.321 0.748
urbanicity2_recodeRural -0.16370 0.21899 -0.747 0.455
pew_religimpSomewhat important 0.94584 0.20458 4.623 3.78e-06 ***
pew_religimpNot too important 1.54525 0.27888 5.541 3.01e-08 ***
pew_religimpNot at all important 1.47602 0.26265 5.620 1.91e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 1334.70 on 1055 degrees of freedom
Residual deviance: 873.07 on 1045 degrees of freedom
(79 observations deleted due to missingness)
AIC: 976.48
Number of Fisher Scoring iterations: 5
tbl_regression(roe_glm, exponentiate = TRUE) |>
add_glance_source_note(
include = c(AIC))
Characteristic | OR1 | 95% CI1 | p-value |
---|---|---|---|
Profile: Ideology | |||
Very liberal | — | — | |
Liberal | 1.10 | 0.48, 2.48 | 0.8 |
Moderate | 0.37 | 0.18, 0.71 | 0.004 |
Conservative | 0.06 | 0.03, 0.11 | <0.001 |
Very conservative | 0.03 | 0.01, 0.06 | <0.001 |
Not sure | 1.29 | 0.34, 6.99 | 0.7 |
Profile: Urban-rural status | |||
City | — | — | |
Suburb | 0.94 | 0.62, 1.41 | 0.7 |
Rural | 0.85 | 0.55, 1.31 | 0.5 |
Profile: Importance of religion (Pew version) | |||
Very important | — | — | |
Somewhat important | 2.57 | 1.73, 3.86 | <0.001 |
Not too important | 4.69 | 2.74, 8.21 | <0.001 |
Not at all important | 4.38 | 2.64, 7.40 | <0.001 |
AIC = 976 | |||
1 OR = Odds Ratio, CI = Confidence Interval |
tab_model(roe_glm)
Favor/oppose-overturn Roe v Wade |
|||
Predictors | Odds Ratios | CI | p |
(Intercept) | 4.11 | 2.17 – 8.37 | <0.001 |
Profile:Ideology: Liberal | 1.10 | 0.48 – 2.48 | 0.826 |
Profile:Ideology: Moderate |
0.37 | 0.18 – 0.71 | 0.004 |
Profile:Ideology: Conservative |
0.06 | 0.03 – 0.11 | <0.001 |
Profile:Ideology: Very conservative |
0.03 | 0.01 – 0.06 | <0.001 |
Profile:Ideology: Not sure |
1.29 | 0.34 – 6.99 | 0.731 |
Profile:Urban-rural status: Suburb |
0.94 | 0.62 – 1.41 | 0.748 |
Profile:Urban-rural status: Rural |
0.85 | 0.55 – 1.31 | 0.455 |
Profile:Importance of religion(Pew version): Somewhat important |
2.57 | 1.73 – 3.86 | <0.001 |
Profile:Importance of religion(Pew version): Not too important |
4.69 | 2.74 – 8.21 | <0.001 |
Profile:Importance of religion(Pew version): Not at all important |
4.38 | 2.64 – 7.40 | <0.001 |
Observations | 1056 | ||
R2 Tjur | 0.012 |
F.1.5 Save your updated dataset?
Need help? Go to chapter 4 in the webbook.