Created
October 29, 2013 09:09
-
-
Save dhotson/7211314 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
function wilson($p, $n) { | |
$z = 1.9599; | |
$z2 = pow($z, 2); | |
return array( | |
($p + $z2/(2*$n) - $z * sqrt(($p*(1-$p) + $z2/(4*$n)) / $n)) / (1 + $z2/$n), | |
($p + $z2/(2*$n) + $z * sqrt(($p*(1-$p) + $z2/(4*$n)) / $n)) / (1 + $z2/$n), | |
); | |
} | |
for ($i=0; $i<4; $i++) { | |
$n = pow(10, $i); | |
for ($r=0; $r<=5; $r++) { | |
$rating = $r*2 / 10; | |
list($lb, $ub) = wilson($rating, $n); | |
printf("n=%5d | %5.1f -> %5.1f -> %5.1f\n", $n, $lb*100, $rating*100, $ub*100); | |
} | |
printf("\n"); | |
} |
Author
dhotson
commented
Oct 29, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment