Skip to content

Instantly share code, notes, and snippets.

@abhishek-ghose
Created July 31, 2024 07:36
Show Gist options
  • Select an option

  • Save abhishek-ghose/04750e46ebaf27117ea6745019918276 to your computer and use it in GitHub Desktop.

Select an option

Save abhishek-ghose/04750e46ebaf27117ea6745019918276 to your computer and use it in GitHub Desktop.

Revisions

  1. abhishek-ghose created this gist Jul 31, 2024.
    18 changes: 18 additions & 0 deletions kendal_W.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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