Created
September 26, 2018 23:50
-
-
Save briandfoy/11c6fcedf5ef9d1fcee60b777c607dc5 to your computer and use it in GitHub Desktop.
Don't sort by average ratings
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
http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
sub ci_lower_bound ( $postive_ratings, $total_ratings, $confidence = 0.95 ) { | |
return 0 if $total_ratings == 0; | |
my $z = 1.96; | |
my $p_hat = $postive_ratings / $total_ratings; | |
( $phat + $z**2/(2*$total_ratings) | |
- z * | |
sqrt( ( $phat*(1-$phat) + (z**2/(4*$total_ratings)) ) / $total_ratings ) | |
/ | |
(1 + z**2/$total_ratings) | |
( | |
phat + z*z/(2*n) - z * Math.sqrt( | |
( phat*(1-phat)+z*z/(4*n) ) / n | |
) | |
)/(1+z*z/n) | |
__END__ | |
require 'statistics2' | |
def ci_lower_bound(pos, n, confidence) | |
if n == 0 | |
return 0 | |
end | |
z = Statistics2.pnormaldist(1-(1-confidence)/2) | |
phat = 1.0*pos/n | |
(phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment