We can use statsmodels to calculate the confidence interval of the proportion of given ’successes’ from a number of trials. This may the frequency of occurrence of a gene, the intention to vote in a particular way, etc.

import statsmodels.stats.proportion as smp
# e.g. 35 out of a sample 120 (29.2%) people have a particular gene type.
# What are the 95% confidence intervals on the proportion?
lower, upper = smp.proportion_confint (35, 120, alpha=0.05, method='normal')
print ('Lower confidence interval:', lower)
print ('Upper confidence interval:', upper)
OUT:
Lower confidence interval: 0.21034248403748906
Upper confidence interval: 0.3729908492958443

Interests are use of simulation and machine learning in healthcare, currently working for the NHS and the University of Exeter. Committed to all work being performed in Free and Open Source Software (FOSS), and as much source data being made available as possible.
https://gitlab.com/michaelallen1966
View all posts by Michael Allen

Published

One thought on “57. Statistics: Confidence Interval for a single proportion”

## One thought on “57. Statistics: Confidence Interval for a single proportion”