Skip to content

Instantly share code, notes, and snippets.

View elliottmorris's full-sized avatar

G. Elliott Morris elliottmorris

View GitHub Profile
@elliottmorris
elliottmorris / midterm-rdpi-seats-data.csv
Created January 5, 2026 17:20
correlation between midterm seat loss and rdpi
Year President Party House_Seat_Change RDPI_YoY_Pct_Change_July RDPI_Source
1946 Harry S. Truman D -55 -1.1 FRED A067RL1A156NBEA (annual % chg, total RDPI): 1945-1946
1950 Harry S. Truman D -29 8.71 FRED DPIC96: Q2-49 (1564.4) to Q2-50 (1700.7)
1954 Dwight D. Eisenhower R -18 -0.22 FRED DPIC96: Q2-53 (1935.2) to Q2-54 (1931.0)
1958 Dwight D. Eisenhower R -48 -0.36 FRED DPIC96: Q2-57 (2238.1) to Q2-58 (2230.0)
1962 John F. Kennedy D -4 4.58 FRED DSPIC96: Jul-61 (2517.6) to Jul-62 (2633.0)
1966 Lyndon B. Johnson D -47 5.25 FRED DSPIC96: Jul-65 (3097.8) to Jul-66 (3260.4)
1970 Richard Nixon R -12 5.05 FRED DSPIC96: Jul-69 (3705.6) to Jul-70 (3892.6)
1974 Gerald R. Ford R -48 -1.34 FRED DSPIC96: Jul-73 (4499.0) to Jul-74 (4438.7)
1978 Jimmy Carter D -15 4.77 FRED DSPIC96: Jul-77 (4841.6) to Jul-78 (5072.8)
library(tidyverse)
library(janitor)
library(zoo)
library(scales)
clean_and_avg = function(series){
dat = read_csv(sprintf('%s.csv',series))
@elliottmorris
elliottmorris / war_and_ideo.csv
Created August 12, 2025 14:25
2024 Strength In Numbers WAR estimates with Bonica's CFscore
party cycle state_name district representative WAR ideo
dem 2024 Alabama 2 Shomari Figures -0.0142956 -2.40172899842457
dem 2024 Alabama 7 Terri A. Sewell -0.013435550000000001 -2.07122942055397
dem 2024 Arizona 3 Yassamin Ansari -0.0015478900000000001 -1.9319779182875
dem 2024 Arizona 4 Greg Stanton -0.008184455 -2.18490810244875
dem 2024 Arizona 7 Raúl Grijalva -0.018168 -3.33143206893384
dem 2024 California 2 Jared Huffman 0.00308888 -3.35023512544864
dem 2024 California 4 Mike Thompson 0.018705350000000003 -2.10464881402841
dem 2024 California 6 Ami Bera -0.013199550000000001 -2.40293561432867
dem 2024 California 7 Doris Matsui 0.0075622499999999995 -2.67086471545931
@elliottmorris
elliottmorris / main_2024_trump_musk.R
Created July 10, 2025 05:22
Figuring out who would vote for Musk using ANES data
library(tidyverse)
library(survey)
# mutate weight variable
dat = read_csv('anes_timeseries_2024_csv_20250430.csv') %>%
filter(V241012 == 1) %>%# RVs
mutate(weight = case_when(!is.na(V240103b) ~ V240103b,
!is.na(V240104b) ~ V240104b,
!is.na(V240104b) ~ V240104b,
!is.na(V240103a) ~ V240103a,
@elliottmorris
elliottmorris / cpi_adj_outlays.R
Created April 11, 2025 13:18
script to look at federal spending by year
library(tidyverse)
library(zoo)
dat = read_csv('~/Desktop/selected_outlays_2025-04-10.csv') %>%
select(date, spend = `Cumulative year-to-date`)
dat = tibble(
date = ymd(as_date(min(dat$date):max(dat$date)))
) %>%
@elliottmorris
elliottmorris / gist:94ac7a4dc7b96aa13294aa18794c5803
Created April 3, 2025 14:04
trump issue approval march 2025
library(tidyverse)
library(janitor)
dat = read_csv('~/Downloads/Trump issue approval march - Sheet1.csv')
dat = clean_names(dat)
dat %>% group_by(category) %>%
summarise_at(c('approve', 'disapprove', 'net'), mean) %>%
mutate_if(is.numeric,round_half_up,1) %>%
@elliottmorris
elliottmorris / ElectionResults.xlsx
Created April 2, 2025 02:38
Wisconsin Supreme Court Election live modeling, Apr 1 2025
download excel file from: https://elections.countyofdane.com/Precincts-Result/179/0005
@elliottmorris
elliottmorris / bayes update young voters.R
Created November 27, 2023 22:50
for twitter. showing how to combine a prior (past election results) and data (polls) for certain poll subgroups
library(tidyverse)
bayes_update_normal = function(
data_mu,
data_se,
prior_mu = 0,
prior_se = 3){
if(all(data_mu == 0)){
return(c(0,0))
@elliottmorris
elliottmorris / Untitled spreadsheet - Sheet1.csv
Created October 17, 2023 15:51
chart for Matt and Derek
country inflation (YoY Sept 2023) Leader approval Disapproval Net
Austria 7.37 23 73 -50
Belgium 2.39 38 46 -8
Brazil 5.19 51 45 6
Canada 4 33 59 -26
France 4.86 23 72 -49
Germany 4.53 25 68 -43
Ireland 6.41 39 52 -13
Italy 5.44 44 51 -7
Japan 3.2 23 63 -40
@elliottmorris
elliottmorris / ca_polls - Sheet1.csv
Last active September 18, 2021 03:03
California 2021 recall polling model
end_date pollster n population pid_weighted keep remove
2021-09-13 survey monkey 3985 LV 1 0.55 0.41
2021-09-13 trafalgar 1082 LV 0 0.53 0.45
2021-09-11 emerson 1000 LV 1 0.6 0.4
2021-09-10 data for progress 2464 LV 1 0.57 0.43
2021-09-08 surveyusa 930 LV 0 0.54 0.41
2021-09-07 suffolk 500 LV 0 0.58 0.41
2021-09-06 uc berkeley 6550 LV 0 0.6 0.39
2021-09-04 trafalgar 1079 LV 0 0.53 0.43
2021-09-01 yougov 1955 LV 1 0.56 0.44