This file contains 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
################################### | |
# exploring the 538 package | |
# code by G. Elliott Morris, @gelliottmorris | |
################################### | |
#install pacakges | |
install.packages(c("fivethirtyeight","ggplot2","dplyr","ggthemes")) | |
#load them | |
library(fivethirtyeight) |
This file contains 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
################################## | |
# Code for house-correcting Trump approval polls | |
# Written by Alexander Agadjanian and G. Elliott Morris | |
# for use on Elliott's blog, TheCrosstab.com. | |
# @a_agadjanian @GElliottMorris | |
# | |
# Github Gist lives at https://gist.github.com/elliottmorris/905bd514110ea7d0b599cfca8a8e7332 | |
#################################### | |
# libraries #### |
This file contains 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
## R Code for Analysing the 2016 Cooperative Congressional Election Study | |
## Written by G. Elliott Morris | |
## @gelliottmorris | [email protected] | TheCrosstab.com | |
## please do not replicate the analysis without permission. | |
## | |
## Additional info: | |
## DOWNLOAD DATA AT https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/GDF6Z0 | |
## Github Gist lives at: https://gist.github.com/elliottmorris/79141ff0f0c3824798ce3b84f18b817b | |
### libraries & functions #### |
This file contains 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
## R Code for analysing AHCA CBO outlook and congress data | |
## Written by G. Elliott Morris | |
## @gelliottmorris | [email protected] | TheCrosstab.com | |
## please do not replicate the analysis without permission. | |
## | |
## Additional info: | |
## DOWNLOAD DATA AT http://bit.ly/2oa0RPa | |
## Github Gist lives at: http://bit.ly/2nI5bZu | |
# libraries #### |
This file contains 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
# Libraries, data, setup #### | |
rm(list=ls()) | |
library(tidyverse) | |
library(gridExtra) | |
library(googlesheets) | |
source("~/Desktop/theme_elliott.R") | |
# load in data from Gsheet | |
my_sheets <- gs_ls() |
This file contains 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
# function written by HuffPost Pollster's Natalie Jackson for the 2016 election | |
# ibraries and import -------- | |
library(dplyr) | |
library('Matrix') | |
seat_data <- read.csv("seat_partisanship_demog.csv") # read in a 435 | |
seat_data <- seat_data %>% | |
select(clinton2016, obama2012, house2016, pct_nonwhite) |
This file contains 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) | |
polls_2018 <- read_tsv("http://elections.huffingtonpost.com/pollster/api/v2/questions/18-US-House/poll-responses-clean.tsv") %>% | |
filter(month(end_date)>=6) %>% | |
mutate(Dem.Margin = Democrat-Republican) %>% | |
group_by(mode) %>% | |
mutate(mean_dem = mean(Dem.Margin)) | |
ggplot(polls_2018,aes(x=Dem.Margin,fill=Dem.Margin>0,col=Dem.Margin>0)) + | |
geom_bar(width=0.8,alpha=0.5) + | |
scale_color_manual(values=c("TRUE"="blue","FALSE"="red")) + |
This file contains 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
vote_model <- brm(mvbind(vote_trump,vote_clinton) ~ 1 + | |
# pop level | |
state_clinton + state_black_pct + state_hispanic_pct + state_white_protestant + | |
# group effects | |
(1|sex) + (1|race) + (1|age) + (1|edu) + (1|state_name) + (1|region) + | |
# interactions b/t group effects | |
(1|race:edu) + (1|age:edu) + (1|race:region), | |
data = cces, | |
family = bernoulli(link = "logit"), | |
# stan stuff |
This file contains 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
# History files | |
.Rhistory | |
.Rapp.history | |
# Session Data files | |
.RData | |
# User-specific files | |
.Ruserdata |
This file contains 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) |
OlderNewer