# Confidence interval around binomial estimate of 0 or 1

What is the best technique to calculate a confidence interval of a binomial experiment, if your estimate is that $p=0$ (or similarly $p=1$) and sample size is relatively small, for example $n=25$?

• How close to zero is $\hat{p}$? Is it zero often, or on the order of 0.001, or 0.01, or ...? And how much data do you have? – jbowman Oct 9 '18 at 17:06
• We usually have greater than 800 trials. We usually expect 0 to 0.1 for $\hat{p}$ – AI2.0 Oct 9 '18 at 17:21
• Use Clopper–Pearson interval you linked. The general principle: Try Clopper–Pearson interval first. If computer cannot get the answer, try the approximation method, such as normal approximation. According to the current computer speed, I do not think we need approximation on most situations. – user158565 Oct 9 '18 at 17:27
• For only getting the upper limit of the confidence interval with (1-$\alpha$ confidence level, we will just use B(1−$\alpha$;x+1,n−x) where x is the number of successes (or failures), n is the sample size. In python, we just use scipy.stats.beta.ppf(1−$\alpha$;x+1,n−x) . If this is TRUE, can we conclude that we are 1−$\alpha$ confident that the upper limit is bounded by the value we calculate from scipy.stats.beta.ppf(1−$\alpha$;x+1,n−x) ? – AI2.0 Oct 9 '18 at 18:19
• With 800 trials, the usual Normal approximation will work reasonably well down to about $p=0.015$ (my simulations indicated a 94.5% actual coverage of a 95% confidence interval.) At 1000 trials and $p=0.01$, the actual coverage was about 92.7% (all based on 100,000 replications.) So this is only an issue for very low $p$, given your trial count. – jbowman Oct 9 '18 at 18:23

library(binom)