Skip to content

Instantly share code, notes, and snippets.

View dheerajrajagopal's full-sized avatar

Dheeraj Rajagopal dheerajrajagopal

View GitHub Profile
@dheerajrajagopal
dheerajrajagopal / wilson.py
Created July 2, 2012 06:39
python code to find the wilson interval
#! /usr/bin/env python
import math
def wilson( total, correct):
z = 1.96 # can be changed to a suitable value you want.
p = float(correct) / total
center = (p + 1 / 2.0 / total * z * z) / (1 + 1.0 / total * z * z)
d = z * math.sqrt((p * (1 - p) + 1 / 4.0 / total * z * z) / total) / (1 + 1.0 / total * z * z)
t = (center, d)