# How does Clopper and Pearson interval compute

Suppose we have $$10$$ observations and we run $$20$$ trials. A two-sided binomial test with $$H_0:p=0.4$$ from R I get is

binom.test(x=10, n = 20, p = 0.4, alternative = c("two.sided"))
Exact binomial test

data:  10 and 20
number of successes = 10, number of trials = 20, p-value = 0.3703
alternative hypothesis: true probability of success is not equal to 0.4
95 percent confidence interval:
0.2719578 0.7280422
sample estimates:
probability of success
0.5


if I assume $$H_0:p=0.3$$, I get

Exact binomial test

data:  10 and 20
number of successes = 10, number of trials = 20, p-value = 0.08345
alternative hypothesis: true probability of success is not equal to 0.3
95 percent confidence interval:
0.2719578 0.7280422
sample estimates:
probability of success
0.5


The confidence intervals in both cases are identical. I believe that is because of a same number of observations. I found this article about the confidence intervals. But it doesn't tell me how to find k and both lower bound and upper bound.

• k is the number of events in the sample. Oct 25, 2022 at 5:34
• You might be interested in this question: The basic logic of constructing a confidence interval. The answer explains the confidence interval by using an example of the Clopper Pearson interval. Also it contains a link to the original article. Oct 25, 2022 at 14:44
• Also related stats.stackexchange.com/questions/351320 Note that the 95% confidence intervals are the same (these intervals are function of only the data at the confidence level) but the p-values are not (which also depend on the hypothesis). Oct 25, 2022 at 14:51

Confidence intervals are identical because number of trials, number of successes, and $$\alpha$$ are the same. In the linked text, it shows "a more common way to represent the Binomial Exact CI," using the relationship between the binomial CDF and the beta distribution (aka Clopper-Pearson Method). A similar formula:

$$P_{lb} = B(\alpha/2;k, n-k+1)\text{ and } P_{ub} = B(1-\alpha/2;(k+1), (n-k))$$

Where $$n$$ is the number of trials, $$k$$ number of successes, and $$\alpha$$ the level of significance. It is easy to implement this formula in R using qbeta:

n <- 20
k <- 10
a <- 0.05

qbeta(a/2, k, n-k+1)
[1] 0.2719578
qbeta((1-a/2), k+1, n-k)
[1] 0.7280422


As you can see, these are the results you get with binom.test because it also uses Clopper-Pearson interval.