All problems
Hypergeometric Mean and Variance
Problem
For sampling draws items without replacement from a population of pop items containing successes successes, return [mean, variance] of the hypergeometric count. mean = draws * K / N and variance = draws * (K / N) * (1 - K / N) * (pop - draws) / (pop - 1), where K / N = successes / pop. Return [0.0, 0.0] for invalid counts and variance 0.0 when pop == 1.
Hint
This is the binomial variance reduced by the finite population correction factor.
Test cases
case 1
in: [50,5,10]
expected: [1,0.7346938775510204]
case 2
in: [10,3,4]
expected: [1.2,0.56]
case 3
in: [52,4,5]
expected: [0.38461538461538464,0.32718412808910546]
case 4
in: [5,5,5]
expected: [5,0]
case 5
in: [10,3,11]
expected: [0,0]
Starter codePython
def hypergeometric_mean_variance(pop, successes, draws):
# Your code here
pass5 test cases · run your code against them in the editor