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(gapminder)
library(readr)
library(ggplot2)
Data1 <- read_csv("~/Downloads/Abbreviated Dataset Labeled.csv")%>%
filter(PartyIdentification %in% c("Democrat","Republican"))
## Parsed with column specification:
## cols(
## .default = col_character(),
## NumChildren = col_double(),
## Immigr_Economy_GiveTake = col_double(),
## ft_fem_2017 = col_double(),
## ft_immig_2017 = col_double(),
## ft_police_2017 = col_double(),
## ft_dem_2017 = col_double(),
## ft_rep_2017 = col_double(),
## ft_evang_2017 = col_double(),
## ft_muslim_2017 = col_double(),
## ft_jew_2017 = col_double(),
## ft_christ_2017 = col_double(),
## ft_gays_2017 = col_double(),
## ft_unions_2017 = col_double(),
## ft_altright_2017 = col_double(),
## ft_black_2017 = col_double(),
## ft_white_2017 = col_double(),
## ft_hisp_2017 = col_double()
## )
## See spec(...) for full column specifications.
head(Data1)
## # A tibble: 6 x 53
## gender race education familyincome children region urbancity Vote2012
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Female White 4-year Prefer not … No West Suburb Barack …
## 2 Female White Some Col… $60K-$69,999 No West Rural Ar… Mitt Ro…
## 3 Male White High Sch… $50K-$59,999 No Midwe… City Mitt Ro…
## 4 Male White 4-year $40K-$49,999 No South Suburb Mitt Ro…
## 5 Female White 2-year $30K-$39,999 No West Suburb Barack …
## 6 Female Black Post Grad $120K-$149,… Yes South City Barack …
## # … with 45 more variables: Vote2016 <chr>, TrumpSanders <chr>,
## # PartyRegistration <chr>, PartyIdentification <chr>,
## # PartyIdentification2 <chr>, PartyIdentification3 <chr>,
## # NewsPublicAffairs <chr>, DemPrimary <chr>, RepPrimary <chr>,
## # ImmigrantContributions <chr>, ImmigrantNaturalization <chr>,
## # ImmigrationShouldBe <chr>, Abortion <chr>, GayMarriage <chr>,
## # DeathPenalty <chr>, DeathPenaltyFreq <chr>, TaxWealthy <chr>,
## # Healthcare <chr>, GlobWarmExist <chr>, GlobWarmingSerious <chr>,
## # AffirmativeAction <chr>, Religion <chr>, ReligiousImportance <chr>,
## # ChurchAttendance <chr>, PrayerFrequency <chr>, NumChildren <dbl>,
## # areatype <chr>, GunOwnership <chr>, EconomyBetterWorse <chr>,
## # Immigr_Economy_GiveTake <dbl>, ft_fem_2017 <dbl>, ft_immig_2017 <dbl>,
## # ft_police_2017 <dbl>, ft_dem_2017 <dbl>, ft_rep_2017 <dbl>,
## # ft_evang_2017 <dbl>, ft_muslim_2017 <dbl>, ft_jew_2017 <dbl>,
## # ft_christ_2017 <dbl>, ft_gays_2017 <dbl>, ft_unions_2017 <dbl>,
## # ft_altright_2017 <dbl>, ft_black_2017 <dbl>, ft_white_2017 <dbl>,
## # ft_hisp_2017 <dbl>
Download the updated March Voter data that is provided in the course info section of blackboard.
Identify two groups of respondents who can be segmented from the voter data according to one of the variables in the dataset.
Examples:
Trump vs. Hillary Voters - Identifiable via Vote2016 variable Democrats vs Republicans - Identifiable via PartyIdentification variable Male vs. Female Respondents - Identifiable via gender variable Using the dplyr package, the table() and prop.table() commands, investigate how your two groups differ on at least 5 different factors.
3 of the variables that you use to compare your two groups, should be categorical/nominal. For these categorical variables, you should generate cross-tabs to study how responses distribute across combinations of categories. 2 of the variables that you use to compare your two groups, should be continuous/numerical. For these continuous variables, you should compare average values between your two groups. Example (You cannot use this as your paper topic…)
Comparing Male vs Female American Adults on Social Attitudes.
M v F support for immigrant naturalization M v F comparison of average 0-100 feeling towards immigrants M v F support for gay marriage M v F comparison of average 0-100 feeling towards gays/lesbians M v F support for Abortion Legalization M v F comparison of average 0-100 feeling towards feminists For every table that is produced, you should write 1-2 sentences interpreting your table. Each table should be produced in a separate R chunk, each which has a header, and interpretive text leading up to the R chunk to describe the table being presented.
Post on Rpubs, and post your Rpubs link here. Topics about Religion that other party members might discuss about, and believe in.
#Compare the average 0-100 feeling towards religion, specifically, Christianity (ft_christ_2017) for Democracts & Republicans (PartyIdentification)
Data1 %>%
filter(PartyIdentification %in% c("Democrat","Republican")) %>%
group_by(PartyIdentification)%>%
summarize(AVG = mean(ft_christ_2017, na.rm=TRUE))
## # A tibble: 2 x 2
## PartyIdentification AVG
## <chr> <dbl>
## 1 Democrat 63.8
## 2 Republican 85.4
When asked to rate Christians on a scale from 0 to 100, Democrats gave an average rating of 63.8, and Republicans gave an average score of 85.4. This indicates that Republicans feel more favorably towards Christians than Democrats do.
#Compare the average 0-100 feeling towards being religion, specifically, Islam (ft_muslim_2017) for Democracts & Republicans (PartyIdentification)
Data1 %>%
filter(PartyIdentification %in% c("Democrat","Republican")) %>%
group_by(PartyIdentification)%>%
summarize(AVG = mean(ft_muslim_2017, na.rm=TRUE))
## # A tibble: 2 x 2
## PartyIdentification AVG
## <chr> <dbl>
## 1 Democrat 62.8
## 2 Republican 34.8
When asked to rate Muslims on a scale from 0 to 100, Democrats gave an average rating of 62.8, and Republicans gave an average score of 34.8. This indicates that Democrats feel more favorably towards Muslims than Republican do.
#Compare the average 0-100 feeling towards if Religion is important for Democracts & Republicans (PartyIdentification).
Data1 %>%
filter(PartyIdentification %in% c("Democrat","Republican")) %>%
group_by(PartyIdentification,ReligiousImportance) %>%
summarize(n=n())%>%
mutate(PERCENT=n/sum(n))
## # A tibble: 10 x 4
## # Groups: PartyIdentification [2]
## PartyIdentification ReligiousImportance n PERCENT
## <chr> <chr> <int> <dbl>
## 1 Democrat Not at all Important 748 0.249
## 2 Democrat Not too Important 473 0.157
## 3 Democrat Somewhat Important 753 0.251
## 4 Democrat Very Important 1023 0.341
## 5 Democrat <NA> 7 0.00233
## 6 Republican Not at all Important 177 0.0766
## 7 Republican Not too Important 280 0.121
## 8 Republican Somewhat Important 645 0.279
## 9 Republican Very Important 1206 0.522
## 10 Republican <NA> 3 0.00130
table(Data1$ReligiousImportance,Data1$PartyIdentification)%>%
prop.table(2)
##
## Democrat Republican
## Not at all Important 0.24958292 0.07668977
## Not too Important 0.15782449 0.12131716
## Somewhat Important 0.25125125 0.27946274
## Very Important 0.34134134 0.52253033
In this data, it is comparing the feelings and opinion about Democrats and Republicans on if Religion is important to them from 0 to 100. For those who chose that religion is “Not at all Important”, the Democrats(.2495) favored this choice more than Republican (.0766). For those who chose that religion is “Not too Important”, the Democrats(.1578) favored this choice more than Republican (.1213). For those who chose that religion is “Somewhat Important”, the Republican(.2794) favored this choice more than Democrats (.2512). For those who chose that religion is “Very Important”, the Republicans(.5225) favored this choice more than Democrats (.3413).
#Compare the average 0-100 feeling towards Church Attendance(ChurchAttendance) for Democrats & Republicans (PartyIdentification)
Data1 %>%
filter(PartyIdentification %in% c("Democrat","Republican")) %>%
group_by(PartyIdentification,ChurchAttendance) %>%
summarize(n=n())%>%
mutate(PERCENT=n/sum(n))
## # A tibble: 16 x 4
## # Groups: PartyIdentification [2]
## PartyIdentification ChurchAttendance n PERCENT
## <chr> <chr> <int> <dbl>
## 1 Democrat A few times a year 397 0.132
## 2 Democrat Don't Know 28 0.00932
## 3 Democrat More than once a week 178 0.0593
## 4 Democrat Never 993 0.331
## 5 Democrat Once a week 456 0.152
## 6 Democrat Once or twice a month 226 0.0752
## 7 Democrat Seldom 717 0.239
## 8 Democrat <NA> 9 0.00300
## 9 Republican A few times a year 319 0.138
## 10 Republican Don't Know 18 0.00779
## 11 Republican More than once a week 292 0.126
## 12 Republican Never 381 0.165
## 13 Republican Once a week 600 0.260
## 14 Republican Once or twice a month 195 0.0844
## 15 Republican Seldom 501 0.217
## 16 Republican <NA> 5 0.00216
table(Data1$ChurchAttendance,Data1$PartyIdentification)%>%
prop.table(2)
##
## Democrat Republican
## A few times a year 0.132554257 0.138334779
## Don't Know 0.009348915 0.007805724
## More than once a week 0.059432387 0.126626193
## Never 0.331552588 0.165221162
## Once a week 0.152253756 0.260190807
## Once or twice a month 0.075459098 0.084562012
## Seldom 0.239398998 0.217259324
In this data, it is comparing the feelings and opinion about Democrats and Republicans on whether or not if they attend church. When it asked for the rate of attending to Church from 0 to 100 according to the Democrats and Republicans, the Democrats (13.26 % or .1325) and Republican (13.83% to .1383) to go to church “a few times a year”, which shows that Republican favor this decision more than Democrats. For those who chose “Don’t Know” option, the Democrats(.093% or .0093) favored it more than the Republicans(.078% or .0078). For those who chose “More than once a week” option, the Republicans(12.66% or .1266) favored it more than Democrats(5.94% or .0594). For those who chose “Never” option, the Democrats(33.15% or .3315) favored this option more than Republicans(16.52% or .1652). For those who chose “Once a week”, the Republicans(26.01% or .2601) favored this option more than Democrats (15.22% or .1522). For those who chose “Once or twice a month”, the Republicans(8.45% or .0845) favored this option more than Democrats(7.54% or .0754). For those who chose “Seldom”, the Democrat(23.93% or .2393) favored this option more than Republicans(21.72% or .2172).
#Compare the feeling towards Prayer Frequency (PrayerFrequency) for Democrats & Republicans (PartyIdentification)
Data1 %>%
filter(PartyIdentification %in% c("Democrat","Republican")) %>%
group_by(PartyIdentification,PrayerFrequency) %>%
summarize(n=n())%>%
mutate(PERCENT=n/sum(n))
## # A tibble: 18 x 4
## # Groups: PartyIdentification [2]
## PartyIdentification PrayerFrequency n PERCENT
## <chr> <chr> <int> <dbl>
## 1 Democrat A few times a month 185 0.0616
## 2 Democrat A few times a week 406 0.135
## 3 Democrat Don't know 70 0.0233
## 4 Democrat Never 578 0.192
## 5 Democrat Once a day 443 0.147
## 6 Democrat Once a week 56 0.0186
## 7 Democrat Seldom 432 0.144
## 8 Democrat Several times a day 826 0.275
## 9 Democrat <NA> 8 0.00266
## 10 Republican A few times a month 168 0.0727
## 11 Republican A few times a week 346 0.150
## 12 Republican Don't know 25 0.0108
## 13 Republican Never 148 0.0640
## 14 Republican Once a day 421 0.182
## 15 Republican Once a week 43 0.0186
## 16 Republican Seldom 285 0.123
## 17 Republican Several times a day 866 0.375
## 18 Republican <NA> 9 0.00389
table(Data1$PrayerFrequency,Data1$PartyIdentification)%>%
prop.table(2)
##
## Democrat Republican
## A few times a month 0.06174900 0.07298002
## A few times a week 0.13551402 0.15030408
## Don't know 0.02336449 0.01086012
## Never 0.19292390 0.06429192
## Once a day 0.14786382 0.18288445
## Once a week 0.01869159 0.01867941
## Seldom 0.14419226 0.12380539
## Several times a day 0.27570093 0.37619461
In this data, it is comparing the feeling and opinions about how frequent they pray between the Democrat Party and Republican Party. When it asked for the rate of Frequency of Prayer from 0 to 100 according to the Democrats and Republicans, the Democrats (.0617) and Republican (.0729) to go to church “a few times a month”, which shows that Republican favor this decision more than Democrats. For those who chose “A few times a week” option, the Republicans(.1503) favored it more than the Democrats(.1355). For those who chose “Don’t know” option, the Democrats(.0233) favored it more than Republicans(.0108). For those who chose “Never” option, the Democrats(.1929) favored this option more than Republicans(.0642). For those who chose “Once a day”, the Republicans(.1828) favored this option more than Democrats (.1478). For those who chose “Once a week”, the Democrats(.01869) favored this option more than Republicans(.01867). For those who chose “Seldom”, the Democrat(.1441) favored this option more than Republicans(.1238). For those who chose “Several times a day”, the Republicans(.3761) favored this option more than Democrats (.2757).