# Number of Bernoulli trials until success, for successful attempts

Given a Bernoulli trial with probability of success p and a number of trials x, what is the expected number of trials until success in a case success was achieved in x trials? It is assumed that after a successful attempt, the single experiment ends and no further trials are taken.

e.g. if p = 0.02 and x = 60, I would like to find the expected number of trials taken in case success was obtained 60 trials. Indeed there is a chance to fail all 60, but I'm interested, for the case of success within 60 trials, in the average/expected number of trials it takes. I understand it is lower than 1/0.02 and decreases with x.

• So you want to find, given that there was at least one success, the expected number of trials taken to reach the first success? Jul 7, 2019 at 20:44
• Well for the case of p = 0.02 and x = 60, I understand that 1-((1-0.02)^60) ~ 0.7 of experiments result in success. For those experiments, what is the expected number of trials to reach first (and only) success? Jul 7, 2019 at 20:54
• Are you only considering experiments with exactly one success? Jul 7, 2019 at 20:56
• Yes the experiment terminates after a successful attempt Jul 7, 2019 at 20:57

The waiting time to the first success is geometrically distributed: $$P(T\le t) = 1-(1-p)^{t}.$$ You are interested in conditioning on $$T\le 60,$$ so for $$t\le 60,$$ we have $$P(T\le t\mid T\le 60) = \frac{P(T\le t,T\le 60)}{P(T\le 60)} = \frac{P(T\le t)}{P(T\le 60)} =\frac{1-(1-p)^{t}}{1-(1-p)^{60}},$$ and differencing gives $$P(T=t\mid T\le 60) = \frac{p(1-p)^{t-1}}{1-(1-p)^{60}}.$$ Thus, $$E(T\mid T\le 60) = \frac{p}{1-(1-p)^{60}}\sum_{t=1}^{60}t(1-p)^{t-1}.$$
This sum can be done in closed form using a standard trick $$\sum_{t=1}^{60}tz^{t-1}= \frac{d}{dz}\sum_{t=1}^{60} z^t = \frac{d}{dz}\frac{z-z^{61}}{1-z}=\frac{z-z^{61}}{(1-z)^2}+\frac{1-60z^{59}}{1-z}$$ so taking $$z=1-p,$$ we have $$E(T\mid T\le 60) = \frac{1-z}{1-z^{60}}\left(\frac{z-z^{61}}{(1-z)^2}-\frac{1-61z^{60}}{1-z}\right) = \frac{1-p}{p} + \frac{1-61(1-p)^{60}}{1-(1-p)^{60}}\\= \frac{1}{p}- \frac{60(1-p)^{60}}{1-(1-p)^{60}}$$