Last active
August 29, 2015 14:01
-
-
Save vi/d55ac171e1b6568276a9 to your computer and use it in GitHub Desktop.
Simple Perl script for playing with formula from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
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
| #!/usr/bin/perl -wln | |
| # Calculate lower and upper bounds of Wilson confidence interval based on upvotes and downvotes | |
| # Based on SQL expression from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
| # Confidence parameter is hardcoded at 95% | |
| # Each input line is two numbers: number_of_upvotes <whitespace> number_of_downvotes | |
| # Each output line is two numbers: minimal_estimated_ratio_of_upvoters <space> maximal_estimated_ratio_of_upvoters | |
| use strict; | |
| INIT { $|=1; } | |
| my ($positive, $negative) = /\S+/g; | |
| my $total = $positive + $negative; | |
| $total=0.0001 if $total==0; | |
| my $lower = (($positive + 1.9208) / $total - 1.96 * sqrt(($positive * $negative) / $total + 0.9604) / $total) / (1 + 3.8416 / $total); | |
| my $upper = (($positive + 1.9208) / $total + 1.96 * sqrt(($positive * $negative) / $total + 0.9604) / $total) / (1 + 3.8416 / $total); | |
| print "$lower $upper"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment