Created
April 4, 2021 08:10
-
-
Save erose/a1ea9c4d62895c796e28525991fe2c1b to your computer and use it in GitHub Desktop.
This file contains 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
# A solution to "how do I sort by average rating, while taking into account the fact that some things have more ratings than others and this provides more Bayesian evidence about their quality? See https://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
def ci_lower_bound(pos, n) | |
if n == 0 | |
return 0 | |
end | |
z = 1.96 # hardcoded confidence level of 0.95 | |
phat = 1.0*pos/n | |
midpoint = phat + z*z/(2*n) | |
half_width = z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n) | |
[(midpoint - half_width)/(1+z*z/n), (midpoint + half_width)/(1+z*z/n)] | |
end | |
p ci_lower_bound(81.83, 92.67) | |
p ci_lower_bound(48, 59) | |
p ci_lower_bound(152, 157) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment