Skip to content

Instantly share code, notes, and snippets.

View jonrobinson2's full-sized avatar

Jonathan Robinson jonrobinson2

View GitHub Profile
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),
## 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)

Rockville tracts for CVAP checks

  • 701007
  • 701006
  • 701002
  • 701210
  • 701001
  • 700905
  • 700904
  • 701102
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))))
@jonrobinson2
jonrobinson2 / cces_absentee_val.R
Last active December 15, 2020 21:43
Mark B CCES 2016 Mail Intention Validation
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),
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),