Complete Randomization example

In our running example, let’s see what happens if we choose completely at random.

gen_random_exp <- function(){
  res <- hypo_data |> mutate(
    
     # assign treatment
     z = sample(c(rep(0, 4), rep(1, 4)),8),
     y = if_else(z==1, y1, y0)
     )
  res
}

n <- 100
avg_eff <- rep(0,n)
for(i in 1:n){
  exp <- gen_random_exp() |> group_by(z) |> summarise(res = mean(y))
  avg_eff[i] <- (exp |> filter(z==1))$res -(exp |> filter(z==0))$res
}

c(mean(avg_eff), sd(avg_eff))
## [1] -6.025000  8.521326

On average the answer is equal to the SATE, but it is quite noisy!