Skip to content

Instantly share code, notes, and snippets.

@timelf123
Forked from honza/description.md
Created September 22, 2017 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelf123/2b9dff57449f5bf980446cbc73244c69 to your computer and use it in GitHub Desktop.
Save timelf123/2b9dff57449f5bf980446cbc73244c69 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