import numpy as np def kendall_w(scores): """ :param scores: rows correspond to category levels, e.g., for QS this would be unc. sampling, CAL etc, and the columns correspond to the scores. :return: """ if scores.ndim!=2: raise 'scores matrix must be 2-dimensional' m = scores.shape[0] # raters/levels n = scores.shape[1] # items rated score_ranks = np.argsort(scores, axis=1) denom = m**2*(n**3-n) rating_sums = np.sum(score_ranks, axis=0) S = n*np.var(rating_sums) return 12*S/denom