All problems
Stratified Variance
Problem
Return the stratified sampling variance sum(w_h^2 * var_h / n_h) for the given per-stratum variances, sample sizes, and weights. Strata with n_h <= 0 are skipped and empty input returns 0.0.
Hint
Each stratum contributes its weighted squared share.
Test cases
case 1
in: [[4,9],[10,20],[0.5,0.5]]
expected: 0.21250000000000002
case 2
in: [[1],[10],[1]]
expected: 0.1
case 3
in: [[4,9],[10,0],[0.5,0.5]]
expected: 0.1
case 4
in: [[],[],[]]
expected: 0
case 5
in: [[1,1],[5,5],[0.2,0.8]]
expected: 0.13600000000000004
Starter codePython
def stratified_variance(variances, sizes, weights):
# Your code here
pass5 test cases · run your code against them in the editor