// 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); }