Created
June 29, 2023 22:24
-
-
Save possibly-wrong/4a823f9acc65b49c4f6037573a115df2 to your computer and use it in GitHub Desktop.
Probability P(Theta1 > Theta2) for independent beta-distributed random variables
This file contains 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 p = compare_binomial(x1, n1, x2, n2) | |
| % Compute P(Beta(x1+1,n1-x1+1) > Beta(x2+1,n2-x2+1)). | |
| % Compute p(x1, n1, x2, x2). | |
| p = 1; | |
| for k = 0:x2 | |
| p = p * (x1 + 1 + k) / (n1 + 2 + k); | |
| end | |
| % Iterate Bayes updates with each of n2 - x2 failures. | |
| q = p * (n1 - x1 + 1) * (x2 + 1) / (n1 + x2 + 3); | |
| for k = 1:(n2 - x2) | |
| p = p + q / k; | |
| q = q * (n1 - x1 + 1 + k) * (x2 + 1 + k) / (k * (n1 + x2 + 3 + k)); | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment