Skip to content

Instantly share code, notes, and snippets.

View carlislerainey's full-sized avatar

Carlisle Rainey carlislerainey

View GitHub Profile
@carlislerainey
carlislerainey / all-policies.csv
Last active July 25, 2024 09:32
Code to create a list of the 154 policies in our Roper population for Clifford, Leeper, and Rainey
Category Issue Policy
Economic Drug Costs allowing imported drugs from Canada
Economic Drug Costs eliminate drug advertisements
Economic Drug Costs requiring to pay higher share in drugs
Economic Education free state college tuition
Economic Energy adding monthly charge to utility bill to combat climate change
Economic Energy carbon dioxide emission limits
Economic Energy coal
Economic Energy drilling
Economic Energy energy efficiency
@carlislerainey
carlislerainey / pilot-se.R
Created June 3, 2024 13:30
DeclareDesign code from Alex Coppock to simulate SEs from pilot studies
library(tidyverse)
library(DeclareDesign)
# Original parameters
tau <- 1 # treatment effect
se <- tau / (qnorm(0.95) + qnorm(0.80)) # standard error for 80% power
n_planned <- 500 # sample size per condition in planned full study
# calculate required standard deviation to yield 80% power given the above
sigma <- se * sqrt(2 * n_planned / 2)
@carlislerainey
carlislerainey / br-separation-illustration.R
Created April 20, 2024 10:03
Code to illustrate separation
# load packages
library(modelsummary)
# get latest version of {crdata} package, if updated
remotes::install_github("carlislerainey/crdata")
# load (and slightly wrangle) data from Barrilleaux and Rainey (2014)
br <- crdata::br2014 %>%
# recode from centered GOP gov. indicator to 0/1 Dem. gov. indicator
# (explanatory variables are centered about mean)
@carlislerainey
carlislerainey / illustrate-display.R
Created March 29, 2024 09:34
Illustrate arm::display()
# load packages
library(tidyverse)
# update {crdata} if necessary
remotes::install_github("carlislerainey/crdata")
# load data
weis <- crdata::weisiger2014
# rescale weisiger2014 explanatory variables using arm::rescale()
@carlislerainey
carlislerainey / starter-lm.R
Created March 28, 2024 13:38
Starter code for live coding using OLS, robust SEs, and {marginaleffects} to analysis data from survey experiments
# load packages
library(tidyverse)
# create data frame of the potential outcomes
po <- tribble(
~Name, ~Y1, ~Y0,
"Alex Smith", 7, 5,
"Jamie Doe", 2, 3,
"Pat Johnson", 7, 7,
@carlislerainey
carlislerainey / compute-coverage.R
Created March 26, 2024 15:16
R code to compute coverage of 95% CI using PO framework
# load packages
library(tidyverse)
# create data frame of the potential outcomes
po <- tribble(
~Name, ~Y1, ~Y0,
"Alex Smith", 7, 5,
"Jamie Doe", 2, 3,
"Pat Johnson", 7, 7,
@carlislerainey
carlislerainey / starter.R
Created March 26, 2024 13:36
Starter code for analyzing randomized experiments
# load packages
library(tidyverse)
# create data frame of the potential outcomes
po <- tribble(
~Name, ~Y1, ~Y0,
"Alex Smith", 7, 5,
"Jamie Doe", 2, 3,
"Pat Johnson", 7, 7,
# load packages
library(rstan)
library(bayesplot)
# make a stan model
fancy_stan_model <- "
generated quantities {
int<lower=0, upper=1> y_sim = bernoulli_rng(0.5);
}
"
@carlislerainey
carlislerainey / comparing.R
Created February 12, 2024 21:06
Comparing OLS w/ interactions to RE w/ and w/o interactions with oversight data
# load packages
library(tidyverse)
library(marginaleffects)
library(rstanarm); options(mc.cores = parallel::detectCores())
# load data
data <- read_rds("https://www.dropbox.com/s/9grn8kkb5yzwagx/data.rds?raw=1") %>%
filter(passed_mvc1) %>%
glimpse()
@carlislerainey
carlislerainey / animated-sharing.R
Last active January 31, 2024 11:36
Code for animating the figure on data sharing in political science
# load packages
library(tidyverse)
library(ggrepel)
library(gganimate)
# set ggplot options
theme_set(theme_bw(base_family = "Gill Sans"))
update_geom_defaults("label", list(family = theme_get()$text$family))
update_geom_defaults("text", list(family = theme_get()$text$family))