Lower bound of Wilson score confidence interval for a Bernoulli parameter
All implementations use 95% probability.
pos is the number of positive votes, n is the total number of votes.
Lower bound of Wilson score confidence interval for a Bernoulli parameter
All implementations use 95% probability.
pos is the number of positive votes, n is the total number of votes.
| (ns ranking.core | |
| (:use clojure.contrib.math) | |
| (:gen-class)) | |
| (def z 1.96) | |
| (defn ci | |
| [pos n] | |
| (let [phat (/ (* 1.0 pos) n)] | |
| (/ (- (+ phat | |
| (/ (* z z) | |
| (* n 2))) | |
| (* z | |
| (sqrt (/ (+ (* phat | |
| (- 1 phat)) | |
| (/ (* z z) | |
| (* 4 n))) | |
| n)))) | |
| (+ 1 (/ (* z z) n))))) | |
| (defn -main | |
| [& args] | |
| (println (ci 600 1000)) | |
| (println (ci 5500 10000))) |
| function ci(pos, n) { | |
| var z, phat; | |
| z = 1.96; | |
| phat = 1 * pos / n; | |
| return (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n); | |
| } | |
| console.log(ci(600, 1000)); | |
| console.log(ci(5500, 10000)); |
| import math | |
| def ci(pos, n): | |
| z = 1.96 | |
| phat = 1.0 * pos / n | |
| return (phat + z*z/(2*n) - z * math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n) | |
| print ci(600, 1000) | |
| print ci(5500, 10000) |