Last active
May 13, 2019 14:29
-
-
Save arnov/60de0b1ad62d329bc222 to your computer and use it in GitHub Desktop.
Bayesian AB Test
This file contains hidden or 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import math | |
def calc_ab(alpha_a, beta_a, alpha_b, beta_b): | |
''' | |
See http://www.evanmiller.org/bayesian-ab-testing.html | |
αA is one plus the number of successes for A | |
βA is one plus the number of failures for A | |
αB is one plus the number of successes for B | |
βB is one plus the number of failures for B | |
''' | |
total = 0.0 | |
for i in range(alpha_b): | |
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 | |
print(calc_ab(1600+1,1500+1,3200+1,3300+1)) |
Ah I think you're right, the for loop in Evan Millar's example is in Julia where it is inclusive! I've updated it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! I think it should be
for i in range(alpha_b)
to includealpha_b-1
in the counting.