-
-
Save tlehman/8fa9911d01e394e197005e989848d6ec to your computer and use it in GitHub Desktop.
http://www.evanmiller.org/bayesian-ab-testing.html implemented in ruby
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
# http://www.evanmiller.org/bayesian-ab-testing.html implemented in ruby | |
# requires the distribution gem from https://github.com/clbustos/distribution (gem 'distribution', require: false) | |
def probability_b_beats_a(completed_a, total_a, completed_b, total_b) | |
require 'distribution/math_extension' | |
total = 0.0 | |
alpha_a = completed_a + 1 | |
beta_a = total_a - completed_a + 1 | |
alpha_b = completed_b + 1 | |
beta_b = total_b - completed_b + 1 | |
0.upto(alpha_b - 1) do |i| | |
total += Math.exp(Math::Beta.log_beta(alpha_a+i, beta_b+beta_a).first - Math.log(beta_b+i) - Math::Beta.log_beta(1+i, beta_b).first - Math::Beta.log_beta(alpha_a, beta_a).first) | |
end | |
total | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment