# Calculate the number of trials needed to achieve certain number of successes at a confidence level

If I know the probability of success for an event, the number of time that I want to observe the event at a certain confidence level how do I calculate the number of trials needed?

Let's say your Success probability is $$p=0.3,$$ your target number of Successes is $$k = 10$$ and your target probability of fulfillment is 0.95.

Then you seek $$n$$ sufficiently large that $$P(X \ge 10) = 0.95,$$ given that $$X \sim \mathsf{Binom}(n, p=0.3).$$

For most values of $$p,$$ you could get a close answer by obtaining a normal approximation of $$P(X \ge 10)$$ and solving for $$n.$$

However, it is simple to search for $$n$$ using R. First, we guess that $$n = 100$$ might we large enough. So we use R to find that $$P(X \ge 10) = 1 - P(X \le 9) = 0.9999996 > 0.95,$$ using pbinom, which denotes a binomial CDF in R:

1 - pbinom(9, 100, .3)
[1] 0.9999996


Also it is obvious that $$n \ge 10.$$ So we look at all values of $$n$$ between 10 and 100 inclusive, and pick the smallest $$n$$ that works. [In R, n is a numerical vector of length 91, thus bpr is a numerical vector of length 91, and bpr >= .95 is a logical vector of length 91, containing TRUEs and FALSEs, You can read the bracket notation [ ] as "such that." ]

n = 10:100;  k = 10;  p= .3
bpr = 1 - pbinom(k-1, n, p)
min(n[bpr >= .95])
[1] 49


Thus $$n = 49$$ should be barely large enough and $$n = 48$$ not quite large enough. We verify that this is true:

1 - pbinom(9, 49, .3)
[1] 0.9520446
1 - pbinom(9, 48, .3)
[1] 0.9430372

• Thank you for the detailed answer. Does this problem/test have a name? – nex Jul 18 at 16:19