Skip to content

Instantly share code, notes, and snippets.

@nalanj
Created November 2, 2014 21:29
Show Gist options
  • Save nalanj/7e00648073d949172002 to your computer and use it in GitHub Desktop.
Save nalanj/7e00648073d949172002 to your computer and use it in GitHub Desktop.
Bayesian experiment comparison
require 'distribution'
# set these values
control_success = 338
control_fail = 56
experiment_success = 341
experiment_fail = 53
alpha_a = control_success + 1
beta_a = control_fail + 1
alpha_b = experiment_success + 1
beta_b = experiment_fail + 1
total = 0.0
0.upto(alpha_b - 1) do |i|
total += Math.exp(Math.lbeta(alpha_a + i, beta_b + beta_a)[0] - Math.log(beta_b + i) -
Math.lbeta(1 + i, beta_b)[0] - Math.lbeta(alpha_a, beta_a)[0])
end
puts total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment