All problems
Cronbach's Alpha
Problem
Return Cronbach's alpha (k/(k-1)) * (1 - sum(item variances)/total variance) for a list of items, where each item is a list of subject scores and variances are population variances. Return 0.0 when there are fewer than two items, lengths are inconsistent, or the total variance is zero.
Hint
Internal consistency grows with the average inter-item covariance.
Test cases
case 1
in: [[[1,2,3,4],[1,2,3,4]]]
expected: 1
case 2
in: [[[1,2,3,4],[4,3,2,1]]]
expected: 0
case 3
in: [[[1,1,2,3],[2,1,2,3]]]
expected: 0.9142857142857144
case 4
in: [[[5,5],[5,5]]]
expected: 0
case 5
in: [[[1,2],[1,2,3]]]
expected: 0
Starter codePython
def cronbach_alpha(items):
# Your code here
pass5 test cases · run your code against them in the editor