All problems
Beta-Binomial Posterior Predictive Variance
Problem
For a beta-binomial with n future trials after integrating over a Beta(alpha, beta) success probability, the predictive variance is n * p * (1 - p) * (alpha + beta + n) / (alpha + beta + 1), where p = alpha / (alpha + beta). Return 0.0 when alpha or beta is nonpositive or n is negative.
Hint
The predictive variance overdispenses the binomial variance by the factor (alpha + beta + n) / (alpha + beta + 1).
Test cases
case 1
in: [1,1,10]
expected: 10
case 2
in: [2,3,5]
expected: 2
case 3
in: [2,2,1]
expected: 0.25
case 4
in: [3,1,0]
expected: 0
case 5
in: [1,1,2]
expected: 0.6666666666666666
Starter codePython
def beta_binomial_predictive_variance(alpha, beta, n):
# Your code here
pass5 test cases · run your code against them in the editor