Skip to content

Instantly share code, notes, and snippets.

@jasonreposa
Created April 3, 2012 14:02

Revisions

  1. jasonreposa created this gist Apr 3, 2012.
    10 changes: 10 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
    // http://gist.github.com/raw/63002/b53853727856bad494dcbb7ffed4fc17f289af92/gistfile1.rb

    // $z is the pnormaldist with power = 0.05. I.e., pnormaldist(1-power/2)
    function score($pos, $n) {
    if ($n == 0) { return 0; }
    $z = 1.95996397158435;
    $phat = 1.0*$pos/$n;
    return ($phat + $z*$z/(2*$n) - $z * sqrt(($phat*(1-$phat)+$z*$z/(4*$n))/$n))/(1+$z*$z/$n);
    }