[Math] How to calculate expected number of trials of this geometric distribution

expectationprobabilityprobability distributionsstatistics

I understand why the expected number of trials until there is a success is given by

$$ \sum_{i=0}^{\infty} i p q^{i-1} \ = \ E[\text{number of trials until} \ X=1] = \frac{1}{p} $$

where $p$ is the probability of success and $X=1$ denotes the first success. However, I have different problem. In my setting, after the $n$th trial there will be success with probability 1. The probability of a success happening at the $i$th period [before n periods] is $p(1-p)^{i-1}$. I suspect that the expected amount of trials until success is given by

$$ p + 2p(1-p) + 3p(1-p)^2 + …+ np(1-p)^{n-1} $$

I am not sure if the correct answer is either

$$ \frac{1-(1-p)^n}{p} $$

or

$$ \frac{1-(1-p)^n}{p} -n(1-p)^n $$

I have tried using a few partial sum tricks and forcing the addition of probabilities equal to one in the following way:

$$ \sum_{i=0}^{n} p (1-p)^{i-1} + (1-p)^{n-1} \ = 1 $$

But I am not sure if this is the right way to even approach the question. How can I calculate the expected value of trials until the first success when I know that at a some $n$th period there will be success with probability 1?

Best Answer

Define the random variable $X = \sum_{i \leqslant n}i{\bf 1}_{\{\text{1st success on trial }i\}}$ , so that the expectation is computed as follows: $$\mathbb E[X] = \mathbb E[\sum_{i \leqslant n}i{\bf 1}_{\{\text{1st success on trial }i\}}] = \sum_{i \leqslant n}\mathbb E[i{\bf 1}_{\{\text{1st success on trial }i\}}] = \sum_{i \leqslant n}i{\bf P}[{\text{1st success on trial }i}] \\ = \sum_{i < n}i(1-p)^{i-1}p + n(1-p)^{n-1} = \frac{1-(1-p)^{n-1}(1+(n-1)p)}{p} + n(1-p)^{n-1}.$$

That is,

$$ \mathbb E[X] = \frac{1-(1-p)^{n-1}(1+(n-1)p)}{p} + n(1-p)^{n-1} $$


The form of $\mathbb E[X]$ can be simplified further, since $$\mathbb E[X] = \frac{1-(1-p)^{n-1}(1+(n-1)p)}{p} + n(1-p)^{n-1} = \frac{1-(1-p)^{n-1}(1+(n-1)p - np))}{p} = \frac{1-(1-p)^n}{p}$$ Therefore,

$$ \mathbb E[X] = \frac{1-(1-p)^n}{p} $$