Saturday, March 12, 2016

The failed "Southern Strategy" of the Democrats


Political piece here.



# Primaries.r 
# Using AP Data from Google for Primaries
# Can be run source("Primaries.r") for cat/print of data and chart
print("Democrat Primaries/Caucuses as of 3:59 PM 3/11/2016")
cat('
DemPrimary_001.csv
State,Type,T_Delegates,B_Del,B_Votes,H_Del,H_Votes
Iowa,C,44,21,697,23,701
New Hampshire,P,24,15,151584,9,95252
Nevada,C,35,15,5678,20,6316
South Carolina,P,53,14,95977,39,271514
Alabama,P,53,9,76399,44,309928
Arkansas,P,32,10,64868,22,144580
Colorado,C,66,38,72115,28,49314
Georgia,P,102,28,214332,72,543008
Massachusetts,P,91,45,586716,46,603784
Minnesota,C,77,46,118135,31,73510
Oklahoma,P,38,21,174054,17,139338
Tennessee,P,67,23,120333,44,245304
Texas,P,222,74,475561,147,935080
Vermont,P,16,16,115863,0,1833
Virginia,P,95,33,275507,62,503358
Kansas,C,33,24,26450,9,12593
Louisiana,P,51,14,72240,37,221615
Nebraska,C,25,15,19120,10,14340
Maine,C,25,15,2231,8,1232
Michigan,P,130,67,595222,60,576795
Mississippi,P,36,4,36348,30,182447
')
print(" ")
print("All Caucuses and Primaries together:")
colSums(subset(read.csv("C:/Politics/Bernie/DemPrimary_001.csv"))[,3:7],na.rm=TRUE)
cat('
T_Delegates       B_Del     B_Votes       H_Del     H_Votes 
       1315         547     3299430         758     4931842 
')

print("Just Primaries:")
colSums(subset(read.csv("C:/Politics/Bernie/DemPrimary_001.csv"),Type == "P")[,3:7],na.rm=TRUE)
cat('
T_Delegates       B_Del     B_Votes       H_Del     H_Votes 
       1010         373     3055004         629     4773836
')

print("Just Caucuses:")
colSums(subset(read.csv("C:/Politics/Bernie/DemPrimary_001.csv"),Type == "C")[,3:7],na.rm=TRUE)
cat('
T_Delegates       B_Del     B_Votes       H_Del     H_Votes 
        305         174      244426         129      158006
')

# merge Primary with CVAP
# For this need Census Data:
# https://www.census.gov/rdo/data/voting_age_population_by_citizenship_and_race_cvap.html
# download(https://www.census.gov/rdo/pdf/CVAP_CSV_Format_2010-2014.zip)

library(data.table)
DemP <- fread("C:/Politics/Bernie/DemPrimary_001.csv")
setkey(DemP,State)
cvap14 <- fread("C:/Politics/CVAP_CSV_Format_2010-2014/State.csv")
cvap14 <- cbind("ROW"=as.numeric(rownames(cvap14)),cvap14)
setkey(cvap14,ROW)
cvapState <- cvap14[LNTITLE == "Total"]
cvapState$State <- cvapState$GEONAME
setkey(cvapState,State)
merge1 <- merge(DemP,cvapState,by="State")
# with(merge1,(B_Votes + H_Votes)/(.5 * CVAP_EST))
StateT <- data.table(with(merge1[Type=="P"],cbind(State,"TO" = ((B_Votes + H_Votes)/(CVAP_EST)))))
StateT <- arrange(StateT,desc(TO))
with(StateT,cbind(State,scales::percent(as.numeric(TO))))
# print("Sum Democrat (non caucus) Primary Votes / Census CVAP or Citizens Voting Age Population 2014")
cat('
      State                   
 [1,] "Massachusetts"  "24.8%"
 [2,] "New Hampshire"  "24.4%"
 [3,] "Vermont"        "23.9%"
 [4,] "Michigan"       "16.0%"
 [5,] "Virginia"       "13.3%"
 [6,] "Oklahoma"       "11.4%"
 [7,] "Georgia"        "11.0%"
 [8,] "Alabama"        "10.7%"
 [9,] "South Carolina" "10.5%"
[10,] "Mississippi"    "9.9%" 
[11,] "Arkansas"       "9.7%" 
[12,] "Louisiana"      "8.7%" 
[13,] "Texas"          "8.5%" 
[14,] "Tennessee"      "7.6%" 
')

with(StateT,barplot(as.numeric(TO), names.arg=State,cex.names=.65,las=2,col=rainbow(nrow(StateT))))
mtext("Combined Democrat (non Caucus) Primary Votes / Citizens of Voting Age (CVAP_EST 2014)", cex=1.25)

No comments:

Post a Comment