Appendix G — Skill Assignment 6: Linear Regression Analysis

Author

Methods Student

Published

November 13, 2024

Find Quarto themes here.

Find the sample assignment here.

G.1 Overall Discussion

G.1.1 Load Packages

library(tidyverse)
library(haven)
library(hrbrthemes)
library(survey)
library(srvyr)
library(labelled)
library(sjmisc)
library(sjPlot)
library(gmodels)
library(gtsummary)
library(skimr)
library(ggblanket)

G.1.2 Load Your Dataset

Need help? Go to chapter x in the webbook.

load("anes_pilot_small.RData")

G.1.3 Manage your data as needed

Need help? Go to chapter x in the webbook.

G.1.4 Final Regression Model

Need help? Go to chapter 4 in the webbook.

opinion_of_scotus <- lm(ftscotus ~ as_factor(ideo5) + as_factor(urbanicity2) + as_factor(pew_religimp), data = anes_pilot_small)
summary(opinion_of_scotus)

Call:
lm(formula = ftscotus ~ as_factor(ideo5) + as_factor(urbanicity2) + 
    as_factor(pew_religimp), data = anes_pilot_small)

Residuals:
    Min      1Q  Median      3Q     Max 
-71.159 -16.889   1.078  17.119  61.433 

Coefficients:
                                            Estimate Std. Error t value
(Intercept)                                   43.121      2.498  17.264
as_factor(ideo5)Liberal                        3.173      2.490   1.274
as_factor(ideo5)Moderate                      16.291      2.273   7.167
as_factor(ideo5)Conservative                  30.636      2.473  12.386
as_factor(ideo5)Very conservative             32.782      2.781  11.786
as_factor(ideo5)Not sure                      12.380      2.893   4.280
as_factor(urbanicity2)Smaller city            -4.743      2.133  -2.223
as_factor(urbanicity2)Suburban area           -4.872      1.773  -2.747
as_factor(urbanicity2)Small town              -2.652      2.256  -1.175
as_factor(urbanicity2)Rural area              -2.952      2.096  -1.409
as_factor(pew_religimp)Somewhat important     -5.885      1.644  -3.579
as_factor(pew_religimp)Not too important     -10.765      2.033  -5.295
as_factor(pew_religimp)Not at all important  -15.682      1.811  -8.660
                                            Pr(>|t|)    
(Intercept)                                  < 2e-16 ***
as_factor(ideo5)Liberal                     0.202734    
as_factor(ideo5)Moderate                    1.17e-12 ***
as_factor(ideo5)Conservative                 < 2e-16 ***
as_factor(ideo5)Very conservative            < 2e-16 ***
as_factor(ideo5)Not sure                    1.98e-05 ***
as_factor(urbanicity2)Smaller city          0.026327 *  
as_factor(urbanicity2)Suburban area         0.006080 ** 
as_factor(urbanicity2)Small town            0.240005    
as_factor(urbanicity2)Rural area            0.159091    
as_factor(pew_religimp)Somewhat important   0.000355 ***
as_factor(pew_religimp)Not too important    1.36e-07 ***
as_factor(pew_religimp)Not at all important  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 24.9 on 1571 degrees of freedom
  (1 observation deleted due to missingness)
Multiple R-squared:  0.2712,    Adjusted R-squared:  0.2657 
F-statistic: 48.73 on 12 and 1571 DF,  p-value: < 2.2e-16
tbl_regression(opinion_of_scotus) |>
  add_glance_source_note()
Characteristic Beta 95% CI1 p-value
Profile: Ideology


    Very liberal
    Liberal 3.2 -1.7, 8.1 0.2
    Moderate 16 12, 21 <0.001
    Conservative 31 26, 35 <0.001
    Very conservative 33 27, 38 <0.001
    Not sure 12 6.7, 18 <0.001
Profile: Urban-rural status


    Big city
    Smaller city -4.7 -8.9, -0.56 0.026
    Suburban area -4.9 -8.3, -1.4 0.006
    Small town -2.7 -7.1, 1.8 0.2
    Rural area -3.0 -7.1, 1.2 0.2
Profile: Importance of religion (Pew version)


    Very important
    Somewhat important -5.9 -9.1, -2.7 <0.001
    Not too important -11 -15, -6.8 <0.001
    Not at all important -16 -19, -12 <0.001
R² = 0.271; Adjusted R² = 0.266; Sigma = 24.9; Statistic = 48.7; p-value = <0.001; df = 12; Log-likelihood = -7,334; AIC = 14,695; BIC = 14,770; Deviance = 974,245; Residual df = 1,571; No. Obs. = 1,584
1 CI = Confidence Interval
tab_model(opinion_of_scotus)
  ftscotus
Predictors Estimates CI p
(Intercept) 43.12 38.22 – 48.02 <0.001
as_factor(ideo5)Liberal 3.17 -1.71 – 8.06 0.203
as_factor(ideo5)Moderate 16.29 11.83 – 20.75 <0.001
as_factor(ideo5)Conservative 30.64 25.78 – 35.49 <0.001
as_factor(ideo5)Very conservative 32.78 27.33 – 38.24 <0.001
as_factor(ideo5)Not sure 12.38 6.71 – 18.05 <0.001
as_factor(urbanicity2)Smaller city -4.74 -8.93 – -0.56 0.026
as_factor(urbanicity2)Suburban area -4.87 -8.35 – -1.39 0.006
as_factor(urbanicity2)Small town -2.65 -7.08 – 1.77 0.240
as_factor(urbanicity2)Rural area -2.95 -7.06 – 1.16 0.159
as_factor(pew_religimp)Somewhat important -5.88 -9.11 – -2.66 <0.001
as_factor(pew_religimp)Not too important -10.77 -14.75 – -6.78 <0.001
as_factor(pew_religimp)Not at all important -15.68 -19.23 – -12.13 <0.001
Observations 1584
R2 / R2 adjusted 0.271 / 0.266

G.1.5 Save your updated dataset?

Need help? Go to chapter 4 in the webbook.