Last active
March 22, 2021 18:36
-
-
Save avibryant/545e63b446a840951d5e to your computer and use it in GitHub Desktop.
An implementation of http://www.evanmiller.org/bayesian-ab-testing.html with no depenedencies
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
function probabilityBBeatsA(aa, ba, ab, bb) { | |
var probability = 0.0; | |
for(var i = 0; i < ab; i++) { | |
var product = Math.log(1 + (aa + ba)/(i + bb)); | |
var j = 1; | |
var start = i+1; | |
[bb, ba, aa, i].forEach(function(steps){ | |
var stop = start + steps; | |
while(start < stop) { | |
product += Math.log(start++) | |
product -= Math.log(j++); | |
} | |
start = steps; | |
}); | |
probability += Math.exp(product); | |
} | |
return probability; | |
} |
Updated to have the right name (BBeatsA, not ABeatsB)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use logs, to avoid Infinity issues.