This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(lubridate) | |
| library(pbapply) | |
| url<- 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQ56fySJKLL18Lipu1_i3ID9JE06voJEz2EXm6JW4Vh11zmndyTwejMavuNntzIWLY0RyhA1UsVEen0/pub?gid=0&single=true&output=csv' | |
| all_polls <- read_csv(url) | |
| # remove any polls if biden or trump blank | |
| all_polls <- all_polls %>% filter(!is.na(biden),!is.na(trump))#, include == "TRUE") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(pbapply) | |
| library(tidyverse) | |
| mod <- read_csv('~/Downloads/output/site_data/electoral_college_simulations.csv') | |
| mod <- mod %>% gather(state,vote,4:ncol(.)) | |
| evs <- read_csv('data/prior/state_evs.csv') | |
| mod <- mod %>% left_join(evs) | |
| tp <- pblapply(1:max(mod$draw), | |
| cl = 12, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(janitor) | |
| library(lubridate) | |
| library(zoo) | |
| library(politicaldata) | |
| RUN_DATE <- Sys.Date() | |
| start_date <- ymd("2020-02-01") | |
| election_day <- ymd('2020-11-03') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(zoo) | |
| trump_approve <- read_csv("https://projects.fivethirtyeight.com/polls-page/president_approval_polls.csv") | |
| trump_approve <- trump_approve %>% | |
| mutate("date" = mdy(end_date)) %>% | |
| dplyr::select(pollster, | |
| date, | |
| "approve" = yes, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(politicaldata) | |
| library(lubridate) | |
| library(zoo) | |
| library(gghighlight) | |
| today_2020_time_difference <- as.numeric(difftime(ymd('2020-11-03'),Sys.Date(),units = 'days')) | |
| # wrangle ----------------------------------------------------------------- | |
| # historical |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rm(list = ls()) #reset the environment | |
| library(tidyverse) | |
| library(lubridate) | |
| library(mgcv) | |
| exponent_weight <- function(i) { | |
| exp(-0.04*i) | |
| } | |
| TODAY_DAY <- difftime(Sys.Date(),as.Date("2017-01-21")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(lubridate) | |
| library(colorspace) | |
| # get raw polls | |
| if(!exists("raw_polls")){ | |
| raw_polls <- read_csv('https://projects.fivethirtyeight.com/polls-page/president_approval_polls.csv') | |
| } | |
| # selects cols etc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| state_name | white_evangel | n | prop | |
|---|---|---|---|---|
| Alabama | No | 2635716.4303168333 | 0.7215633301038805 | |
| Alabama | Yes | 1017069.5696831668 | 0.27843666989611954 | |
| Alaska | No | 408543.06241488626 | 0.7700455804134742 | |
| Alaska | Yes | 122000.93758511376 | 0.22995441958652582 | |
| Arizona | No | 3873710.103017639 | 0.8261500325275896 | |
| Arizona | Yes | 815159.8969823611 | 0.17384996747241044 | |
| Arkansas | No | 1325152.1454922806 | 0.6069750351168169 | |
| Arkansas | Yes | 858054.8545077195 | 0.3930249648831831 | |
| California | No | 22234460.694529217 | 0.8909648084418956 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| state_abb | pct_bachelors_higher | |
|---|---|---|
| DC | 0.6483020341946732 | |
| MA | 0.4908509625882079 | |
| CT | 0.4712702755955542 | |
| CO | 0.4706548492306638 | |
| NJ | 0.45938202372319153 | |
| NY | 0.45520330118475155 | |
| MD | 0.4496009185101967 | |
| CA | 0.42358538595803436 | |
| VA | 0.42333224401155256 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This file runs an analysis of 2020 Democratic primary polls to | |
| # assess relationships between candidate's polling averages using | |
| # variance-covariance matrices. | |
| # | |
| # Read more about it here: | |
| # https://thecrosstab.substack.com/p/buttigiegs-rise-has-cost-biden-and | |
| rm(list=ls()) | |
| library(tidyverse) | |
| library(lubridate) |