Skip to content

Instantly share code, notes, and snippets.

@teguhn
Last active September 26, 2016 05:54
Show Gist options
  • Save teguhn/4d39db3797b7664a5f6f32ea4dca782e to your computer and use it in GitHub Desktop.
Save teguhn/4d39db3797b7664a5f6f32ea4dca782e to your computer and use it in GitHub Desktop.
Function to calculate the winning probability of an binary (control vs 1 variant) experiment. Reference: www.evanmiller.org/bayesian-ab-testing.html
ab.result <- function(control_success, control_failed, variant_success, variant_failed){
growth <- (variant_success/(variant_success+variant_failed))/(control_success/(control_success+control_failed))-1
control_success <- control_success+1
control_failed <- control_failed+1
variant_success <- variant_success+1
variant_failed <- variant_failed+1
winning_prob <- 0
for(i in 0:(variant_success-1)){
winning_prob <- winning_prob + exp(lbeta(control_success+i, variant_failed+control_failed)
- log(variant_failed+i) - lbeta(1+i, variant_failed) - lbeta(control_success, control_failed))
}
return(list(winning_prob=winning_prob, growth=growth))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment