Skip to content

Instantly share code, notes, and snippets.

@avibryant
Last active March 22, 2021 18:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save avibryant/545e63b446a840951d5e to your computer and use it in GitHub Desktop.
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
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;
}
@avibryant
Copy link
Author

Updated to use logs, to avoid Infinity issues.

@avibryant
Copy link
Author

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