Skip to content
No description, website, or topics provided.
R
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README_files/figure-markdown_strict
.gitignore Init Feb 5, 2020
County Level Analysis.R
Delegate Apportionment_Page 1_Pivot table.csv
Delegate_Apportionment.pdf
Iowa Caucus Inconsistencies.Rproj
Precincts.R
README.md
cleaned_iowa_dems_data.csv
cleaned_nyt_results.csv
cleaned_nyt_results2020-02-06 10:50:53.csv
cleaned_nyt_results2020-02-06 11:00:43.csv some script updates Feb 11, 2020
cleaned_nyt_results2020-02-06 11:33:24.csv
iowa_dems_data_cleaning.R
iowa_precinct_results.csv
iowadems_resumts_0205_8PM.csv
theme_powerbi.R
viable_to_nonviable_analysis.R

README.md

library(rvest)
library(tidyverse)
library(tidycensus)
library(httr)
library(reshape2)

source("./theme_powerbi.R")

# Pull in precinct data from NYT latest endpoint

precincts <- GET("https://int.nyt.com/applications/elections/2020/data/api/2020-02-03/precincts/IowaDemPrecinctsSFTP-latest.json") %>% content()


precincts <- precincts$precincts %>% 
  map_if(negate(is.list), function(x) flatten_chr(x)) %>% 
  enframe()


results <- precincts$value %>% map("results") %>% bind_rows()
results_first_alignment <- precincts$value %>% map("results_align1") %>% bind_rows()
results_final_alignment <- precincts$value %>% map("results_alignfinal") %>% bind_rows()

## Ugly but doing it on the fly
precinct_details <- precincts$value %>% 
  map(function(x) keep(x, negate(is.list))) %>% 
  map(bind_rows) %>% map(sapply, as.character) %>% 
  map(bind_rows) %>% bind_rows()

precinct_details <- precinct_details %>% 
  mutate(precinct = paste0(precinct, "-", precinct_id))


precinct_names <- precinct_details %>% 
  select(precinct, is_complete)


## Combine first alignment results with precinct details
first_alignment_results <- results_first_alignment %>% bind_cols(precinct_names) %>%
  melt(id.vars = c("precinct", "is_complete")) %>% rename(candidate = variable, votes_first = value) %>%
  group_by(precinct) %>% mutate(total_first = sum(votes_first)) %>%
  group_by(precinct, candidate) %>% mutate(percent_first = votes_first/total_first) %>%
  mutate(candidate_not_viable_first = ifelse(percent_first < .15, TRUE, FALSE)) %>%
  group_by(candidate) %>%
  ungroup() 


## Same same with final results
final_alignment_results <- results_final_alignment %>% bind_cols(precinct_names)  %>%
  melt(id.vars = c("precinct", "is_complete")) %>% rename(candidate = variable, votes_final = value) %>%
  group_by(precinct) %>% mutate(total_final = sum(votes_final)) %>%
  group_by(precinct, candidate) %>% mutate(percent_final = votes_final/total_final) %>%
  mutate(candidate_viable_final = ifelse(percent_final > .15, TRUE, FALSE)) %>%
  ungroup() 


results_full <- first_alignment_results %>%
  left_join(final_alignment_results, by = c("precinct", "candidate", "is_complete")) %>%
  mutate(change_from_first = votes_final - votes_first)


viability <- results_full %>% filter(is_complete == "TRUE") %>%
  select(precinct, candidate, candidate_not_viable_first) %>%
  mutate(candidate = paste0(candidate, "_not_viable_after_first")) %>%
  dcast(precinct ~ candidate)


change_between_rounds <- results_full %>% 
  filter(is_complete == "TRUE") %>%
  select(precinct, candidate, change_from_first) %>%
  mutate(candidate = paste0(candidate, "_change")) %>%
  dcast(precinct~candidate)

Iowa Weirdness

I posted a thread on Twitter (https://twitter.com/SethYefrican/status/1224982241740091392?s=20) highlighting some strange data discrepancies between the precinct level vote counts in the first and final alignment of the Iowa Caucus. These are:

  • Indianola 2 - (precinct == “IN2-948050”) in the data
  • Deval Patrick’s 41 votes apparently moving to Bernie Sanders in final round, with Bernie having 0 in the first
  • Tom Steyer’s 50 votes moving to Elizabeth Warren in the final round, with Warren having 0 in the first
  • Council Bluffs 12 - (precinct == “CB 12-947794”)
  • Michael Bloomberg’s 24 votes moving to Buttigieg in the final round, with Buttigieg having 0 in the first

These observations and others with similar patterns (that I have not had the time to fully validate) are available in the table below. Feel free to snoop and update the thread with anything you see.

## Coded few conditions that might be of interest.
results_full %>% 
  group_by(precinct) %>% 
  mutate(unviable_to_viable = ifelse((candidate_not_viable_first & candidate_viable_final & 
                                        !candidate %in% c("other", "uncommitted")), TRUE, FALSE),
         viable_to_unviable = ifelse((!candidate_not_viable_first & !candidate_viable_final & 
                                        !candidate %in% c("other", "uncommitted")), TRUE, FALSE),
         zero_votes_to_nonzero_votes = ifelse((votes_first == 0 & votes_final > 0), TRUE, FALSE),
         viable_to_zero_votes = ifelse((!candidate_not_viable_first & votes_final == 0 & 
                                          !candidate %in% c("other", "uncommitted")), TRUE, FALSE)) %>%
  group_by(precinct) %>% arrange(precinct, candidate) %>% 
  mutate(mickey_mouse_shit = ifelse((zero_votes_to_nonzero_votes|viable_to_zero_votes), TRUE, FALSE)) %>%
                  group_by(precinct) %>%  
  mutate(precincts_with_mms = max(mickey_mouse_shit)) %>% 
  filter(precincts_with_mms == 1) %>% 
  arrange(precinct, candidate) %>% 
  select(viable_to_zero_votes, zero_votes_to_nonzero_votes, viable_to_unviable,
         unviable_to_viable, everything()) %>% 
  filter(viable_to_zero_votes & !candidate %in% c("other", "uncommitted")) %>% 
  knitr::kable(caption = "Cases of Viable Candidates Receiving 0 Votes in Final Tally")
Cases of Viable Candidates Receiving 0 Votes in Final Tally
viable_to_zero_votes zero_votes_to_nonzero_votes viable_to_unviable unviable_to_viable precinct is_complete candidate votes_first total_first percent_first candidate_not_viable_first votes_final total_final percent_final candidate_viable_final change_from_first mickey_mouse_shit precincts_with_mms
TRUE FALSE TRUE FALSE 1 BA-LS-1593688 TRUE warrene 5 28 0.1785714 FALSE 0 28 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE 12-946730 TRUE klobuchara 5 20 0.2500000 FALSE 0 20 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE 13-947157 TRUE buttigiegp 8 37 0.2162162 FALSE 0 29 0 FALSE -8 TRUE 1
TRUE FALSE TRUE FALSE 2-947146 TRUE sandersb 7 42 0.1666667 FALSE 0 42 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE 2-947842 TRUE klobuchara 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE 2-947842 TRUE warrene 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE 24-947957 TRUE bidenj 19 112 0.1696429 FALSE 0 93 0 FALSE -19 TRUE 1
TRUE FALSE TRUE FALSE 3 GC-947480 TRUE warrene 5 27 0.1851852 FALSE 0 27 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE 30-947964 TRUE bidenj 16 87 0.1839080 FALSE 0 83 0 FALSE -16 TRUE 1
TRUE FALSE TRUE FALSE 31-947965 TRUE bidenj 18 106 0.1698113 FALSE 0 88 0 FALSE -18 TRUE 1
TRUE FALSE TRUE FALSE 34-947968 TRUE klobuchara 7 43 0.1627907 FALSE 0 43 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE 35-947969 TRUE sandersb 7 37 0.1891892 FALSE 0 37 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE 36-948169 TRUE buttigiegp 4 25 0.1600000 FALSE 0 18 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE 36-948169 TRUE warrene 6 25 0.2400000 FALSE 0 18 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE 37-946977 TRUE warrene 5 33 0.1515152 FALSE 0 33 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE 41-947976 TRUE buttigiegp 17 87 0.1954023 FALSE 0 86 0 FALSE -17 TRUE 1
TRUE FALSE TRUE FALSE 42-947977 TRUE buttigiegp 2 9 0.2222222 FALSE 0 9 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE 42-947977 TRUE sandersb 2 9 0.2222222 FALSE 0 9 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE 42-948175 TRUE sandersb 2 9 0.2222222 FALSE 0 9 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE 43-947978 TRUE bidenj 15 90 0.1666667 FALSE 0 63 0 FALSE -15 TRUE 1
TRUE FALSE TRUE FALSE 43-947978 TRUE warrene 23 90 0.2555556 FALSE 0 63 0 FALSE -23 TRUE 1
TRUE FALSE TRUE FALSE 5-947845 TRUE bidenj 2 11 0.1818182 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE 5-947845 TRUE klobuchara 2 11 0.1818182 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE 6 LB-MI-1593700 TRUE bidenj 4 22 0.1818182 FALSE 0 22 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE 7 MA-WA-1593701 TRUE warrene 3 20 0.1500000 FALSE 0 20 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE AD-947268 TRUE klobuchara 3 14 0.2142857 FALSE 0 14 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE AD-947268 TRUE sandersb 3 14 0.2142857 FALSE 0 14 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE AD-947443 TRUE buttigiegp 3 11 0.2727273 FALSE 0 8 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE AD-947443 TRUE sandersb 2 11 0.1818182 FALSE 0 8 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE ADS-1593466 TRUE bidenj 15 75 0.2000000 FALSE 0 75 0 FALSE -15 TRUE 1
TRUE FALSE TRUE FALSE AL2-1593468 TRUE klobuchara 29 190 0.1526316 FALSE 0 175 0 FALSE -29 TRUE 1
TRUE FALSE TRUE FALSE BG-947194 TRUE buttigiegp 35 167 0.2095808 FALSE 0 68 0 FALSE -35 TRUE 1
TRUE FALSE TRUE FALSE BG-947194 TRUE warrene 39 167 0.2335329 FALSE 0 68 0 FALSE -39 TRUE 1
TRUE FALSE TRUE FALSE BN-946737 TRUE klobuchara 3 12 0.2500000 FALSE 0 12 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE BO-947088 TRUE bidenj 3 19 0.1578947 FALSE 0 19 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE BO-947444 TRUE klobuchara 4 19 0.2105263 FALSE 0 19 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE CARSON-947805 TRUE bidenj 3 16 0.1875000 FALSE 0 16 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE CB 12-947794 TRUE bloombergm 24 119 0.2016807 FALSE 0 119 0 FALSE -24 TRUE 1
TRUE FALSE TRUE FALSE CE-947196 TRUE warrene 12 65 0.1846154 FALSE 0 65 0 FALSE -12 TRUE 1
TRUE FALSE TRUE FALSE CEDAR-948229 TRUE bidenj 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE CEDAR-948229 TRUE warrene 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE CENT-946829 TRUE warrene 3 14 0.2142857 FALSE 0 14 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE CL-948284 TRUE warrene 3 20 0.1500000 FALSE 0 17 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE CLAY 1-947721 TRUE sandersb 12 72 0.1666667 FALSE 0 64 0 FALSE -12 TRUE 1
TRUE FALSE TRUE FALSE CLAY 1-947721 TRUE warrene 13 72 0.1805556 FALSE 0 64 0 FALSE -13 TRUE 1
TRUE FALSE TRUE FALSE CM WDM-1593777 TRUE klobuchara 9 36 0.2500000 FALSE 0 27 0 FALSE -9 TRUE 1
TRUE FALSE TRUE FALSE CROCK 2-1593721 TRUE bidenj 20 132 0.1515152 FALSE 0 111 0 FALSE -20 TRUE 1
TRUE FALSE TRUE FALSE CRONNOC-1593767 TRUE bidenj 2 13 0.1538462 FALSE 0 13 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE CRONNOC-1593767 TRUE klobuchara 2 13 0.1538462 FALSE 0 13 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE CW-946561 TRUE sandersb 2 13 0.1538462 FALSE 0 13 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE CW-946561 TRUE warrene 3 13 0.2307692 FALSE 0 13 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE DA-947134 TRUE buttigiegp 4 24 0.1666667 FALSE 0 24 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE DEL 2-947728 TRUE bidenj 2 13 0.1538462 FALSE 0 13 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE DM-947185 TRUE klobuchara 4 17 0.2352941 FALSE 0 17 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE DM 048-947649 TRUE buttigiegp 6 38 0.1578947 FALSE 0 30 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE DM 074-947675 TRUE warrene 12 75 0.1600000 FALSE 0 75 0 FALSE -12 TRUE 1
TRUE FALSE TRUE FALSE DV-947003 TRUE klobuchara 3 14 0.2142857 FALSE 0 14 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE ED-947446 TRUE bidenj 2 11 0.1818182 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE ED-947446 TRUE sandersb 2 11 0.1818182 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE ELMYVO-948246 TRUE buttigiegp 5 31 0.1612903 FALSE 0 31 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE ELMYVO-948246 TRUE warrene 5 31 0.1612903 FALSE 0 31 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE EM-947488 TRUE sandersb 4 15 0.2666667 FALSE 0 12 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE F1-947526 TRUE buttigiegp 7 45 0.1555556 FALSE 0 37 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE FC 4-948317 TRUE sandersb 7 43 0.1627907 FALSE 0 43 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE G000-1593427 TRUE buttigiegp 3 12 0.2500000 FALSE 0 1 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE GFHD-946806 TRUE buttigiegp 3 16 0.1875000 FALSE 0 14 0 FALSE -3 TRUE 1
TRUE FALSE NA FALSE GR-947204 TRUE bidenj 10 54 0.1851852 FALSE 0 0 NaN NA -10 TRUE 1
TRUE FALSE NA FALSE GR-947204 TRUE buttigiegp 11 54 0.2037037 FALSE 0 0 NaN NA -11 TRUE 1
TRUE FALSE NA FALSE GR-947204 TRUE klobuchara 13 54 0.2407407 FALSE 0 0 NaN NA -13 TRUE 1
TRUE FALSE NA FALSE GR-947204 TRUE sandersb 9 54 0.1666667 FALSE 0 0 NaN NA -9 TRUE 1
TRUE FALSE TRUE FALSE GRAVITY-1593773 TRUE bidenj 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE GREENFI-948232 TRUE bidenj 2 9 0.2222222 FALSE 0 9 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE GREENFI-948232 TRUE warrene 2 9 0.2222222 FALSE 0 9 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE GT-947596 TRUE klobuchara 2 10 0.2000000 FALSE 0 10 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE HA-947560 TRUE bidenj 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE HA-947560 TRUE sandersb 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE HD-947205 TRUE buttigiegp 12 55 0.2181818 FALSE 0 55 0 FALSE -12 TRUE 1
TRUE FALSE TRUE FALSE HD-947205 TRUE sandersb 10 55 0.1818182 FALSE 0 55 0 FALSE -10 TRUE 1
TRUE FALSE TRUE FALSE HJ-946945 TRUE bidenj 9 37 0.2432432 FALSE 0 37 0 FALSE -9 TRUE 1
TRUE FALSE TRUE FALSE HS-1593580 TRUE warrene 12 68 0.1764706 FALSE 0 68 0 FALSE -12 TRUE 1
TRUE FALSE TRUE FALSE IG2-947131 TRUE klobuchara 3 12 0.2500000 FALSE 0 12 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE IN-947455 TRUE bidenj 4 22 0.1818182 FALSE 0 22 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE IN2-948050 TRUE patrickd 41 199 0.2060302 FALSE 0 190 0 FALSE -41 TRUE 1
TRUE FALSE TRUE FALSE IN2-948050 TRUE steyert 50 199 0.2512563 FALSE 0 190 0 FALSE -50 TRUE 1
TRUE FALSE TRUE FALSE JF-947008 TRUE sandersb 4 26 0.1538462 FALSE 0 26 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE LB-947233 TRUE warrene 10 63 0.1587302 FALSE 0 61 0 FALSE -10 TRUE 1
TRUE FALSE TRUE FALSE LB-947461 TRUE warrene 3 16 0.1875000 FALSE 0 15 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE LB-947903 TRUE buttigiegp 6 17 0.3529412 FALSE 0 15 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE LB-947903 TRUE klobuchara 3 17 0.1764706 FALSE 0 15 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE LCN-1593443 TRUE bidenj 6 29 0.2068966 FALSE 0 29 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE LCN-1593443 TRUE sandersb 5 29 0.1724138 FALSE 0 29 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE LGGG-946808 TRUE buttigiegp 2 11 0.1818182 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE LM-946821 TRUE warrene 4 16 0.2500000 FALSE 0 12 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE LS-947093 TRUE buttigiegp 2 7 0.2857143 FALSE 0 6 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE LW-946738 TRUE buttigiegp 5 27 0.1851852 FALSE 0 27 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE MADISON-1593727 TRUE bidenj 3 13 0.2307692 FALSE 0 13 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE MADISON-1593727 TRUE warrene 2 13 0.1538462 FALSE 0 13 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE MC-1593758 TRUE sandersb 9 42 0.2142857 FALSE 0 42 0 FALSE -9 TRUE 1
TRUE FALSE TRUE FALSE MC-1593758 TRUE warrene 11 42 0.2619048 FALSE 0 42 0 FALSE -11 TRUE 1
TRUE FALSE TRUE FALSE MC-947557 TRUE bidenj 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE MC-947557 TRUE klobuchara 1 5 0.2000000 FALSE 0 5 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE MCCLELL-1833332 TRUE warrene 4 23 0.1739130 FALSE 0 23 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE MV-946780 TRUE sandersb 3 15 0.2000000 FALSE 0 15 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE NE-948115 TRUE bidenj 1 6 0.1666667 FALSE 0 6 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE NE-948115 TRUE klobuchara 1 6 0.1666667 FALSE 0 6 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE NENP-948224 TRUE klobuchara 5 32 0.1562500 FALSE 0 22 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE NENP-948224 TRUE yanga 7 32 0.2187500 FALSE 0 22 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE NL-EV-1593573 TRUE sandersb 1 3 0.3333333 FALSE 0 2 0 FALSE -1 TRUE 1
TRUE FALSE TRUE FALSE OGCA-1593455 TRUE buttigiegp 6 31 0.1935484 FALSE 0 31 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE OR-947013 TRUE bidenj 3 15 0.2000000 FALSE 0 15 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE OR-947013 TRUE warrene 3 15 0.2000000 FALSE 0 15 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE OR-947541 TRUE warrene 3 14 0.2142857 FALSE 0 10 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE ORGM-1593456 TRUE warrene 6 28 0.2142857 FALSE 0 28 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE OT ML-1593785 TRUE warrene 9 55 0.1636364 FALSE 0 55 0 FALSE -9 TRUE 1
TRUE FALSE TRUE FALSE OX-947240 TRUE bidenj 19 112 0.1696429 FALSE 0 74 0 FALSE -19 TRUE 1
TRUE FALSE TRUE FALSE OX-947240 TRUE warrene 19 112 0.1696429 FALSE 0 74 0 FALSE -19 TRUE 1
TRUE FALSE TRUE FALSE OX-947263 TRUE buttigiegp 3 17 0.1764706 FALSE 0 17 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE P2-947426 TRUE sandersb 2 11 0.1818182 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE P3-947427 TRUE buttigiegp 3 17 0.1764706 FALSE 0 17 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE P4-947046 TRUE buttigiegp 4 23 0.1739130 FALSE 0 19 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE P5-947429 TRUE warrene 6 23 0.2608696 FALSE 0 23 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE PCT 04-1593517 TRUE bidenj 2 13 0.1538462 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE PCT 04-1593517 TRUE buttigiegp 2 13 0.1538462 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE PCT 04-1593517 TRUE warrene 2 13 0.1538462 FALSE 0 11 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE PCT 14-1593513 TRUE klobuchara 5 33 0.1515152 FALSE 0 33 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE PI-947542 TRUE sandersb 7 23 0.3043478 FALSE 0 23 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE POD-1593445 TRUE sandersb 5 31 0.1612903 FALSE 0 29 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE PR-947906 TRUE warrene 13 70 0.1857143 FALSE 0 70 0 FALSE -13 TRUE 1
TRUE FALSE TRUE FALSE PV-947905 TRUE bidenj 14 65 0.2153846 FALSE 0 47 0 FALSE -14 TRUE 1
TRUE FALSE TRUE FALSE PW-946947 TRUE buttigiegp 3 20 0.1500000 FALSE 0 20 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE RJO-1825047 TRUE klobuchara 4 17 0.2352941 FALSE 0 12 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE SB-948206 TRUE buttigiegp 2 13 0.1538462 FALSE 0 12 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE SB-948206 TRUE yanga 2 13 0.1538462 FALSE 0 12 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE SC-947015 TRUE bidenj 2 5 0.4000000 FALSE 0 5 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE SG1-947276 TRUE buttigiegp 3 20 0.1500000 FALSE 0 20 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE SG1-947276 TRUE sandersb 4 20 0.2000000 FALSE 0 20 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE SG2-947277 TRUE bidenj 8 26 0.3076923 FALSE 0 20 0 FALSE -8 TRUE 1
TRUE FALSE TRUE FALSE SG3-947278 TRUE yanga 2 13 0.1538462 FALSE 0 13 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE SG4-947279 TRUE bidenj 4 23 0.1739130 FALSE 0 23 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE SHLN-1593457 TRUE sandersb 4 21 0.1904762 FALSE 0 21 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE SHLN-1593457 TRUE warrene 5 21 0.2380952 FALSE 0 21 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE SRK-1593465 TRUE sandersb 3 20 0.1500000 FALSE 0 20 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE TBRO-1593664 TRUE bidenj 18 90 0.2000000 FALSE 0 71 0 FALSE -18 TRUE 1
TRUE FALSE TRUE FALSE TCLI-1593666 TRUE klobuchara 10 46 0.2173913 FALSE 0 46 0 FALSE -10 TRUE 1
TRUE FALSE TRUE FALSE TCOL-1593667 TRUE bidenj 9 46 0.1956522 FALSE 0 46 0 FALSE -9 TRUE 1
TRUE FALSE TRUE FALSE TCOL-1593667 TRUE warrene 7 46 0.1521739 FALSE 0 46 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE TFAY-1593669 TRUE sandersb 11 54 0.2037037 FALSE 0 43 0 FALSE -11 TRUE 1
TRUE FALSE TRUE FALSE TLIN-1593673 TRUE buttigiegp 7 41 0.1707317 FALSE 0 34 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE TLIN-1593673 TRUE klobuchara 7 41 0.1707317 FALSE 0 34 0 FALSE -7 TRUE 1
TRUE FALSE TRUE FALSE TMAR-1593675 TRUE buttigiegp 15 96 0.1562500 FALSE 0 68 0 FALSE -15 TRUE 1
TRUE FALSE TRUE FALSE TMAR-1593675 TRUE sandersb 18 96 0.1875000 FALSE 0 68 0 FALSE -18 TRUE 1
TRUE FALSE TRUE FALSE TMAR-1593675 TRUE warrene 15 96 0.1562500 FALSE 0 68 0 FALSE -15 TRUE 1
TRUE FALSE TRUE FALSE TMON1-1593676 TRUE warrene 16 96 0.1666667 FALSE 0 74 0 FALSE -16 TRUE 1
TRUE FALSE TRUE FALSE UNION-1593507 TRUE bidenj 5 25 0.2000000 FALSE 0 18 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE UNION-1593507 TRUE warrene 5 25 0.2000000 FALSE 0 18 0 FALSE -5 TRUE 1
TRUE FALSE TRUE FALSE WB-946804 TRUE bidenj 3 17 0.1764706 FALSE 0 16 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE WB 1-947762 TRUE bidenj 11 42 0.2619048 FALSE 0 30 0 FALSE -11 TRUE 1
TRUE FALSE TRUE FALSE WC-947281 TRUE buttigiegp 2 12 0.1666667 FALSE 0 10 0 FALSE -2 TRUE 1
TRUE FALSE TRUE FALSE WC-948076 TRUE sandersb 6 34 0.1764706 FALSE 0 34 0 FALSE -6 TRUE 1
TRUE FALSE TRUE FALSE WDM-313-947776 TRUE sandersb 23 148 0.1554054 FALSE 0 133 0 FALSE -23 TRUE 1
TRUE FALSE TRUE FALSE WE2-947020 TRUE bidenj 3 19 0.1578947 FALSE 0 15 0 FALSE -3 TRUE 1
TRUE FALSE TRUE FALSE WE2-947020 TRUE klobuchara 4 19 0.2105263 FALSE 0 15 0 FALSE -4 TRUE 1
TRUE FALSE TRUE FALSE YK-947999 TRUE sandersb 3 16 0.1875000 FALSE 0 12 0 FALSE -3 TRUE 1

Correlations Between First Round Unviable Candidates and Vote Increases for Viable Candidates in Final Round

As a bonus, here’s the original thing I was looking into here, trying to get a read on whose voters went where after their candidate was unviable. The weird 100% positive correlation between Deval Patrick being unviable and Deval Patrick gaining voters was what got me digging.

### Join change between first and final round with viability, create correlation matrix, remove 1:1 correlations

change_between_rounds %>%
  inner_join(viability, by = "precinct") %>%
  select(-precinct) %>% cor() %>% 
  as_tibble(rownames = "corr") %>%
  filter(str_detect(corr, "change")) %>% 
  select(contains("viable"), corr) %>%
  column_to_rownames(var = "corr") %>% 
  as.matrix() %>% ggcorrplot::ggcorrplot(lab = TRUE, insig = "blank", colors = c("red3", "white", "green3")) +
  ggtitle("Correlations Between Non-Viable Candidates and Second Round Gains") +
  theme_powerbi()

You can’t perform that action at this time.