Somer's D - mauriceling/mauriceling.github.io GitHub Wiki

Purpose: To measure the strength of the correspondence between two rankings.

Null hypothesis: Correlation coefficient = 0

Alternate hypothesis: Correlation coefficient ≠ 0.

Code 1 (correlation between 2 sets of data):

>>> from scipy import stats
>>> X = [1, 2, 3, 4, 5]
>>> Y = [5, 6, 7, 8, 7]
>>> result = stats.somersd(X, Y)
>>> print("D = %.3f" % result.statistic)
D = 0.700
>>> print("p-value = %.3f" % result.pvalue)
p-value = 0.007

Code 2 (correlation between the rows and columns of a table):

>>> from scipy import stats
>>> table = [[3, 6, 10], 
             [4, 10, 8], 
             [7, 4, 3]]
>>> result = stats.somersd(table)
>>> print("D = %.3f" % result.statistic)
D = -0.277
>>> print("p-value = %.3f" % result.pvalue)
p-value = 0.022

Reference:

  1. Somers RH. 1962. A New Asymmetric Measure of Association for Ordinal Variables. American Sociological Review 27(6), 799–811.