Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spearman Rank Correlation Index
function getSpearmanRankCorrelation(list_x, list_y) {
var n;
if (list_x.length !== list_y.length)
throw "Error: Lists are of different length";
else n = list_x.length;
sorted_x = list_x.sort();
sorted_y = list_y.sort();
var summation = 0;
for (var i = 0; i < n; i++) {
summation += Math.pow((sorted_x[i][1] - sorted_y[i][1]), 2);
}
var index = 1 - ((6 * summation) / (n * (Math.pow(n, 2) - 1)));
return index;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment