Skip to content

Instantly share code, notes, and snippets.

@dheerajrajagopal
Created July 2, 2012 06:39
Show Gist options
  • Select an option

  • Save dheerajrajagopal/3031480 to your computer and use it in GitHub Desktop.

Select an option

Save dheerajrajagopal/3031480 to your computer and use it in GitHub Desktop.
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)
return t # returns a tuple with center and the wilson interval
print wilson(550, 276)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment