Created
April 3, 2012 20:09
-
-
Save abdollar/2295194 to your computer and use it in GitHub Desktop.
wilson score confidence interval - what percentage of people took some sort of action
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
| #pos is the number of positive ratings | |
| #n is the total number of ratings | |
| def score_ratings(pos, n) | |
| #modified shamelessly from http://evanmiller.org/how-not-to-sort-by-average-rating.html | |
| return 0 if n == 0 | |
| # require 'statistics2' | |
| # z = Statistics2.pnormaldist(1-(1-confidence)/2) | |
| # the z score refers to a confidence: pick 0.95 to have a 95% chance that your lower bound is correct, 0.975 to have a 97.5% chance, etc. | |
| # (Uses #1.96 for a confidence level of 0.95.) | |
| z = 1.96 | |
| 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