Skip to content

Instantly share code, notes, and snippets.

@jasonreposa
Created April 3, 2012 14:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonreposa/2292254 to your computer and use it in GitHub Desktop.
Save jasonreposa/2292254 to your computer and use it in GitHub Desktop.
// 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment