Plot table proportions by predicted class {1, 2} for each outcome variable and demographic variable
Prorportion of class membership prediction
- From the posterior distribution we get the probability for each respondent of being a member of a class.
survey %>% select(outcome_variables) %>% get_label()
## ABINSPAY
## "Should people be able to use health insurance for abortion - Ver Y"
## ABMEDGOV1
## "Woman and doctor or Govt should decide what info needed for abortion - Ver X"
## ABHELP1
## "R would help with arrangements for abortion"
## ABHELP2
## "R would help with paying for abortion"
## ABHELP3
## "R would help with paying for abortion-related other costs"
## ABHELP4
## "R would help with emotional support for abortion"
## ABMORAL
## "R has a moral opposition to abortion"
## ABSTATE1
## "Difficulty of obtaining abortion in R's state"
## ABSTATE2
## "Change abortion laws in R's state to make it easier or harder to get an abortion"
breakdown of class membership predictions
df %>% group_by(class_prediction) %>%
count() %>%
ungroup() %>%
mutate(proportion = n/sum(n)) %>%
datatable()
df %>% group_by(class_prediction) %>%
count_(outcome_variables) %>%
mutate(proportion = n/sum(n)) %>%
arrange(desc(proportion)) %>%
datatable()
demographic variables value codes
survey %>% select(demogrpahic_variables) %>% get_labels()
## $SEX
## [1] "MALE" "FEMALE"
##
## $RACE
## [1] "IAP" "WHITE" "BLACK" "OTHER"
##
## $CLASS
## [1] "IAP" "LOWER CLASS" "WORKING CLASS" "MIDDLE CLASS"
## [5] "UPPER CLASS" "NO CLASS" "DK" "NA"
##
## $PARTYID
## [1] "STRONG DEMOCRAT" "NOT STR DEMOCRAT" "IND,NEAR DEM"
## [4] "INDEPENDENT" "IND,NEAR REP" "NOT STR REPUBLICAN"
## [7] "STRONG REPUBLICAN" "OTHER PARTY" "DK"
## [10] "NA"
predicted class memberhip by gender
df %>%
group_by(class_prediction) %>%
count(SEX) %>%
ungroup() %>%
mutate(proportion = n/sum(n)) %>%
plot_ly(x = ~SEX, y = ~proportion, type = 'bar', colors=~class_prediction, name = ~class_prediction) %>%
layout(yaxis = list(title = 'Proportion', range=c(0,1)), barmode = 'group')
predicted class memberhip by RACE
df %>%
group_by(class_prediction) %>%
count(RACE) %>%
ungroup() %>%
mutate(proportion = n/sum(n)) %>%
plot_ly(x = ~RACE, y = ~proportion, type = 'bar', colors=~class_prediction, name = ~class_prediction) %>%
layout(yaxis = list(title = 'Proportion', range=c(0,1)), barmode = 'group')
predicted class memberhip by CLASS
df %>%
group_by(class_prediction) %>%
count(CLASS) %>%
ungroup() %>%
mutate(proportion = n/sum(n)) %>%
plot_ly(x = ~CLASS, y = ~proportion, type = 'bar', colors=~class_prediction, name = ~class_prediction) %>%
layout(yaxis = list(title = 'Proportion', range=c(0,1)), barmode = 'group')
predicted class memberhip by PARTYID
df %>%
group_by(class_prediction) %>%
count(PARTYID) %>%
ungroup() %>%
mutate(proportion = n/sum(n)) %>%
plot_ly(x = ~PARTYID, y = ~proportion, type = 'bar', colors=~class_prediction, name = ~class_prediction) %>%
layout(yaxis = list(title = 'Proportion', range=c(0,1)), barmode = 'stack')