Skip to content

Instantly share code, notes, and snippets.

@abhishek-ghose
Created July 31, 2024 07:36
Show Gist options
  • Save abhishek-ghose/04750e46ebaf27117ea6745019918276 to your computer and use it in GitHub Desktop.
Save abhishek-ghose/04750e46ebaf27117ea6745019918276 to your computer and use it in GitHub Desktop.
Calculates Kendal's W from scores, by calculating ranks first.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment