Created
February 13, 2009 02:16
-
-
Save renatoalbano/63002 to your computer and use it in GitHub Desktop.
How Not To Sort By Average Rating
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
# How Not To Sort By Average Rating | |
# url: http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
# lib: http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2/ (need compile) | |
# statistics2 disabled | |
#require 'statistics2' | |
def ci_lower_bound(pos, n, power) | |
if n == 0 | |
return 0 | |
end | |
# statistics2 disabled / z hardcoded | |
#z = Statistics2.pnormaldist(1-power/2) | |
#z = Statistics2.pnormaldist(1-0.05/2) = 1.95996397158435 | |
z = 1.95996397158435 | |
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 | |
puts ci_lower_bound(234, 600, 0.05) # 0.351790426361396 | |
puts ci_lower_bound(2, 5, 0.05) # 0.11762077514747 | |
puts ci_lower_bound(398, 400, 0.05) # 0.981955081697407 | |
puts ci_lower_bound(19999, 20000, 0.05) # 0.999716809432394 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment