Assignment 3 - Binomial and Ordered Models

Author

Jingyi Yang

library(haven)
library(ggplot2) #Graphical display of results
library(ggeffects) #Calculates predicted values and probabilities from regression models
Warning: package 'ggeffects' was built under R version 4.4.3
library(tidyverse) #General coding language
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ lubridate 1.9.3     ✔ tibble    3.2.1
✔ purrr     1.0.2     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(stargazer) #Display regression tables 

Please cite as: 

 Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.3. https://CRAN.R-project.org/package=stargazer 
library(caret) #Confusion matrix
Warning: package 'caret' was built under R version 4.4.3
Loading required package: lattice

Attaching package: 'caret'

The following object is masked from 'package:purrr':

    lift
library(jtools) #Display regression tables & does other calculations on our regression output
Warning: package 'jtools' was built under R version 4.4.3
library(janitor) #Cleans variable names in our dataset 

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(descr)  #Efficient approach to calculating frequency tables for individual variables
Warning: package 'descr' was built under R version 4.4.3

Attaching package: 'descr'

The following object is masked from 'package:janitor':

    crosstab
library (skimr) #Efficient approach to looking at means, variance and distribution for a set of data
library(patchwork) #Merge GGPlots together 
library(stats) #Imports survey data
library(nnet) #For multinomial models
library(MASS) #For ordered models 

Attaching package: 'MASS'

The following object is masked from 'package:patchwork':

    area

The following object is masked from 'package:dplyr':

    select
library(brant) #Test parallel regression assumption 
Warning: package 'brant' was built under R version 4.4.3
library(boot) #Create CIs for Multinomial Modeling

Attaching package: 'boot'

The following object is masked from 'package:lattice':

    melanoma
anes<- read_dta("C:/Users/Admin/Downloads/anes2020_with_validated_vote.dta")
head(anes)
# A tibble: 6 × 1,508
  version      V200001 V160001_orig V200002  V200003  V200004  V200005  V200010a
  <chr>          <dbl> <dbl+lbl>    <dbl+lb> <dbl+lb> <dbl+lb> <dbl+lb>    <dbl>
1 "ANES2020Ti…  209586 300001        3 [3. …  2 [2. … -2 [-2.…  0 [0. …    0.925
2 "ANES2020Ti…  211206 300002        3 [3. …  2 [2. … -2 [-2.…  0 [0. …    0.906
3 ""                NA 300003       NA       NA       NA       NA         NA    
4 "ANES2020Ti…  233169 300004        3 [3. …  2 [2. … -2 [-2.…  0 [0. …    0.453
5 "ANES2020Ti…  203670 300006        3 [3. …  2 [2. … -2 [-2.…  0 [0. …    0.762
6 ""                NA 300007       NA       NA       NA       NA         NA    
# ℹ 1,500 more variables: weight_full <dbl>, V200010c <dbl>, V200010d <dbl>,
#   V200011a <dbl>, V200011b <dbl>, V200011c <dbl>, V200011d <dbl>,
#   V200012a <dbl>, V200012b <dbl>, V200012c <dbl>, V200012d <dbl>,
#   V200013a <dbl>, V200013b <dbl>, V200013c <dbl>, V200013d <dbl>,
#   V200014a <dbl>, V200014b <dbl>, V200014c <dbl>, V200014d <dbl>,
#   V200015a <dbl>, V200015b <dbl>, V200015c <dbl>, V200015d <dbl>,
#   V200016a <dbl>, V200016b <dbl>, V200016c <dbl>, V200016d <dbl>, …

Part 1: Binary Modeling

Data Prepare

  • Select the variables and rename the column.
anes_vv<-anes %>% filter(vv_20==0)%>% dplyr::select( c(V202109x,party_str, education, pol_int, income, ideo_str, female, poc, martial_status, age_group))
head(anes_vv)
# A tibble: 6 × 10
  V202109x            party_str education pol_int income  ideo_str female    poc
  <dbl+lbl>           <dbl+lbl> <dbl+lbl> <dbl+l> <dbl+l> <dbl+lb> <dbl+l> <dbl>
1 0 [0. Did not vote] 1 [Leani… 2 [Some … 3 [som… 4 [75-… 1 [Lean… 1 [1. …     0
2 1 [1. Voted]        1 [Leani… 2 [Some … 3 [som… 5 [100… 1 [Lean… 2 [2. …     0
3 0 [0. Did not vote] 2 [Weak … 1 [HS or… 3 [som… 1 [<25… 1 [Lean… 1 [1. …     1
4 0 [0. Did not vote] 0 [Indep… 2 [Some … 2 [not… 4 [75-… 1 [Lean… 2 [2. …     1
5 1 [1. Voted]        1 [Leani… 1 [HS or… 3 [som… 1 [<25… 0 [Mode… 2 [2. …     1
6 1 [1. Voted]        3 [Stron… 1 [HS or… 2 [not… 2 [25-… 1 [Lean… 2 [2. …     1
# ℹ 2 more variables: martial_status <dbl+lbl>, age_group <dbl+lbl>
# Update column names

new_names <- c("report_vote", "political_party", "education","interested_in_politics", "income", "strength_of_ideological_commitmen", "female", "person_of_color_or_not", "marital_status","age_group") #Give your variables new informative names 

colnames(anes_vv) <- new_names 
skim(anes_vv)
Data summary
Name anes_vv
Number of rows 583
Number of columns 10
_______________________
Column type frequency:
numeric 10
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
report_vote 50 0.91 0.50 0.50 0 0 0 1 1 ▇▁▁▁▇
political_party 1 1.00 1.72 1.14 0 1 2 3 3 ▅▅▁▆▇
education 7 0.99 2.13 1.01 1 1 2 3 4 ▇▇▁▃▃
interested_in_politics 56 0.90 2.61 0.93 1 2 3 3 4 ▃▅▁▇▃
income 35 0.94 2.81 1.59 1 1 3 4 6 ▇▃▂▂▁
strength_of_ideological_commitmen 14 0.98 1.13 0.90 0 0 1 2 3 ▅▇▁▃▂
female 6 0.99 1.53 0.50 1 1 2 2 2 ▇▁▁▁▇
person_of_color_or_not 6 0.99 0.39 0.49 0 0 0 1 1 ▇▁▁▁▅
marital_status 4 0.99 1.07 0.85 0 0 1 2 2 ▆▁▆▁▇
age_group 18 0.97 3.11 1.37 1 2 3 4 5 ▅▆▅▇▆

Model Building:define hypothesis & control variables

The hypothesis for all three primary independent variables would be: - The level of respondents’ identity with a political party will lead to an increase in the chance they reported voting. - The degree of respondents’ educational attainment will lead to an increase in the chance they reported voting. - The level of respondents’ interest in politics will lead to an increase in the chance they reported voting.

The control variables:

I chose two variables, person of color or not and biological Sex, as control variables because they are dichotomous demographic variables.

logit <- glm(report_vote ~ factor(political_party)+factor(education)+ factor(interested_in_politics)+female+person_of_color_or_not, data =anes_vv, family = binomial(link = "logit"))
summary(logit)

Call:
glm(formula = report_vote ~ factor(political_party) + factor(education) + 
    factor(interested_in_politics) + female + person_of_color_or_not, 
    family = binomial(link = "logit"), data = anes_vv)

Coefficients:
                                Estimate Std. Error z value Pr(>|z|)    
(Intercept)                      -2.7305     0.5059  -5.397 6.77e-08 ***
factor(political_party)1          0.6319     0.3138   2.014  0.04399 *  
factor(political_party)2          0.4025     0.3067   1.312  0.18936    
factor(political_party)3          1.3377     0.2908   4.600 4.22e-06 ***
factor(education)2                0.3130     0.2437   1.284  0.19900    
factor(education)3                0.7880     0.3079   2.560  0.01048 *  
factor(education)4                0.6715     0.3220   2.086  0.03701 *  
factor(interested_in_politics)2   1.4301     0.3832   3.732  0.00019 ***
factor(interested_in_politics)3   1.7580     0.3626   4.849 1.24e-06 ***
factor(interested_in_politics)4   2.3531     0.4340   5.421 5.91e-08 ***
female                            0.1245     0.1989   0.626  0.53158    
person_of_color_or_not           -0.1945     0.2038  -0.954  0.33985    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 711.07  on 512  degrees of freedom
Residual deviance: 603.62  on 501  degrees of freedom
  (70 observations deleted due to missingness)
AIC: 627.62

Number of Fisher Scoring iterations: 4
probit <- glm(report_vote ~ factor(political_party)+factor(education)+ factor(interested_in_politics)+female+person_of_color_or_not, data =anes_vv, family = binomial(link = "probit"))
summary(probit)

Call:
glm(formula = report_vote ~ factor(political_party) + factor(education) + 
    factor(interested_in_politics) + female + person_of_color_or_not, 
    family = binomial(link = "probit"), data = anes_vv)

Coefficients:
                                Estimate Std. Error z value Pr(>|z|)    
(Intercept)                     -1.59966    0.28794  -5.555 2.77e-08 ***
factor(political_party)1         0.37234    0.18911   1.969  0.04897 *  
factor(political_party)2         0.21992    0.18338   1.199  0.23044    
factor(political_party)3         0.79491    0.17336   4.585 4.53e-06 ***
factor(education)2               0.19404    0.14672   1.323  0.18599    
factor(education)3               0.47964    0.18498   2.593  0.00952 ** 
factor(education)4               0.41647    0.19392   2.148  0.03175 *  
factor(interested_in_politics)2  0.81854    0.21494   3.808  0.00014 ***
factor(interested_in_politics)3  1.02532    0.20175   5.082 3.73e-07 ***
factor(interested_in_politics)4  1.38358    0.24578   5.629 1.81e-08 ***
female                           0.07464    0.11972   0.624  0.53295    
person_of_color_or_not          -0.12250    0.12266  -0.999  0.31794    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 711.07  on 512  degrees of freedom
Residual deviance: 604.16  on 501  degrees of freedom
  (70 observations deleted due to missingness)
AIC: 628.16

Number of Fisher Scoring iterations: 4
ols <- glm(report_vote ~ factor(political_party)+factor(education)+ factor(interested_in_politics)+female+person_of_color_or_not, data =anes_vv, family = gaussian(link = "identity"))
summary(ols)

Call:
glm(formula = report_vote ~ factor(political_party) + factor(education) + 
    factor(interested_in_politics) + female + person_of_color_or_not, 
    family = gaussian(link = "identity"), data = anes_vv)

Coefficients:
                                Estimate Std. Error t value Pr(>|t|)    
(Intercept)                     -0.03067    0.08969  -0.342 0.732516    
factor(political_party)1         0.13194    0.06442   2.048 0.041075 *  
factor(political_party)2         0.07586    0.06130   1.238 0.216455    
factor(political_party)3         0.28194    0.05836   4.831 1.81e-06 ***
factor(education)2               0.06553    0.04974   1.317 0.188284    
factor(education)3               0.16680    0.06292   2.651 0.008279 ** 
factor(education)4               0.14220    0.06614   2.150 0.032052 *  
factor(interested_in_politics)2  0.25207    0.06650   3.790 0.000169 ***
factor(interested_in_politics)3  0.33251    0.06184   5.377 1.17e-07 ***
factor(interested_in_politics)4  0.45696    0.07751   5.895 6.88e-09 ***
female                           0.02697    0.04061   0.664 0.506914    
person_of_color_or_not          -0.04260    0.04163  -1.023 0.306654    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 0.207255)

    Null deviance: 128.23  on 512  degrees of freedom
Residual deviance: 103.83  on 501  degrees of freedom
  (70 observations deleted due to missingness)
AIC: 662.33

Number of Fisher Scoring iterations: 2

Display and interpret the results

export_summs(ols, logit, probit, type="text", digits=3,model.names = c("Normal: Respondent reported they voted or not", "Logit: Respondent reported they voted or not", "Probit: Respondent reported they voted or not"), coefs=c("Intercept" = "(Intercept)", "party_str:Leaning Partisan" = "factor(political_party)1", "party_str:Weak Partisan" = "factor(political_party)2", "party_str: Strong Partisan" = "factor(political_party)3", "educ:Some College" = "factor(education)2", "educ: Bachelor’s" = "factor(education)3", "educ:Advanced" = "factor(education)4", "pol_int:Not very interested" = "factor(interested_in_politics)2", "pol_int:Somewhat interested" = "factor(interested_in_politics)3", "pol_int:Very interested" = "factor(interested_in_politics)4", "Female"="female", "Person of color or not"="person_of_color_or_not") , quiet = TRUE)
Normal: Respondent reported they voted or notLogit: Respondent reported they voted or notProbit: Respondent reported they voted or not
Intercept-0.031    -2.730 ***-1.600 ***
(0.090)   (0.506)   (0.288)   
party_str:Leaning Partisan0.132 *  0.632 *  0.372 *  
(0.064)   (0.314)   (0.189)   
party_str:Weak Partisan0.076    0.402    0.220    
(0.061)   (0.307)   (0.183)   
party_str: Strong Partisan0.282 ***1.338 ***0.795 ***
(0.058)   (0.291)   (0.173)   
educ:Some College0.066    0.313    0.194    
(0.050)   (0.244)   (0.147)   
educ: Bachelor’s0.167 ** 0.788 *  0.480 ** 
(0.063)   (0.308)   (0.185)   
educ:Advanced0.142 *  0.672 *  0.416 *  
(0.066)   (0.322)   (0.194)   
pol_int:Not very interested0.252 ***1.430 ***0.819 ***
(0.067)   (0.383)   (0.215)   
pol_int:Somewhat interested0.333 ***1.758 ***1.025 ***
(0.062)   (0.363)   (0.202)   
pol_int:Very interested0.457 ***2.353 ***1.384 ***
(0.078)   (0.434)   (0.246)   
Female0.027    0.124    0.075    
(0.041)   (0.199)   (0.120)   
Person of color or not-0.043    -0.195    -0.123    
(0.042)   (0.204)   (0.123)   
N513        513        513        
AIC662.326    627.621    628.163    
BIC717.450    678.504    679.047    
Pseudo R20.248    0.252    0.251    
*** p < 0.001; ** p < 0.01; * p < 0.05.
pp_1 <- ggpredict(logit, terms = "political_party",
                   condition = c(person_of_color_or_not = "1", 
                     female = "1"))
pp_1 
# Predicted probabilities of PRE-POST: SUMMARY: Voter turnout in 2020

political_party | Predicted |     95% CI
----------------------------------------
              0 |      0.06 | 0.03, 0.13
              1 |      0.10 | 0.04, 0.22
              2 |      0.08 | 0.04, 0.18
              3 |      0.19 | 0.09, 0.35

Adjusted for:
*              education = 1
* interested_in_politics = 1
pp_2 <- ggpredict(logit, terms = "education",
                   condition = c(person_of_color_or_not = "1", 
                     female = "1"))
pp_2
# Predicted probabilities of PRE-POST: SUMMARY: Voter turnout in 2020

education | Predicted |     95% CI
----------------------------------
        1 |      0.06 | 0.03, 0.13
        2 |      0.08 | 0.03, 0.16
        3 |      0.12 | 0.05, 0.26
        4 |      0.11 | 0.04, 0.24

Adjusted for:
*        political_party = 0
* interested_in_politics = 1
pp_3 <- ggpredict(logit, terms = "interested_in_politics",
                   condition = c(person_of_color_or_not = "1", 
                     female = "1"))
graphic_function <- function (z) {ggplot(z, aes(x = x)) +
  geom_line(aes(y = predicted, color = group), linewidth = .75) +
   geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.05) +
  labs(y = "Predicted Value of Y") +  # Update y-axis label here
  theme_minimal()}

graphic_pp_1<- graphic_function(pp_1)+  
  labs (x="An individual's identification with a political party", color="An individual's \n identification with \n a political party" ,title = "Predicted Probability with Confidence Intervals", subtitle = "Factors set to Female and Person of color or not")+
  scale_x_continuous(labels= c("0"= "Independent", "1"= "Leaning Partisan", "2"= "Weak Partisan", "3"= "Strong Partisan"))+
  scale_color_manual(values = c("1"= "darkred") ,labels = c("1"="party_str"))
  
graphic_pp_1

graphic_pp_2 <- graphic_function(pp_2)+
  labs (x="Educational Attainment For The Responden", color="Education" ,title = "Predicted Probability with Confidence Intervals", subtitle = "Factors set to Female and Person of color or not")+
  scale_x_continuous(labels= c("1"= "HS or less", "2"= "Some College", "3"= "Bachelor’s", "4"= "Advanced"))+
  scale_color_manual(values = c("1"= "darkgreen") ,labels = c("1"="education"))
  
graphic_pp_2

graphic_pp_3 <- graphic_function(pp_3)+
    labs (x="Respondent's politics interested in politics", color="Respondent's politics \n interested in politics" ,title = "Predicted Probability with Confidence Intervals", subtitle = "Factors set to Female and Person of color or not")+
  scale_x_continuous(labels= c("1"= "Not al all interested", "2"= "Not very interested", "3"= "Somewhat interested", "4"= "Very interested"))+
  scale_color_manual(values = c("1"= "orange") ,labels = c("1"="pol_int"))

graphic_pp_3

The Logit model has lower AIC and BIC numbers compared to linear and probit models. Regarding the Pseudo R-squared, the Logit model has higher numbers compared to the linear and probit model. Accordingly, the Logit model will be a better fit with the dataset.

Interpretation: In the logit model, the coefficient values indicate the logged odds. Below, we show the factors significantly related to whether respondents reported voting in the survey.

  1. Compared to “Independent” and holding other variables constant, the “Leaning Partisan” factor in variables that measure how closely a person identifies with a political party, at its steepest slope, increase one unit is equal to a 0.632 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means that people with leaning partisan identification are more likely to lie about voting than those independent identification.
  2. Compared to “Independent” and holding other variables constant, the “Strong Partisan” factor in variables that measure how closely a person identifies with a political party”, at its steepest slope, an increase of one unit is equal to a 1.338 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means that people with strong partisan identification are more likely to lie about voting than those independent identification.
  3. Compared to “HS or less” and holding other variables constant, the “Bachelor’s” factor in variables that measure educational attainment for the respondent, at its steepest slope, an increase of one unit is equal to a 0.788 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means people with Bachelor’s degrees are more likely to lie about voting than those with “HS or less.”
  4. Compared to “HS or less” and holding other variables constant, the “Advanced” factor in variables that measure educational attainment for the respondent, at its steepest slope, increase one unit is equal to a 0.672 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means those with an “Advanced” education degree (Master’s or higher) are more likely to lie about voting than those with “HS or less.”
  5. Compared to “Not at all interested” and holding other variables constant, the “Not very interested” factor in variables that measure how interested in politics a respondent is, at its steepest slope, increase one unit is equal to a 1.430 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means that people who are not very interested in politics are more likely to lie about voting than those who are “Not at all interested.”
  6. Compared to “Not at all interested” and holding other variables constant, the “Somewhat interested” factor in variables that measure how interested in politics a respondent is, at its steepest slope, increase one unit is equal to a 1.758 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means the people who are somewhat interested in politics are more likely to lie about voting than those who are“Not at all interested.”
  7. Compared to “Not at all interested” and holding other variables constant, the “Very interested” factor in variables that measure how interested in politics a respondent is, at its steepest slope, increase one unit is equal to a 2.353 logged odds increase in the variable analysis if respondents reported they voted or not. This outcome means the people who are very interested in politics are more likely to lie about voting than those who are “Not at all interested.”

A brief description of why:

Thus, certain factors in variables measure how closely a person identifies with a political party and the educational attainment of the respondent, and all factors in variables measure respondents’ interest in politics are statistically significantly related to misrepresenting voting.

For the variable related to a political party and interest in politics, people who have strong ideological beliefs are more active and prefer to speak out and participate in every level of the political process. The people at the middle of the range are likely to stay distant and disengaged about politics. For people who are earning college degrees or higher are more likely to vote because the university creates a great environment provoking registration to vote. For instance, at Umass, there are many activities being held and propaganda messages being sent out to encourage students to vote and provide guidelines and support. Thus, to fit the trend, some people who might not vote will say they vote.

Part 2: Ordered Regression Model

Data Prepare

anes_marriage<- anes %>% dplyr::select(V201416,pid_x,V201433,libcon,female,poc) 

anes_marriage <- anes_marriage %>% 
  mutate(V201433 = case_when(
   V201433 ==5 ~ 1,
   V201433 ==4 ~ 2,
   V201433 ==3 ~ 3,
   V201433 ==4 ~ 2,
   V201433 ==5 ~ 1,
   V201433 == -8 ~ NA_real_,
   V201433 == -9 ~ NA_real_),
   V201433 = labelled(V201433, c(`N/A`= 0, `Not important at all` = 1, `A little important` = 2, `Moderately important` = 3, `Very important` = 4, `Extremely important`=5)))

new_names <- c("position_on_gay_marriage", "partisan_identification", "importance_of_religion", "strength_of_ideological_identification", "female", "person_of_color_or_not") #Give your variables new informative names 

colnames(anes_marriage) <- new_names 

skim(anes_marriage) 
Data summary
Name anes_marriage
Number of rows 3735
Number of columns 6
_______________________
Column type frequency:
numeric 6
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
position_on_gay_marriage 943 0.75 1.48 0.73 1 1 1 2 3 ▇▁▂▁▂
partisan_identification 897 0.76 3.91 2.29 1 2 4 6 7 ▇▂▂▂▇
importance_of_religion 2237 0.40 2.01 0.87 1 1 2 3 3 ▇▁▅▁▇
strength_of_ideological_identification 918 0.75 4.17 1.63 1 3 4 6 7 ▆▅▆▆▇
female 916 0.75 1.54 0.50 1 1 2 2 2 ▇▁▁▁▇
person_of_color_or_not 920 0.75 0.27 0.44 0 0 0 1 1 ▇▁▁▁▃
anes_marriage <- anes_marriage %>%
     mutate(across(c(position_on_gay_marriage,partisan_identification, importance_of_religion, strength_of_ideological_identification), 
                   ~ factor(.)))
head(anes_marriage)
# A tibble: 6 × 6
  position_on_gay_marriage partisan_identification importance_of_religion
  <fct>                    <fct>                   <fct>                 
1 2                        7                       <NA>                  
2 2                        4                       1                     
3 <NA>                     <NA>                    <NA>                  
4 2                        5                       <NA>                  
5 1                        4                       <NA>                  
6 <NA>                     <NA>                    <NA>                  
# ℹ 3 more variables: strength_of_ideological_identification <fct>,
#   female <dbl+lbl>, person_of_color_or_not <dbl>

Model Building:define hypothesis & control variables

The hypothesis for all three primary independent variables would be: 1) The level of conservative partisan identification will be positive relative to the respondent’s position against gay marriage. People are more likely to be against gay marriage when leaner to Republicans.  2) The importance of religion in the respondent’s life will have a positive relationship with the respondent’s position against gay marriage. The more religion is important for people, the more likely they are against gay marriage. 3)The strength of ideological identification will have a positive relationship with the level of respondent’s position against gay marriage. The more conserved people are, the more likely they are against gay marriage.

The control variables:

I chose two variables, person of color or not and biological Sex, as control variables because they are dichotomous demographic variables.

logistic_order<-polr(position_on_gay_marriage~ partisan_identification + importance_of_religion + strength_of_ideological_identification + female+person_of_color_or_not, data=anes_marriage, 
           na.action = na.exclude, method = "logistic")
summary(logistic_order)

Re-fitting to get Hessian
Call:
polr(formula = position_on_gay_marriage ~ partisan_identification + 
    importance_of_religion + strength_of_ideological_identification + 
    female + person_of_color_or_not, data = anes_marriage, na.action = na.exclude, 
    method = "logistic")

Coefficients:
                                          Value Std. Error t value
partisan_identification2                 0.2102     0.3087  0.6811
partisan_identification3                -0.4964     0.3719 -1.3345
partisan_identification4                 0.3663     0.3088  1.1860
partisan_identification5                 0.6461     0.3164  2.0418
partisan_identification6                 0.8442     0.3233  2.6109
partisan_identification7                 0.7895     0.3172  2.4891
importance_of_religion2                  0.3541     0.2326  1.5221
importance_of_religion3                  0.9420     0.2002  4.7063
strength_of_ideological_identification2 -0.1009     0.8170 -0.1235
strength_of_ideological_identification3  1.5456     0.7514  2.0569
strength_of_ideological_identification4  1.6420     0.7494  2.1911
strength_of_ideological_identification5  1.8820     0.7579  2.4831
strength_of_ideological_identification6  2.2122     0.7708  2.8699
strength_of_ideological_identification7  2.9548     0.8532  3.4631
female                                  -0.3973     0.1596 -2.4898
person_of_color_or_not                   0.9241     0.1762  5.2437

Intercepts:
    Value   Std. Error t value
1|2  3.8184  0.7759     4.9210
2|3  5.4194  0.7850     6.9036

Residual Deviance: 1344.585 
AIC: 1380.585 
(2267 observations deleted due to missingness)
probit_order<-polr(position_on_gay_marriage~ partisan_identification + importance_of_religion + strength_of_ideological_identification +female + person_of_color_or_not, data=anes_marriage, 
           na.action = na.exclude, method = "probit")
summary (probit_order)

Re-fitting to get Hessian
Call:
polr(formula = position_on_gay_marriage ~ partisan_identification + 
    importance_of_religion + strength_of_ideological_identification + 
    female + person_of_color_or_not, data = anes_marriage, na.action = na.exclude, 
    method = "probit")

Coefficients:
                                           Value Std. Error  t value
partisan_identification2                 0.08805    0.16260  0.54149
partisan_identification3                -0.21769    0.18263 -1.19195
partisan_identification4                 0.21604    0.16595  1.30181
partisan_identification5                 0.31876    0.17436  1.82818
partisan_identification6                 0.48154    0.17564  2.74164
partisan_identification7                 0.44966    0.17118  2.62683
importance_of_religion2                  0.16283    0.12264  1.32769
importance_of_religion3                  0.49558    0.10613  4.66945
strength_of_ideological_identification2  0.03078    0.36315  0.08476
strength_of_ideological_identification3  0.82675    0.34194  2.41784
strength_of_ideological_identification4  0.85556    0.34158  2.50472
strength_of_ideological_identification5  0.97913    0.34667  2.82437
strength_of_ideological_identification6  1.17396    0.35421  3.31432
strength_of_ideological_identification7  1.63609    0.41125  3.97837
female                                  -0.21427    0.08731 -2.45405
person_of_color_or_not                   0.51546    0.09652  5.34033

Intercepts:
    Value   Std. Error t value
1|2  2.1093  0.3632     5.8075
2|3  2.9597  0.3676     8.0508

Residual Deviance: 1345.184 
AIC: 1381.184 
(2267 observations deleted due to missingness)
anes_marriage$position_on_gay_marriage_num<-as.numeric(anes_marriage$position_on_gay_marriage)
ols_order <- glm(position_on_gay_marriage_num~ partisan_identification + importance_of_religion + strength_of_ideological_identification + female + person_of_color_or_not, data=anes_marriage,family=gaussian(link="identity"))
summary(ols_order)

Call:
glm(formula = position_on_gay_marriage_num ~ partisan_identification + 
    importance_of_religion + strength_of_ideological_identification + 
    female + person_of_color_or_not, family = gaussian(link = "identity"), 
    data = anes_marriage)

Coefficients:
                                         Estimate Std. Error t value Pr(>|t|)
(Intercept)                              1.073540   0.065157  16.476  < 2e-16
partisan_identification2                -0.006476   0.042264  -0.153 0.878240
partisan_identification3                -0.056886   0.040836  -1.393 0.163816
partisan_identification4                 0.046014   0.047555   0.968 0.333411
partisan_identification5                 0.066902   0.055230   1.211 0.225967
partisan_identification6                 0.141514   0.055341   2.557 0.010656
partisan_identification7                 0.119704   0.055578   2.154 0.031421
importance_of_religion2                  0.008232   0.032712   0.252 0.801349
importance_of_religion3                  0.121275   0.030104   4.029 5.90e-05
strength_of_ideological_identification2 -0.009839   0.054543  -0.180 0.856864
strength_of_ideological_identification3  0.094564   0.057434   1.646 0.099881
strength_of_ideological_identification4  0.100724   0.058714   1.716 0.086465
strength_of_ideological_identification5  0.153112   0.064210   2.385 0.017228
strength_of_ideological_identification6  0.243225   0.071563   3.399 0.000695
strength_of_ideological_identification7  0.536387   0.110602   4.850 1.37e-06
female                                  -0.060803   0.025222  -2.411 0.016044
person_of_color_or_not                   0.152155   0.029319   5.190 2.41e-07
                                           
(Intercept)                             ***
partisan_identification2                   
partisan_identification3                   
partisan_identification4                   
partisan_identification5                   
partisan_identification6                *  
partisan_identification7                *  
importance_of_religion2                    
importance_of_religion3                 ***
strength_of_ideological_identification2    
strength_of_ideological_identification3 .  
strength_of_ideological_identification4 .  
strength_of_ideological_identification5 *  
strength_of_ideological_identification6 ***
strength_of_ideological_identification7 ***
female                                  *  
person_of_color_or_not                  ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 0.2199046)

    Null deviance: 367.87  on 1467  degrees of freedom
Residual deviance: 319.08  on 1451  degrees of freedom
  (2267 observations deleted due to missingness)
AIC: 1961.5

Number of Fisher Scoring iterations: 2

Display and interpret the results

stargazer(ols_order, logistic_order, probit_order, digits=3, type="text", single.row = TRUE)

======================================================================================================
                                                             Dependent variable:                      
                                        --------------------------------------------------------------
                                        position_on_gay_marriage_num     position_on_gay_marriage     
                                                   normal                ordered          ordered     
                                                                         logistic          probit     
                                                    (1)                    (2)              (3)       
------------------------------------------------------------------------------------------------------
partisan_identification2                       -0.006 (0.042)         0.210 (0.309)    0.088 (0.163)  
partisan_identification3                       -0.057 (0.041)         -0.496 (0.372)   -0.218 (0.183) 
partisan_identification4                       0.046 (0.048)          0.366 (0.309)    0.216 (0.166)  
partisan_identification5                       0.067 (0.055)         0.646** (0.316)   0.319* (0.174) 
partisan_identification6                      0.142** (0.055)        0.844*** (0.323) 0.482*** (0.176)
partisan_identification7                      0.120** (0.056)        0.790** (0.317)  0.450*** (0.171)
importance_of_religion2                        0.008 (0.033)          0.354 (0.233)    0.163 (0.123)  
importance_of_religion3                       0.121*** (0.030)       0.942*** (0.200) 0.496*** (0.106)
strength_of_ideological_identification2        -0.010 (0.055)         -0.101 (0.817)   0.031 (0.363)  
strength_of_ideological_identification3        0.095* (0.057)        1.546** (0.751)  0.827** (0.342) 
strength_of_ideological_identification4        0.101* (0.059)        1.642** (0.749)  0.856** (0.342) 
strength_of_ideological_identification5       0.153** (0.064)        1.882** (0.758)  0.979*** (0.347)
strength_of_ideological_identification6       0.243*** (0.072)       2.212*** (0.771) 1.174*** (0.354)
strength_of_ideological_identification7       0.536*** (0.111)       2.955*** (0.853) 1.636*** (0.411)
female                                        -0.061** (0.025)       -0.397** (0.160) -0.214** (0.087)
person_of_color_or_not                        0.152*** (0.029)       0.924*** (0.176) 0.515*** (0.097)
Constant                                      1.074*** (0.065)                                        
------------------------------------------------------------------------------------------------------
Observations                                       1,468                  1,468            1,468      
Log Likelihood                                    -963.764                                            
Akaike Inf. Crit.                                1,961.528                                            
======================================================================================================
Note:                                                                      *p<0.1; **p<0.05; ***p<0.01
export_summs(ols_order, logistic_order, probit_order, digits=3, model.names = c("Normal: Respondent’s position on gay marriage", "Logit: Respondent’s position on gay marriage", "Probit: Respondent’s position on gay marriage"), coefs=c("Intercept" = "(Intercept)", "pid_x: weak democrat" = "partisan_identification2", "pid_x:lean democrat" = "partisan_identification3", "pid_x:  independent" = "partisan_identification4", "pid_x: lean republican" = "partisan_identification5", "pid_x: weak republican" = "partisan_identification6", "pid_x:strong republican"= "partisan_identification7", "religion:Very important"= "importance_of_religion2", "religion:Moderately important"="importance_of_religion3", "libcon: somewhat liberal"= "strength_of_ideological_identification2", "libcon:slightly liberal"="strength_of_ideological_identification3", "libcon:moderate"="strength_of_ideological_identification4", "libcon: slightly conservative"="strength_of_ideological_identification5", "libcon:somewhat conservative"= "strength_of_ideological_identification6", "libcon:extremely conservative"= "strength_of_ideological_identification7", "Female"="female", "Person of color"="person_of_color_or_not") , quiet = TRUE)

Re-fitting to get Hessian


Re-fitting to get Hessian
Warning in FUN(X[[i]], ...): tidy() does not return p values for models of
class data.frame; significance stars not printed.
Warning in FUN(X[[i]], ...): tidy() does not return p values for models of
class data.frame; significance stars not printed.
Normal: Respondent’s position on gay marriageLogit: Respondent’s position on gay marriageProbit: Respondent’s position on gay marriage
Intercept1.074 ***          
(0.065)             
pid_x: weak democrat-0.006    0.210 0.088 
(0.042)   (0.309)(0.163)
pid_x:lean democrat-0.057    -0.496 -0.218 
(0.041)   (0.372)(0.183)
pid_x: independent0.046    0.366 0.216 
(0.048)   (0.309)(0.166)
pid_x: lean republican0.067    0.646 0.319 
(0.055)   (0.316)(0.174)
pid_x: weak republican0.142 *  0.844 0.482 
(0.055)   (0.323)(0.176)
pid_x:strong republican0.120 *  0.790 0.450 
(0.056)   (0.317)(0.171)
religion:Very important0.008    0.354 0.163 
(0.033)   (0.233)(0.123)
religion:Moderately important0.121 ***0.942 0.496 
(0.030)   (0.200)(0.106)
libcon: somewhat liberal-0.010    -0.101 0.031 
(0.055)   (0.817)(0.363)
libcon:slightly liberal0.095    1.546 0.827 
(0.057)   (0.751)(0.342)
libcon:moderate0.101    1.642 0.856 
(0.059)   (0.749)(0.342)
libcon: slightly conservative0.153 *  1.882 0.979 
(0.064)   (0.758)(0.347)
libcon:somewhat conservative0.243 ***2.212 1.174 
(0.072)   (0.771)(0.354)
libcon:extremely conservative0.536 ***2.955 1.636 
(0.111)   (0.853)(0.411)
Female-0.061 *  -0.397 -0.214 
(0.025)   (0.160)(0.087)
Person of color0.152 ***0.924 0.515 
(0.029)   (0.176)(0.097)
N1468        1468.000 1468.000 
AIC1961.528    1380.585 1381.184 
BIC2056.778    1475.834 1476.434 
Pseudo R20.173              
*** p < 0.001; ** p < 0.01; * p < 0.05.
logistic_predict_1<-ggpredict(logistic_order, terms= "partisan_identification", 
                         condition = c(person_of_color_or_not = "1", 
                     female = "1")) 
logistic_predict_1
# Predicted probabilities of position_on_gay_marriage

position_on_gay_marriage: 1

partisan_identification | Predicted |     95% CI
------------------------------------------------
1                       |      0.96 | 0.94, 0.98
2                       |      0.96 | 0.91, 0.98
3                       |      0.98 | 0.95, 0.99
4                       |      0.95 | 0.90, 0.98
5                       |      0.93 | 0.86, 0.97
6                       |      0.92 | 0.83, 0.96
7                       |      0.92 | 0.84, 0.97

position_on_gay_marriage: 2

partisan_identification | Predicted |     95% CI
------------------------------------------------
1                       |      0.03 | 0.02, 0.04
2                       |      0.03 | 0.02, 0.07
3                       |      0.02 | 0.01, 0.04
4                       |      0.04 | 0.02, 0.08
5                       |      0.05 | 0.02, 0.11
6                       |      0.06 | 0.03, 0.13
7                       |      0.06 | 0.03, 0.13

position_on_gay_marriage: 3

partisan_identification | Predicted |     95% CI
------------------------------------------------
1                       |      0.01 | 0.00, 0.01
2                       |      0.01 | 0.00, 0.02
3                       |      0.00 | 0.00, 0.01
4                       |      0.01 | 0.00, 0.02
5                       |      0.01 | 0.01, 0.03
6                       |      0.02 | 0.01, 0.04
7                       |      0.02 | 0.01, 0.04

Adjusted for:
*                 importance_of_religion = 1
* strength_of_ideological_identification = 1
logistic_predict_2<-ggpredict(logistic_order, terms= "importance_of_religion", 
                         condition = c(person_of_color_or_not = "1", 
                     female = "1")) 
logistic_predict_2
# Predicted probabilities of position_on_gay_marriage

position_on_gay_marriage: 1

importance_of_religion | Predicted |     95% CI
-----------------------------------------------
1                      |      0.96 | 0.94, 0.98
2                      |      0.95 | 0.91, 0.97
3                      |      0.91 | 0.85, 0.95

position_on_gay_marriage: 2

importance_of_religion | Predicted |     95% CI
-----------------------------------------------
1                      |      0.03 | 0.02, 0.04
2                      |      0.04 | 0.02, 0.07
3                      |      0.07 | 0.04, 0.12

position_on_gay_marriage: 3

importance_of_religion | Predicted |     95% CI
-----------------------------------------------
1                      |      0.01 | 0.00, 0.01
2                      |      0.01 | 0.01, 0.02
3                      |      0.02 | 0.01, 0.03

Adjusted for:
*                partisan_identification = 1
* strength_of_ideological_identification = 1
logistic_predict_3<-ggpredict(logistic_order, terms= "strength_of_ideological_identification", 
                         condition = c(person_of_color_or_not = "1", 
                     female = "1")) 
logistic_predict_3
# Predicted probabilities of position_on_gay_marriage

position_on_gay_marriage: 1

strength_of_ideological_identification | Predicted |     95% CI
---------------------------------------------------------------
1                                      |      0.96 | 0.94, 0.98
2                                      |      0.97 | 0.85, 0.99
3                                      |      0.85 | 0.55, 0.96
4                                      |      0.84 | 0.52, 0.96
5                                      |      0.80 | 0.46, 0.95
6                                      |      0.75 | 0.37, 0.94
7                                      |      0.58 | 0.19, 0.89

position_on_gay_marriage: 2

strength_of_ideological_identification | Predicted |     95% CI
---------------------------------------------------------------
1                                      |      0.03 | 0.02, 0.04
2                                      |      0.03 | 0.00, 0.12
3                                      |      0.11 | 0.03, 0.38
4                                      |      0.12 | 0.03, 0.40
5                                      |      0.15 | 0.04, 0.46
6                                      |      0.19 | 0.04, 0.54
7                                      |      0.29 | 0.07, 0.70

position_on_gay_marriage: 3

strength_of_ideological_identification | Predicted |     95% CI
---------------------------------------------------------------
1                                      |      0.01 | 0.00, 0.01
2                                      |      0.01 | 0.00, 0.03
3                                      |      0.03 | 0.01, 0.14
4                                      |      0.04 | 0.01, 0.15
5                                      |      0.05 | 0.01, 0.19
6                                      |      0.06 | 0.01, 0.25
7                                      |      0.13 | 0.02, 0.45

Adjusted for:
* partisan_identification = 1
*  importance_of_religion = 1
logistic_graphic<- function (z) {z %>% ggplot(aes(x = response.level, y = predicted,  fill = factor(x))) +
  geom_bar(stat = "identity", position = "dodge", width = 0.7) +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.4, position = position_dodge(width = 0.7))+ 
    labs(x = " Response Level: Respondent’s Position On Gay Marriage", y = "Predicted Probability", 
       title = "Predicted Probability with Confidence Intervals")+
  theme_minimal(base_size = 13)+ 
    scale_x_discrete(labels = c("1" = "Gays and lesbians \n should be allowed \n to legally marry", "2" = "Gays and lesbians \n should be allowed \n to form civil \n unions but not \n legally marry", 
                              "3" = "There should be \n no legal recognition \n of gay or \n lesbian couples’ relationship"))+
  theme(legend.position = "bottom")}


logistic_predict_1_graphic<- logistic_graphic (logistic_predict_1)+
  scale_fill_manual(values = c("1" = "blue", "2" = "cornflowerblue", "3"="lightblue", "4" = "darkgrey",
                               "5" = "lightcoral", "6"="red",  "7" = "firebrick"), labels=c("1"="strong democrat", "2"= "weak democrat", "3"= "lean democrat", "4"= "independent", "5"= "lean republican", "6"= "weak republican", "7"= "strong republican"))+ # Custom x-axis labels
  guides(fill = guide_legend(title = "Partisan \n Identification", nrow=3), color = "none")

logistic_predict_1_graphic

logistic_predict_2_graphic <- logistic_graphic (logistic_predict_2)+
  scale_fill_discrete(labels=c("1"="Extremely important", "2"= "Very important", "3"= "Moderately important"))+ # Custom x-axis labels
  guides(fill = guide_legend(title = "Importance Of Religion \n In Respondent’s Life", nrow=2), color = "none")
  

logistic_predict_2_graphic

logistic_predict_3_graphic <- logistic_graphic (logistic_predict_3)+
  scale_fill_manual(values = c("1" = "blue", "2" = "cornflowerblue", "3"="lightblue", "4" = "darkgrey",
                               "5" = "lightcoral", "6"="red",  "7" = "firebrick"), labels=c("1"="Extremely Liberal", "2"= "Somewhat Liberal", "3"= "Slightly Liberal", "4"= "Moderate", "5"= "Slightly Conservative", "6"= "Somewhat Conservative", "7"= "Extremely Conservative"))+
  guides(fill = guide_legend(title = "Strength Of \n Ideological \n Identification",nrow=3), color = "none")

logistic_predict_3_graphic

Regarding the AIC and BIC, the logit model has lower numbers than the linear and probit models. Accordingly, the Logit model will be a better fit with the dataset.

  • Compared to “strong Democrat” and holding other variables constant, the “weak Democrat” factor in variables that measure partisan identification, at its steepest slope, increases one unit equal to a 0.844 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that people with weak Democratic identification are more likely to oppose gay marriage than those with strong Democratic identification.
  • Compared to “strong democrat” and holding other variables constant, the “strong republican” factor in variables that measure partisan identification, at its steepest slope, increases one unit equal to a 0.844 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that people with strong republican identification are more likely to be against gay marriage than those with strong democrat identification.
  • Compared to “Not important at all” and holding other variables constant, the “Moderately important” factor in variables that measure the importance of religion in respondent’s life, at its steepest slope, increase one unit increase is equal to a 0.942 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that people with strong republican identification are more likely to be against gay marriage than those with strong democrat identification. This outcome means that people who feel religion is moderately important are more likely to be against gay marriage than those who feel not important at all.
  • Compared to “extremely liberal” and holding other variables constant, the “slightly liberal” factor in variables that measure the strength of ideological identification, at its steepest slope, increases one unit equal to a 1.546 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that people who are extremely liberal are more likely to be against gay marriage than those who are extremely liberal.
  • Compared to “extremely liberal” and holding other variables constant, the “moderate” factor in variables that measure the strength of ideological identification, at its steepest slope, increase one unit is equal to a 1.642 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that people who moderate are more likely to be against gay marriage than those who are extremely liberal.
  • Compared to “extremely liberal” and holding other variables constant, the “slightly conservative” factor in variables that measure the strength of ideological identification, at its steepest slope, increases one unit equal to a 1.882 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that slightly conservative people are more likely to be against gay marriage than those who are extremely liberal.
  • Compared to “extremely liberal” and holding other variables constant, the “somewhat conservative” factor in variables that measure the strength of ideological identification, at its steepest slope, increases one unit equal to a 2.212 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that somewhat conservative people are more likely to be against gay marriage than those who are extremely liberal.
  • Compared to “extremely liberal” and holding other variables constant, the “extremely conservative” factor in variables that measure the strength of ideological identification, at its steepest slope, increases one unit equal to a 2.955 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that extremely conservative people are more likely to be against gay marriage than those who are extremely liberal.
  • For the female variable, at its steepest slope, increases of one unit equal to a 0.397 logged odds decrease in the variable analysis respondent’s position on gay marriage. This outcome means that females are less likely to be against gay marriage than men.
  • For the Person of color variable, at its steepest slope, an increase of one unit increase in the level of the strength of ideological identification is equal to a 0.924 logged odds increase in the variable analysis respondent’s position on gay marriage. This outcome means that people of color are less likely to be against gay marriage than people of no color.

Test the parallel regression assumption using the Brant test

brant(logistic_order)
---------------------------------------------------------------------------- 
Test for                    X2  df  probability 
---------------------------------------------------------------------------- 
Omnibus                     24.55   16  0.08
partisan_identification2            4.75    1   0.03
partisan_identification3            0.8 1   0.37
partisan_identification4            0.05    1   0.82
partisan_identification5            4.72    1   0.03
partisan_identification6            0.03    1   0.86
partisan_identification7            1.94    1   0.16
importance_of_religion2         5.06    1   0.02
importance_of_religion3         4.4 1   0.04
strength_of_ideological_identification2 0   1   0.98
strength_of_ideological_identification3 0   1   0.98
strength_of_ideological_identification4 0   1   0.98
strength_of_ideological_identification5 0   1   0.98
strength_of_ideological_identification6 0   1   0.98
strength_of_ideological_identification7 0   1   0.98
female                      0.1 1   0.75
person_of_color_or_not          2.12    1   0.15
---------------------------------------------------------------------------- 

H0: Parallel Regression Assumption holds
Warning in brant(logistic_order): 231 combinations in table(dv,ivs) do not
occur. Because of that, the test results might be invalid.

According to the Omnibus, the probability is 0.08, which means the model is not significant and the parallel regression assumption is met. However, variables like “weak democrat” and “lean republican” are violated as they are smaller than 0.05. There is no need to move to the multinomial modeling approach as it overall does not violate the parallel regression assumption.

Instructions Multinomial Modeling

multinom_logit <- multinom(position_on_gay_marriage~ partisan_identification + importance_of_religion + strength_of_ideological_identification + female + person_of_color_or_not, data=anes_marriage,logit= TRUE)
# weights:  54 (34 variable)
initial  value 1612.762840 
iter  10 value 683.150944
iter  20 value 661.133818
iter  30 value 659.446547
iter  40 value 659.085847
iter  50 value 659.011590
final  value 659.011351 
converged
summary(multinom_logit) 
Call:
multinom(formula = position_on_gay_marriage ~ partisan_identification + 
    importance_of_religion + strength_of_ideological_identification + 
    female + person_of_color_or_not, data = anes_marriage, logit = TRUE)

Coefficients:
  (Intercept) partisan_identification2 partisan_identification3
2   -3.913672                0.6553601               -0.2610745
3  -16.662764               -0.9740893               -1.0230449
  partisan_identification4 partisan_identification5 partisan_identification6
2                0.3730180                1.0509997                0.8511366
3                0.3140273               -0.2594967                0.9087101
  partisan_identification7 importance_of_religion2 importance_of_religion3
2                1.0313318               0.6873105               1.1421027
3                0.4037139              -0.3756813               0.5954235
  strength_of_ideological_identification2
2                              -0.5249731
3                              11.7795078
  strength_of_ideological_identification3
2                               0.9735391
3                              13.6890632
  strength_of_ideological_identification4
2                                1.184898
3                               13.481333
  strength_of_ideological_identification5
2                                1.449345
3                               13.711361
  strength_of_ideological_identification6
2                                1.671087
3                               14.270178
  strength_of_ideological_identification7     female person_of_color_or_not
2                                1.707989 -0.4109582               0.695510
3                               15.786245 -0.4110229               1.397374

Std. Errors:
  (Intercept) partisan_identification2 partisan_identification3
2   0.7954620                0.3520736                0.4331406
3   0.5188098                0.6755463                0.6816024
  partisan_identification4 partisan_identification5 partisan_identification6
2                0.3745717                0.3668469                0.3842441
3                0.4838509                0.6112169                0.5186630
  partisan_identification7 importance_of_religion2 importance_of_religion3
2                0.3709789               0.2684773               0.2378548
3                0.5232478               0.4409674               0.3275306
  strength_of_ideological_identification2
2                               0.8522028
3                               0.6516326
  strength_of_ideological_identification3
2                               0.7639274
3                               0.3325161
  strength_of_ideological_identification4
2                               0.7592122
3                               0.3238776
  strength_of_ideological_identification5
2                               0.7695191
3                               0.3154310
  strength_of_ideological_identification6
2                               0.7852653
3                               0.3388978
  strength_of_ideological_identification7    female person_of_color_or_not
2                               0.9172363 0.1812809               0.204669
3                               0.5050607 0.2847810               0.300272

Residual Deviance: 1318.023 
AIC: 1386.023 
multinom_probit <- multinom(position_on_gay_marriage~ partisan_identification + importance_of_religion + strength_of_ideological_identification + female + person_of_color_or_not, data=anes_marriage,probit= TRUE)
# weights:  54 (34 variable)
initial  value 1612.762840 
iter  10 value 683.150944
iter  20 value 661.133818
iter  30 value 659.446547
iter  40 value 659.085847
iter  50 value 659.011590
final  value 659.011351 
converged
summary(multinom_probit)
Call:
multinom(formula = position_on_gay_marriage ~ partisan_identification + 
    importance_of_religion + strength_of_ideological_identification + 
    female + person_of_color_or_not, data = anes_marriage, probit = TRUE)

Coefficients:
  (Intercept) partisan_identification2 partisan_identification3
2   -3.913672                0.6553601               -0.2610745
3  -16.662764               -0.9740893               -1.0230449
  partisan_identification4 partisan_identification5 partisan_identification6
2                0.3730180                1.0509997                0.8511366
3                0.3140273               -0.2594967                0.9087101
  partisan_identification7 importance_of_religion2 importance_of_religion3
2                1.0313318               0.6873105               1.1421027
3                0.4037139              -0.3756813               0.5954235
  strength_of_ideological_identification2
2                              -0.5249731
3                              11.7795078
  strength_of_ideological_identification3
2                               0.9735391
3                              13.6890632
  strength_of_ideological_identification4
2                                1.184898
3                               13.481333
  strength_of_ideological_identification5
2                                1.449345
3                               13.711361
  strength_of_ideological_identification6
2                                1.671087
3                               14.270178
  strength_of_ideological_identification7     female person_of_color_or_not
2                                1.707989 -0.4109582               0.695510
3                               15.786245 -0.4110229               1.397374

Std. Errors:
  (Intercept) partisan_identification2 partisan_identification3
2   0.7954620                0.3520736                0.4331406
3   0.5188098                0.6755463                0.6816024
  partisan_identification4 partisan_identification5 partisan_identification6
2                0.3745717                0.3668469                0.3842441
3                0.4838509                0.6112169                0.5186630
  partisan_identification7 importance_of_religion2 importance_of_religion3
2                0.3709789               0.2684773               0.2378548
3                0.5232478               0.4409674               0.3275306
  strength_of_ideological_identification2
2                               0.8522028
3                               0.6516326
  strength_of_ideological_identification3
2                               0.7639274
3                               0.3325161
  strength_of_ideological_identification4
2                               0.7592122
3                               0.3238776
  strength_of_ideological_identification5
2                               0.7695191
3                               0.3154310
  strength_of_ideological_identification6
2                               0.7852653
3                               0.3388978
  strength_of_ideological_identification7    female person_of_color_or_not
2                               0.9172363 0.1812809               0.204669
3                               0.5050607 0.2847810               0.300272

Residual Deviance: 1318.023 
AIC: 1386.023 
multinom_model <- multinom(position_on_gay_marriage~ partisan_identification + importance_of_religion + strength_of_ideological_identification +female + person_of_color_or_not, data=anes_marriage)
# weights:  54 (34 variable)
initial  value 1612.762840 
iter  10 value 683.150944
iter  20 value 661.133818
iter  30 value 659.446547
iter  40 value 659.085847
iter  50 value 659.011590
final  value 659.011351 
converged
summary(multinom_model)
Call:
multinom(formula = position_on_gay_marriage ~ partisan_identification + 
    importance_of_religion + strength_of_ideological_identification + 
    female + person_of_color_or_not, data = anes_marriage)

Coefficients:
  (Intercept) partisan_identification2 partisan_identification3
2   -3.913672                0.6553601               -0.2610745
3  -16.662764               -0.9740893               -1.0230449
  partisan_identification4 partisan_identification5 partisan_identification6
2                0.3730180                1.0509997                0.8511366
3                0.3140273               -0.2594967                0.9087101
  partisan_identification7 importance_of_religion2 importance_of_religion3
2                1.0313318               0.6873105               1.1421027
3                0.4037139              -0.3756813               0.5954235
  strength_of_ideological_identification2
2                              -0.5249731
3                              11.7795078
  strength_of_ideological_identification3
2                               0.9735391
3                              13.6890632
  strength_of_ideological_identification4
2                                1.184898
3                               13.481333
  strength_of_ideological_identification5
2                                1.449345
3                               13.711361
  strength_of_ideological_identification6
2                                1.671087
3                               14.270178
  strength_of_ideological_identification7     female person_of_color_or_not
2                                1.707989 -0.4109582               0.695510
3                               15.786245 -0.4110229               1.397374

Std. Errors:
  (Intercept) partisan_identification2 partisan_identification3
2   0.7954620                0.3520736                0.4331406
3   0.5188098                0.6755463                0.6816024
  partisan_identification4 partisan_identification5 partisan_identification6
2                0.3745717                0.3668469                0.3842441
3                0.4838509                0.6112169                0.5186630
  partisan_identification7 importance_of_religion2 importance_of_religion3
2                0.3709789               0.2684773               0.2378548
3                0.5232478               0.4409674               0.3275306
  strength_of_ideological_identification2
2                               0.8522028
3                               0.6516326
  strength_of_ideological_identification3
2                               0.7639274
3                               0.3325161
  strength_of_ideological_identification4
2                               0.7592122
3                               0.3238776
  strength_of_ideological_identification5
2                               0.7695191
3                               0.3154310
  strength_of_ideological_identification6
2                               0.7852653
3                               0.3388978
  strength_of_ideological_identification7    female person_of_color_or_not
2                               0.9172363 0.1812809               0.204669
3                               0.5050607 0.2847810               0.300272

Residual Deviance: 1318.023 
AIC: 1386.023 
stargazer(multinom_model, digits=3, type="text", single.row = TRUE)

============================================================================
                                                Dependent variable:         
                                        ------------------------------------
                                                2                 3         
                                               (1)               (2)        
----------------------------------------------------------------------------
partisan_identification2                 0.655* (0.352)     -0.974 (0.676)  
partisan_identification3                 -0.261 (0.433)     -1.023 (0.682)  
partisan_identification4                  0.373 (0.375)     0.314 (0.484)   
partisan_identification5                1.051*** (0.367)    -0.259 (0.611)  
partisan_identification6                 0.851** (0.384)    0.909* (0.519)  
partisan_identification7                1.031*** (0.371)    0.404 (0.523)   
importance_of_religion2                  0.687** (0.268)    -0.376 (0.441)  
importance_of_religion3                 1.142*** (0.238)    0.595* (0.328)  
strength_of_ideological_identification2  -0.525 (0.852)   11.780*** (0.652) 
strength_of_ideological_identification3   0.974 (0.764)   13.689*** (0.333) 
strength_of_ideological_identification4   1.185 (0.759)   13.481*** (0.324) 
strength_of_ideological_identification5  1.449* (0.770)   13.711*** (0.315) 
strength_of_ideological_identification6  1.671** (0.785)  14.270*** (0.339) 
strength_of_ideological_identification7  1.708* (0.917)   15.786*** (0.505) 
female                                  -0.411** (0.181)    -0.411 (0.285)  
person_of_color_or_not                  0.696*** (0.205)   1.397*** (0.300) 
Constant                                -3.914*** (0.795) -16.663*** (0.519)
----------------------------------------------------------------------------
Akaike Inf. Crit.                           1,386.023         1,386.023     
============================================================================
Note:                                            *p<0.1; **p<0.05; ***p<0.01
stargazer(multinom_model, digits=3, type="text", single.row = TRUE, dep.var.labels=c("Respondent’s position on gay marriage"), covariate.labels=c("pid_x: weak democrat", "pid_x: lean democrat", "pid_x: independent", "pid_x: lean republican", "pid_x: weak republican", "pid_x: strong republican", "religion:Very important", "religion:Moderately important", "libcon: somewhat liberal", "libcon:slightly liberal", "libcon:moderate", "libcon: slightly conservative", "libcon:somewhat conservative", "libcon:extremely conservative", "Female", "Person of color"))

======================================================================================
                                                Dependent variable:                   
                              --------------------------------------------------------
                              Respondent’s position on gay marriage         3         
                                               (1)                         (2)        
--------------------------------------------------------------------------------------
pidweak democrat                         0.655* (0.352)               -0.974 (0.676)  
pidlean democrat                         -0.261 (0.433)               -1.023 (0.682)  
pidindependent                            0.373 (0.375)               0.314 (0.484)   
pidlean republican                      1.051*** (0.367)              -0.259 (0.611)  
pidweak republican                       0.851** (0.384)              0.909* (0.519)  
pidstrong republican                    1.031*** (0.371)              0.404 (0.523)   
religion:Very important                  0.687** (0.268)              -0.376 (0.441)  
religion:Moderately important           1.142*** (0.238)              0.595* (0.328)  
libcon: somewhat liberal                 -0.525 (0.852)             11.780*** (0.652) 
libcon:slightly liberal                   0.974 (0.764)             13.689*** (0.333) 
libcon:moderate                           1.185 (0.759)             13.481*** (0.324) 
libcon: slightly conservative            1.449* (0.770)             13.711*** (0.315) 
libcon:somewhat conservative             1.671** (0.785)            14.270*** (0.339) 
libcon:extremely conservative            1.708* (0.917)             15.786*** (0.505) 
Female                                  -0.411** (0.181)              -0.411 (0.285)  
Person of color                         0.696*** (0.205)             1.397*** (0.300) 
Constant                                -3.914*** (0.795)           -16.663*** (0.519)
--------------------------------------------------------------------------------------
Akaike Inf. Crit.                           1,386.023                   1,386.023     
======================================================================================
Note:                                                      *p<0.1; **p<0.05; ***p<0.01
multinomial_model <- ggpredict(multinom_model, terms="partisan_identification")
multinomial_model
# Predicted probabilities of position_on_gay_marriage

position_on_gay_marriage: 1

partisan_identification | Predicted
-----------------------------------
1                       |      0.99
2                       |      0.98
3                       |      0.99
4                       |      0.98
5                       |      0.96
6                       |      0.97
7                       |      0.97

position_on_gay_marriage: 2

partisan_identification | Predicted
-----------------------------------
1                       |      0.01
2                       |      0.02
3                       |      0.01
4                       |      0.02
5                       |      0.04
6                       |      0.03
7                       |      0.03

position_on_gay_marriage: 3

partisan_identification | Predicted
-----------------------------------
1                       |      0.00
2                       |      0.00
3                       |      0.00
4                       |      0.00
5                       |      0.00
6                       |      0.00
7                       |      0.00

Adjusted for:
*                 importance_of_religion =    1
* strength_of_ideological_identification =    1
*                                 female = 1.49
*                 person_of_color_or_not = 0.24
ordered_model <- ggpredict(probit_order, terms= "partisan_identification")
ordered_model
# Predicted probabilities of position_on_gay_marriage

position_on_gay_marriage: 1

partisan_identification | Predicted |     95% CI
------------------------------------------------
1                       |      0.99 | 1.00, 1.00
2                       |      0.99 | 1.00, 1.00
3                       |      0.99 | 1.00, 1.00
4                       |      0.98 | 1.00, 1.00
5                       |      0.98 | 1.00, 1.00
6                       |      0.97 | 1.00, 1.00
7                       |      0.97 | 1.00, 1.00

position_on_gay_marriage: 2

partisan_identification | Predicted |     95% CI
------------------------------------------------
1                       |      0.01 | 0.00, 0.00
2                       |      0.01 | 0.00, 0.00
3                       |      0.01 | 0.00, 0.00
4                       |      0.02 | 0.00, 0.00
5                       |      0.02 | 0.00, 0.00
6                       |      0.03 | 0.00, 0.00
7                       |      0.03 | 0.00, 0.00

position_on_gay_marriage: 3

partisan_identification | Predicted |     95% CI
------------------------------------------------
1                       |      0.00 | 0.00, 0.00
2                       |      0.00 | 0.00, 0.00
3                       |      0.00 | 0.00, 0.00
4                       |      0.00 | 0.00, 0.00
5                       |      0.00 | 0.00, 0.00
6                       |      0.00 | 0.00, 0.00
7                       |      0.00 | 0.00, 0.00

Adjusted for:
*                 importance_of_religion =    1
* strength_of_ideological_identification =    1
*                                 female = 1.49
*                 person_of_color_or_not = 0.24
# Function to fit the model and get predictions
boot_fn <- function(data, indices) {
  boot_sample <- data[indices, ]  # Resample data
  model_boot <- multinom(position_on_gay_marriage~ partisan_identification + importance_of_religion + strength_of_ideological_identification +female + person_of_color_or_not, data = boot_sample, trace = FALSE)
  preds <- ggpredict(model_boot, terms = "partisan_identification")  # Get predictions for pid_f
  return(preds$predicted)
}

set.seed(2006) #Uses same random number generator for sampling purposs
boot_results <- boot(data = anes_marriage, statistic = boot_fn, R = 500) #R = is where you control number of bootstrapped samples. Should be at least 500 ideally 1,000

# Compute 95% confidence intervals
conf.low <- apply(boot_results$t, 2, quantile, probs = 0.025)
conf.high <- apply(boot_results$t, 2, quantile, probs = 0.975)

# Get original ggeffects predictions
multinomial_model <- ggpredict(multinom_model, terms="partisan_identification")

# Add CIs to ggeffects output
multinomial_model$lower <- conf.low
multinomial_model$upper <- conf.high

multi <- ggplot(multinomial_model, aes(x = x, y = predicted, color = response.level)) +
    geom_point(stat = "identity", position = position_dodge(width = 0.5)) +
    theme_minimal(base_size = 13)+
  labs(x = "Partisan Identification", y = "Predicted Probability", 
       title = "Predicted Probability Multinomial")+
  scale_color_discrete(
    labels = c("1" = "Gays and lesbians should \n be allowed to legally marry", "2" = "Gays and lesbians should be \n allowed to legally marry", 
               "3" = "There should be no legal recognition \n of gay or lesbian couples’ relationship")
  ) +  # Default color scale with custom labels
  scale_x_discrete(
    labels = c("1" = "Strong Democrat", "2" = "Weak Democrat", 
               "3" = "Lean Democrat", "4" = "Independent",
               "5" = "Lean Republican", "6" = "Weak Republican", "7" = "Strong Republican")) +
  theme(legend.position = c(0.05, 0.95), legend.justification = c(0, 1)) +  # Position the legend
  guides(color = guide_legend(title = "Respondent’s Position On Gay Marriage")) +
   geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.4, 
                position = position_dodge(width = 0.5))+
   theme(axis.text.x = element_text(angle=15)) 
Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
3.5.0.
ℹ Please use the `legend.position.inside` argument of `theme()` instead.
multi

  order <- ggplot(ordered_model, aes(x = x, y = predicted, color = response.level)) +
    geom_point(stat = "identity", position = position_dodge(width = 0.5)) +
    theme_minimal(base_size = 13)+
  labs(x = "Partisan Identification", y = "Predicted Probability", 
       title = "Predicted Probability Multinomial")+
  scale_color_discrete(
    labels = c("1" = "Gays and lesbians should \n be allowed to legally marry", "2" = "Gays and lesbians should \n be allowed to legally marry", 
               "3" = "There should be no legal recognition \n of gay or lesbian couples’ relationship")
  ) +  # Default color scale with custom labels
  scale_x_discrete(
    labels = c("1" = "Strong Democrat", "2" = "Weak Democrat", 
               "3" = "Lean Democrat", "4" = "Independent",
               "5" = "Lean Republican", "6" = "Weak Republican", "7" = "Strong Republican")) +
  theme(legend.position = c(0.05, 0.95), legend.justification = c(0, 1)) +  # Position the legend
  guides(color = guide_legend(title = "Respondent’s Position On Gay Marriage")) +
   geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.4, 
                position = position_dodge(width = 0.5))+
   theme(axis.text.x = element_text(angle=15)) 
  order

  plots<-multi + order
  plots

Overall, for respondent’s positions on gay marriage are “Gays and lesbians should be allowed to form civil unions but not legally marry” and “There should be no legal recognition of gay or lesbian couples’ relationship” partisan identification, especially lean to Republican, lean to the conservative, feel religion are important, male, and people of not color are more likely in this position.

  • Keeping all other variables constant, if “Weak Democrat” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 0.655.
  • Keeping all other variables constant, if “Lean Republican” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 1.051.
  • Keeping all other variables constant, if “weak republican” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 0.851.
  • Keeping all other variables constant, if “strong republican” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 1.031.
  • Keeping all other variables constant, if “Very important” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 0.687.
  • Keeping all other variables constant, if “Moderately important” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 1.142.
  • Keeping all other variables constant, if “slightly conservative” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 1.449.
  • Keeping all other variables constant, if “somewhat conservative” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 1.671.
  • Keeping all other variables constant, if “extremely conservative” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is higher by 1.708.
  • Keeping all other variables constant, if “Female” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is decreased by 0.411.
  • Keeping all other variables constant, if “Person of color” is higher by one unit, the log odds for “Gays and lesbians should be allowed to form civil unions but not legally marry” is decreased by 0.696.
  • Keeping all other variables constant, if “weak republican” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 0.909.
  • Keeping all other variables constant, if “Moderately important” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 0.595.
  • Keeping all other variables constant, if “somewhat liberal” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 11.780.
  • Keeping all other variables constant, if “slightly liberal” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 13.689.
  • Keeping all other variables constant, if “somewhat conservative” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 14.270.
  • Keeping all other variables constant, if “extremely conservative” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 15.786.
  • Keeping all other variables constant, if “Person of color” is higher by one unit, the log odds for “There should be no legal recognition of gay or lesbian couples’ relationship” is decreased by 1.397.

According to the graphic, the multinomial regression looks similar to the ordered model, so there is no violation of the proportional regressions assumption.