Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-038

Pooled Variance

Problem

Return the pooled variance ((n1-1)*var1 + (n2-1)*var2) / (n1 + n2 - 2) using sample variances. Return 0.0 when either sample is empty or the total degrees of freedom is not positive.

Hint

Sum the sums of squares and divide by n1 + n2 - 2.

Test cases

case 1
in: [[1,2,3,4,5],[2,4,6,8,10]]
expected: 6.25
case 2
in: [[1,1,1],[5,5,5]]
expected: 0
case 3
in: [[1,2,3],[4,5,6]]
expected: 1
case 4
in: [[1,2],[3,4]]
expected: 0.5
case 5
in: [[5],[1,2]]
expected: 0.5
Starter codePython
def pooled_variance(x, y):
    # Your code here
    pass

5 test cases · run your code against them in the editor