library(haven)
library(foreign)
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(broom)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(readr)
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
library(car)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(alr3)
##
## Attaching package: 'alr3'
## The following object is masked from 'package:MASS':
##
## forbes
library(zoo)
library(nortest)
library(plotrix)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:plotrix':
##
## rescale
## The following object is masked from 'package:readr':
##
## col_factor
library(tableone)
library(Weighted.Desc.Stat)
library(mitools)
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
##
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
##
## dotchart
library(VGAM)
## Loading required package: stats4
## Loading required package: splines
##
## Attaching package: 'VGAM'
## The following object is masked from 'package:survey':
##
## calibrate
## The following object is masked from 'package:lmtest':
##
## lrtest
## The following object is masked from 'package:car':
##
## logit
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
anes2016<-read_dta("C:\\Users\\Jaire\\OneDrive\\Desktop\\Stats for Dem Data 2\\Homework 3\\ANES2016.dta")
In this analysis, the multinomial outome of interest is political party. The variable “V161155” within the ANES 2016 cross-sectional data set contains responses for the self-identified political party of respondents.
The survey question: “Generally speaking, do you usually think of yourself as a Democrat, a Republican, an independent, or what?”
# Outcome Raw Data:
table(anes2016$V161155)
##
## -9 -8 0 1 2 3 5
## 15 10 49 1451 1231 1367 148
# Outcome Transformation:
anes2016$PolParty<-recode(anes2016$V161155, recodes = "-9:0=NA; 1='Democrat'; 2='Republican'; 3='Independent'; 5=NA", as.factor = T)
# Political Party from V161155
table(anes2016$PolParty)
##
## Democrat Independent Republican
## 1451 1367 1231
To what extent does self-identified race and highest level of education impact party preference?
# Raw data:
table(anes2016$V161310X)
##
## -9 1 2 3 4 5 6
## 33 3038 398 148 27 450 177
# Transformation:
anes2016$Race<-recode(anes2016$V161310X, recodes = "-9=NA; 1='White'; 2='Black'; 3='AsNatPac'; 4='NatAmAlsk'; 5='Hisp'; 6='Other'", as.factor = T)
# Race from anes2016$V161310X
table(anes2016$Race)
##
## AsNatPac Black Hisp NatAmAlsk Other White
## 148 398 450 27 177 3038
# Highest Level of Education Raw Data:
table(anes2016$V161270)
##
## -9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 90 95
## 15 1 3 15 22 32 40 62 107 810 899 313 288 955 499 88 93 5 24
# Highest Level of Education Transformations:
anes2016$HLEducation<-recode(anes2016$V161270, recodes = "15:95=NA;-9=NA;10=NA;1:8='LessHSDipGED'; 9='HSDipGED'; 11:12='Assoc'; 13='Bachlrs'; 14='Mastrs'", as.factor = T)
# Highest Level of Education from V161270:
table(anes2016$HLEducation)
##
## Assoc Bachlrs HSDipGED LessHSDipGED Mastrs
## 601 955 810 282 499
The basic assumption of a proportional odds model is that for each level within the outcome variable (i.e. Politcal Party) other than the reference category (i.e. independent), the predictors are independent of the remaining outcome categories. However, this anaylsis uses a multinomial outcome rather than an ordinal outcome and uses a multinomial distribution.
# Combining pre- post- weights into one object:
anes2016$fullwt<-as.numeric(anes2016$V160102+anes2016$V160101)
mfit<-vglm(anes2016$PolParty~anes2016$HLEducation+anes2016$Race,
family = multinomial(refLevel = 3),
data = anes2016,
weights =anes2016$fullwt/mean(anes2016$fullwt, na.rm=T))
summary(mfit)
##
## Call:
## vglm(formula = anes2016$PolParty ~ anes2016$HLEducation + anes2016$Race,
## family = multinomial(refLevel = 3), data = anes2016, weights = anes2016$fullwt/mean(anes2016$fullwt,
## na.rm = T))
##
## Pearson residuals:
## Min 1Q Median 3Q Max
## log(mu[,1]/mu[,3]) -6.475 -0.6900 -0.2980 0.8177 3.528
## log(mu[,2]/mu[,3]) -4.971 -0.6899 -0.3228 0.9798 4.605
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept):1 0.5614827 0.3188524 1.761 0.07825 .
## (Intercept):2 0.6292030 0.3187755 1.974 0.04840 *
## anes2016$HLEducationBachlrs:1 -0.0005426 0.1496642 -0.004 0.99711
## anes2016$HLEducationBachlrs:2 -0.0612833 0.1452091 -0.422 0.67300
## anes2016$HLEducationHSDipGED:1 0.1507730 0.1409454 1.070 0.28474
## anes2016$HLEducationHSDipGED:2 0.1853885 0.1364104 1.359 0.17413
## anes2016$HLEducationLessHSDipGED:1 0.2003232 0.1891991 1.059 0.28969
## anes2016$HLEducationLessHSDipGED:2 0.3776572 0.1820974 2.074 0.03809 *
## anes2016$HLEducationMastrs:1 0.9057196 0.1803981 5.021 5.15e-07 ***
## anes2016$HLEducationMastrs:2 0.3737575 0.1848012 2.022 0.04313 *
## anes2016$RaceBlack:1 1.7726251 0.3768979 4.703 2.56e-06 ***
## anes2016$RaceBlack:2 0.3808063 0.3917677 0.972 0.33104
## anes2016$RaceHisp:1 0.3152484 0.3343170 0.943 0.34570
## anes2016$RaceHisp:2 -0.1266669 0.3388402 -0.374 0.70853
## anes2016$RaceNatAmAlsk:1 0.1085751 0.8237049 0.132 0.89513
## anes2016$RaceNatAmAlsk:2 0.6106323 0.7697928 0.793 0.42764
## anes2016$RaceOther:1 -0.4945788 0.4001184 -1.236 0.21643
## anes2016$RaceOther:2 -0.1211030 0.3886383 -0.312 0.75534
## anes2016$RaceWhite:1 -0.9843840 0.3045205 -3.233 0.00123 **
## anes2016$RaceWhite:2 -0.8309347 0.3055137 -2.720 0.00653 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Names of linear predictors: log(mu[,1]/mu[,3]), log(mu[,2]/mu[,3])
##
## Residual deviance: 6469.122 on 5918 degrees of freedom
##
## Log-likelihood: -3234.561 on 5918 degrees of freedom
##
## Number of Fisher scoring iterations: 5
##
## No Hauck-Donner effect found in any of the estimates
##
##
## Reference group is level 3 of the response
Based on this analysis,
In comparison to voters whose highest level of education is an associate’s degree of some kind:
those whose highest level of education is a bachelor’s degree were less likely to identify as Democracts and even less likely to identify as Republicans, than those whose highest level of education is an associate’s degree of some kind.
those whose highest level of education is a high school diploma or GED were more likely to identify as Democracts and even more likely to identify as Republicans, than those whose highest level of education is an associate’s degree of some kind.
those whose highest level of education is less than a high school diploma or GED were more likely to identify as Democracts and * significantly more likely to identify as Republicans, than those whose highest level of education is an associate’s degree of some kind.
those whose highest level of education is a master’s degree were *** significantly more likely to identify as Democracts and less *significantly more likely to identify as Republicans, than those whose highest level of education is an associate’s degree of some kind.
Based on this analysis,
In comparison to voters whose self-identified race is Asian, Native Hawaiian, or Pacific Islander:
those whose self-identified race is black were more likely to identify as Republicans and *** significantly more likely to identify as Democracts, than those identifying as Asian, Native Hawaiian, or Pacific Islander.
those whose self-identified race is Hispanic were more likely to identify as Democracts and less likely to identify as Republicans, than those identifying as Asian, Native Hawaiian, or Pacific Islander.
those whose self-identified race is Native American or Alaskan Native were more likely to identify as democrats and even more likely to identify as Republicans, than those identifying as Asian, Native Hawaiian, or Pacific Islander.
those whose self-identified race is “other or multiracial” were less likely to identify as Republicans and even less likely to identify as Democrats, than those identifying as Asian, Native Hawaiian, or Pacific Islander.
those whose self-identified race is white were ** significantly less likely to identify as Republicans and ** significantly even less likely to identify as Democrats, than those identifying as Asian, Native Hawaiian, or Pacific Islander.
round(exp(coef(mfit)), 3)
## (Intercept):1 (Intercept):2
## 1.753 1.876
## anes2016$HLEducationBachlrs:1 anes2016$HLEducationBachlrs:2
## 0.999 0.941
## anes2016$HLEducationHSDipGED:1 anes2016$HLEducationHSDipGED:2
## 1.163 1.204
## anes2016$HLEducationLessHSDipGED:1 anes2016$HLEducationLessHSDipGED:2
## 1.222 1.459
## anes2016$HLEducationMastrs:1 anes2016$HLEducationMastrs:2
## 2.474 1.453
## anes2016$RaceBlack:1 anes2016$RaceBlack:2
## 5.886 1.463
## anes2016$RaceHisp:1 anes2016$RaceHisp:2
## 1.371 0.881
## anes2016$RaceNatAmAlsk:1 anes2016$RaceNatAmAlsk:2
## 1.115 1.842
## anes2016$RaceOther:1 anes2016$RaceOther:2
## 0.610 0.886
## anes2016$RaceWhite:1 anes2016$RaceWhite:2
## 0.374 0.436
round(exp(confint(mfit)), 3)
## 2.5 % 97.5 %
## (Intercept):1 0.939 3.275
## (Intercept):2 1.004 3.504
## anes2016$HLEducationBachlrs:1 0.745 1.340
## anes2016$HLEducationBachlrs:2 0.708 1.250
## anes2016$HLEducationHSDipGED:1 0.882 1.533
## anes2016$HLEducationHSDipGED:2 0.921 1.573
## anes2016$HLEducationLessHSDipGED:1 0.843 1.770
## anes2016$HLEducationLessHSDipGED:2 1.021 2.085
## anes2016$HLEducationMastrs:1 1.737 3.523
## anes2016$HLEducationMastrs:2 1.012 2.087
## anes2016$RaceBlack:1 2.812 12.321
## anes2016$RaceBlack:2 0.679 3.154
## anes2016$RaceHisp:1 0.712 2.639
## anes2016$RaceHisp:2 0.453 1.712
## anes2016$RaceNatAmAlsk:1 0.222 5.601
## anes2016$RaceNatAmAlsk:2 0.407 8.326
## anes2016$RaceOther:1 0.278 1.336
## anes2016$RaceOther:2 0.414 1.898
## anes2016$RaceWhite:1 0.206 0.679
## anes2016$RaceWhite:2 0.239 0.793