Skip to content

Instantly share code, notes, and snippets.

@bgweber
Last active January 12, 2017 06:48
Show Gist options
  • Save bgweber/633386c85501fbe1f868103e8c011e46 to your computer and use it in GitHub Desktop.
Save bgweber/633386c85501fbe1f868103e8c011e46 to your computer and use it in GitHub Desktop.
library(boot)
data <- read.csv("UserSessions.csv")
# Function for computing the difference of differences
run_DiD <- function(data, indices){
d <- data[indices,]
new <- mean(d$postval[d$group=='Test'])/mean(d$priorval[d$group=='Test'])
old <-mean(d$postval[d$expgroup=='Control'])/mean(d$priorval[d$expgroup=='Control'])
return((new - old)/old * 100.0)
}
# perform the bootstrapping and output the results
boot_est <- boot(data, run_DiD, R=1000, parallel="multicore", ncpus = 8)
quantile(boot_est$t, c(0.025, 0.975))
plot(density(boot_est$t), xlab = "% Increase vs. Control")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment