Skip to content

Instantly share code, notes, and snippets.

@frankbi
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankbi/7da5399f46ee5c99e3ba to your computer and use it in GitHub Desktop.
Save frankbi/7da5399f46ee5c99e3ba to your computer and use it in GitHub Desktop.
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