# Binomial trials required to achieve a given probability of at least one success

If p is the probability of success of a binomial trial i would like to calculate the number of trials n required that if performed would give a probability x of at least one success. Is there a way to obtain this n in R? I have a large vector of probabilities and would like to extract this n for a given x.

Thank you

The probability of at least one success, x, is 1-p(no successes), which is equal to 1-p(fail)^n, which in turn is equal to 1-(1-p(success))^n.

So, to rearrange this to get n = log(1-x)/log(1-p)

p <- c(.2,.3,.5)
x <- 0.5
n <- log(1-x)/log(1-p)


Of course you can only have an integer number of trials, so you need to use ceiling on this:

ceiling(n)
[1] 4 2 1


For n trials, and probability p, the number of expected successes is n*p. So, just rearrange the terms. If expected successes = 1, then 1=n*p, so n=1/p. This can be easily calculated in R:

probabilities = c(.2,.3,.5)
1/probabilities

• The expected value is correct, but it does not answer the question! – whuber Mar 7 '12 at 23:27