Skip to content

Instantly share code, notes, and snippets.

@honza
Last active January 4, 2022 00:54
Show Gist options
  • Save honza/5050540 to your computer and use it in GitHub Desktop.
Save honza/5050540 to your computer and use it in GitHub Desktop.
Ranking algorithm - Lower bound of Wilson score confidence interval for a Bernoulli parameter All implementations use 95% probability.

Ranking algorithm

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.

Source

(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment