Spearman's rank correlation coefficient - mauriceling/mauriceling.github.io GitHub Wiki

Purpose: To measure the strength of relationship between 2 variables.

Null hypothesis: Correlation coefficient = 0

Alternate hypothesis: Correlation coefficient ≠ 0.

Note: Spearman's correlation coefficient is defined as the Pearson's correlation coefficient between the rank variables; hence, a non-parametric measure.

Code:

>>> from scipy import stats
>>> X = [1, 2, 3, 4, 5]
>>> Y = [5, 6, 7, 8, 7]
>>> result = stats.spearmanr(X, Y)
>>> print("Spearman's correlation coefficient = %.3f" % result.correlation)
Spearman's correlation coefficient = 0.821
>>> print("p-value = %.3f" % result.pvalue)
p-value = 0.089