All problems
Negative Hypergeometric PMF
Problem
Negative hypergeometric probability that the r-th success in sampling without replacement occurs on draw k.
P(X = k) = C(k - 1, r - 1) * C(pop - k, successes - r) / C(pop, successes). Return 0.0 for invalid combinations of arguments.
Hint
Place r - 1 successes in the first k - 1 draws and make draw k a success.
Test cases
case 1
in: [10,3,5,2]
expected: 0.16666666666666666
case 2
in: [5,2,2,2]
expected: 0.1
case 3
in: [10,3,1,1]
expected: 0.3
case 4
in: [4,2,3,2]
expected: 0.3333333333333333
case 5
in: [10,3,12,1]
expected: 0
Starter codePython
import math
def negative_hypergeometric_pmf(pop, successes, k, r):
# Your code here
pass5 test cases · run your code against them in the editor