Last active
May 18, 2017 07:50
-
-
Save salilpa/ef0f82e366b49ddf56e222ec31dc1be8 to your computer and use it in GitHub Desktop.
Simple formula to find Bayesian A/B test confidence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def calc_ab(conversion_a, interaction_a, conversion_b, interaction_b): | |
# more generic function which takes conversions and interactions. Calculates failures internally | |
# total is the confidence that b is doing better than a | |
alpha_a = conversion_a + 1 | |
alpha_b = conversion_b + 1 | |
beta_a = interaction_a - conversion_a + 1 | |
beta_b = interaction_b - conversion_b + 1 | |
total = 0.0 | |
for i in range(alpha_b): # loop till alphab - 1 | |
num = math.lgamma(alpha_a+i) + math.lgamma(beta_a+beta_b) + math.lgamma(1+i+beta_b) + math.lgamma(alpha_a+beta_a) | |
den = math.log(beta_b+i) + math.lgamma(alpha_a+i+beta_a+beta_b) + math.lgamma(1+i) + math.lgamma(beta_b) + math.lgamma(alpha_a) + math.lgamma(beta_a) | |
total += math.exp(num - den) | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment