Rockville tracts for CVAP checks
- 701007
- 701006
- 701002
- 701210
- 701001
- 700905
- 700904
- 701102
| require(jsonlite) | |
| require(plyr) | |
| require(sqldf) | |
| require(reshape2) | |
| require(openxlsx) | |
| download.file(url = 'https://feeds-elections.foxnews.com/voter_analysis/2024_Generals/US/US-P-00.json',destfile = 'Downloads/apv_24.json') | |
| download.file(url = 'https://feeds-elections.foxnews.com/voter_analysis/2020_Generals/US/US-P-00.json',destfile = 'Downloads/apv_20.json') |
| options(gsubfn.engine = "R", scipen=999, digits=3) # This stops the loading of XQuartz on Mac | |
| require(sqldf) | |
| require(ggplot2) | |
| require(scales) | |
| require(reshape2) | |
| require(lubridate) | |
| require(ggrepel) | |
| jr=theme(panel.background = element_rect(fill = NA, colour = "black", size = 0.25), |
| require(tabulizer) | |
| require(dplyr) | |
| require(datapasta) | |
| require(ggplot2) | |
| require(gridExtra) | |
| jr=theme(panel.background = element_rect(fill = NA, colour = "black", size = 0.25), | |
| panel.border = element_blank(), | |
| panel.grid.major = element_line(colour = "black", size = 0.05), | |
| panel.grid.minor = element_line(colour = "black", size = 0.05), |
| require(rio) | |
| require(sqldf) | |
| cces = import('~/Downloads/CCES16_Common_OUTPUT_Feb2018_VV.dta') | |
| .cces = (cces[,c('CL_voterstatus','CC16_364','CC16_403','CL_E2016GVM','commonweight_vv','V101','CL_state')]) | |
| .cces = .cces[.cces$CL_voterstatus %in% c('active','inactive'),] | |
| .cces$VOTE_LIKELIHOOD = car::recode(var = as.numeric(.cces$CC16_364), | |
| recodes = "1='Yes'; 2='Probably' ; 3='Already voted' ; 4 = 'No'; else = NA") | |
| .cces$VOTE_METHOD_SELFREPORT = car::recode(var = as.numeric(.cces$CC16_403), |
| wasserman_rejections = function(by_mail=.8,rejection=.04, | |
| total_votes=2000000, | |
| dem_pct=.65,pre_d_2way=.52){ | |
| rejections = (((total_votes*by_mail)*rejection)) | |
| pre_rej_vote = c(total_votes*pre_d_2way,total_votes*(1-pre_d_2way)) | |
| post_rej_vote = c((total_votes*pre_d_2way) - ((rejections * dem_pct)), | |
| (total_votes*(1-pre_d_2way)) - ((rejections * (1-dem_pct)))) |
Rockville tracts for CVAP checks
| ## LOAD LIBRARIES | |
| library(dplyr) | |
| library(tidyr) | |
| library(httr) | |
| library(readxl) | |
| ## CUSTOM FUNCTION TO READ ALL SHEETS OF AN EXCEL FILE INTO A LIST OF DATA FRAMES OR TIBBLES THANKS STACK OVERFLOW!! | |
| ## https://stackoverflow.com/questions/12945687/read-all-worksheets-in-an-excel-workbook-into-an-r-list-with-data-frames | |
| read_excel_allsheets <- function(filename, tibble = FALSE) { | |
| sheets <- excel_sheets(filename) |
| remove(list=ls()) | |
| require(jsonlite) | |
| require(ggplot2) | |
| require(reshape2) | |
| require(scales) | |
| jr=theme(panel.background = element_rect(fill = NA, colour = "black", size = 0.25), | |
| panel.border = element_blank(), | |
| panel.grid.major = element_line(colour = "black", size = 0.05), | |
| panel.grid.minor = element_line(colour = "black", size = 0.05), |
| require(data.table) | |
| require(sqldf) | |
| require(rvest) | |
| require(dplyr) | |
| fairvote=read_html('https://infogram.com/cong-primaries-by-party-1g0n2owgxvyrp4y') %>% | |
| html_nodes('script') %>% | |
| html_text() | |
| fairvote=fairvote[[7]] | |
| fairvote=unlist(strsplit(x = fairvote,fixed = T, split = c('[\"','\"]'))) |
| require(arm) | |
| set.seed(987654321) | |
| .tmp=(rnorm(100000, mean=0)) | |
| .tmp=invlogit(.tmp) | |
| shift_param=.3 | |
| par(mfrow=c(1,3)) | |
| hist(x=.tmp, main=paste0('Mean=',round(mean(.tmp),3))) |