#Introduction ##The city of Cincinnati has commissioned Blair McKee to perform an analysis on the shifting political climate in the Cincinnati region from 2015 to the present day. One such means of accomplishing this is by using data from the Federal Election Commission (FEC), which is one of many federal organizations responsible for collecting and reporting money in politics. Part of the data collected and reported by the FEC includes all monetary contributions made by individuals to politically affiliated organizations.
#Packages library(tidyverse) library(skimr) install.packages(“sqldf”) library(“sqldf”) library(dplyr)
#Data politics <- read_csv(“https://myxavier-my.sharepoint.com/:x:/g/personal/mckeeb_xavier_edu/EUt3FSidj7BFl6zDm7v4_egBNhkk2GsGXklSiFDDD0mQQg?download=1”)
#Data Cleaning and Summary politics\(contribution_receipt_date <- as.Date(politics\)contribution_receipt_date) sum(is.na(politics)) colSums(is.na(politics))
politics\(contributor_employer <- replace(politics\)contributor_employer, politics\(contributor_employer == "N/A" , NA) politics\)employer <- replace(politics\(contributor_employer,politics\)contributor_employer == “NONE”, NA) politics\(contributor_occupation <- replace(politics\)contributor_occupation,politics\(contributor_occupation == "N/A" , NA) politics\)contributor_employer <- replace(politics\(contributor_employer,politics\)contributor_employer == “NOT EMPLOYED”, NA) politics\(contributor_employer <-replace(politics\)contributor_employer,politics$contributor_employer == “SELF-EMPLOYED”, “SELF EMPLOYED”)
options(scipen=10) summary(politics) ##Many of the contributors did not report their employer or their occupation. This could be because they did not want their party or contributions to be associated with their jobs. For that reason, I will not omit their data from the analysis. ##The average contribution amount is $354.80.
#Directed Analysis ##Which employers are most heavily represented in the data? politics %>% filter(!contributor_employer %in% c(“NONE”,“NOT EMPLOYED”, NA, “RETIRED”,“SELF EMPLOYED”, “SELF”)) %>% group_by(contributor_employer) %>% summarise(count = n()) %>% filter(count > 100) %>% ggplot(politics, mapping = aes(x = contributor_employer, y = count)) + geom_histogram(stat = “identity”, fill = “orange”) + theme(axis.text.x = element_text(angle = 45, hjust = 1))
##What percent of money contributed in Cincinnati benefits Democrats? Republicans? All others?"
sum(politics$contribution_receipt_amount, na.rm = TRUE)
politics %>% filter(committee_party_affiliation %in% c(“DEMOCRATIC PARTY”, “REPUBLICAN PARTY”, “INDEPENDENT”, “LIBERTARIAN PARTY”, “GREEN PARTY”)) %>% group_by(committee_party_affiliation) %>% summarise( 9372506 / sum(politics\(contribution_receipt_amount, na.rm = TRUE), 7677 / sum(politics\)contribution_receipt_amount, na.rm = TRUE), 23986 / sum(politics\(contribution_receipt_amount, na.rm = TRUE), 12027 / sum(politics\)contribution_receipt_amount, na.rm = TRUE), 10918231 / sum(politics$contribution_receipt_amount, na.rm = TRUE))
democrat_percent <- 9372506 / sum(politics\(contribution_receipt_amount, na.rm = TRUE) republican_percent <- 10918231 / sum(politics\)contribution_receipt_amount, na.rm = TRUE) ggplot(data = politics, aes(x = committee_party_affiliation, y = contribution_receipt_amount)) + geom_point() + theme(axis.text.x = element_text(angle = 45, hjust = 1)
##About 46% of money contributed in Cincinnati benefits Democrats, and 53% benefits Republicans. Less than 1% of all money is distributed across all other parties.
#Self-Directed Analysis ##Which occupations give the highest average monetary contributions?
sqldf(“SELECT contributor_occupation, avg(contribution_receipt_amount) AS Highest Average Contribution from politics GROUP BY contributor_occupation ORDER BY avg(contribution_receipt_amount) DESC LIMIT 10”)%>% ggplot(aes(x= contributor_occupation , y = Highest Average Contribution)) + geom_bar(stat=“identity”, fill = “green”) + theme(axis.text.x = element_text(angle = 45, hjust = 1))
##I conducted a sql query using the sqldf package to find the Top 10 occupations with the highest average contributions. The results were Government Relations Specialist and Park Attendants are the occupations with the highest contributions. The City of Cincinnati can use this information to target people in these specific occupations and ask for their help with increasing political involvement. Political activists might also target individuals in this occupation to raise money for political campaigns.
echo=false