All problems
Cohen's d
Problem
Return Cohen's d = (mean_x - mean_y) / sp with pooled standard deviation sp = sqrt(((n1-1)s1^2 + (n2-1)s2^2)/(n1+n2-2)). Return 0.0 when either sample has fewer than two values or the pooled variance is zero.
Hint
Standardized mean difference with a pooled within-group standard deviation.
Test cases
case 1
in: [[1,2,3,4,5],[2,4,6,8,10]]
expected: -1.2
case 2
in: [[1,2,3],[4,5,6]]
expected: -3
case 3
in: [[1,1,1],[2,2,2]]
expected: 0
case 4
in: [[10,12,14],[9,11,13]]
expected: 0.5
case 5
in: [[1],[2,3]]
expected: 0
Starter codePython
def cohens_d(x, y):
# Your code here
pass5 test cases · run your code against them in the editor