Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View carlislerainey's full-sized avatar

Carlisle Rainey carlislerainey

View GitHub Profile
@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))
@carlislerainey
carlislerainey / list-exit-pwr-analysis. R
Created November 16, 2023 13:33
Power analysis for list experiment
# load packages
library(tidyverse)
library(marginaleffects)
library(patchwork)
# clear workspace
rm(list = ls())
@carlislerainey
carlislerainey / test.R
Created November 6, 2023 16:22
{marginaleffects} Question: I feel like these two should give me the same answer...
# load packages
library(tidyverse)
library(marginaleffects)
devtools::install_github("carlislerainey/crdata")
# load data
cg <- crdata::cg2006
# fit model