Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Created March 26, 2024 13:36
Show Gist options
  • Save carlislerainey/03a49bb4eb64c8dd25a902e7aea658db to your computer and use it in GitHub Desktop.
Save carlislerainey/03a49bb4eb64c8dd25a902e7aea658db to your computer and use it in GitHub Desktop.
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,
"Jordan Lee", 5, 4,
"Taylor Green", 3, 6,
"Morgan White", 4, 4,
"Casey Brown", 5, 3,
"Drew Wilson", 3, 3,
"Chris Bailey", 4, 2,
"Sam Rivera", 1, 3,
"Jesse Kim", 7, 1,
"Robin Parker", 5, 3
)
# random assignment
zeros_and_ones <- rep(0:1, length.out = nrow(po))
W <- sample(zeros_and_ones)
# create (fake) observed data set
observed <- data.frame(
W_num = W,
W_fct = ifelse(W == 1, "Treatment", "Control"),
Y = po$Y1*W + po$Y0*(1 - W)
)
# quick look
glimpse(observed)
# compute var(treatment group)/6 + var(control group)/6
# ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment