2018-10-03 18:59:01 +00:00
|
|
|
# http://stackoverflow.com/questions/20799403/improving-performance-of-cronbach-alpha-code-python-numpy
|
|
|
|
# pythran export cronbach(float [][])
|
|
|
|
# setup: import numpy as np ; N = 600 ; items = np.random.rand(N,N)
|
|
|
|
# run: cronbach(items)
|
2018-10-03 12:38:48 +00:00
|
|
|
|
|
|
|
|
2018-04-05 22:07:33 +00:00
|
|
|
def cronbach(itemscores):
|
|
|
|
itemvars = itemscores.var(axis=1, ddof=1)
|
|
|
|
tscores = itemscores.sum(axis=0)
|
|
|
|
nitems = len(itemscores)
|
2018-10-03 18:59:01 +00:00
|
|
|
return nitems / (nitems - 1) * (1 - itemvars.sum() / tscores.var(ddof=1))
|