Created
August 20, 2017 15:52
-
-
Save RHeijnen/989dc0da5fce5c65e35e8e0eb1c12999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
spearman: function (values,x,y) { | |
var sum = 0; | |
var orderedList = []; | |
var length = values[x].length; | |
// for every point in | |
for(i=0;i<length;i++){ | |
orderedList.push([values[x][i], values[y][i]]); | |
} | |
orderedList.sort(function(a,b){ | |
return a[0]-b[0] | |
}); | |
for(i=0;i<length;i++){ | |
orderedList[i].push(i+1); | |
} | |
orderedList.sort(function(a,b){ | |
return a[1]-b[1] | |
}); | |
for(i=0;i<length;i++){ | |
orderedList[i].push(i+1); | |
} | |
for(i=0;i<length;i++){ | |
sum+=Math.pow((orderedList[i][2])-(orderedList[i][3]), 2); | |
} | |
var calc1 = length*length-1 | |
var calc2 = length*calc1 | |
var calc3 = 6*(sum/calc2) | |
var solution = 1 - calc3; // reverse answer | |
return solution; | |
//end | |
}, | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment