Skip to content

Instantly share code, notes, and snippets.

@frankbi
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save frankbi/7da5399f46ee5c99e3ba to your computer and use it in GitHub Desktop.

Select an option

Save frankbi/7da5399f46ee5c99e3ba to your computer and use it in GitHub Desktop.

Revisions

  1. frankbi revised this gist May 6, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,8 @@ function getSpearmanRankCorrelation(list_x, list_y) {
    summation += Math.pow((sorted_x[i][1] - sorted_y[i][1]), 2);
    }

    var rank = 1 - ((6 * summation) / (n * (Math.pow(n, 2) - 1)));
    var index = 1 - ((6 * summation) / (n * (Math.pow(n, 2) - 1)));

    return rank;
    return index;

    };
  2. frankbi created this gist May 6, 2014.
    22 changes: 22 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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 rank = 1 - ((6 * summation) / (n * (Math.pow(n, 2) - 1)));

    return rank;

    };