Created
July 2, 2012 06:39
-
-
Save dheerajrajagopal/3031480 to your computer and use it in GitHub Desktop.
python code to find the wilson interval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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