# A coin with probability $p$ for heads is rolled time after time until we get heads twice

A coin with probability $p$ for heads is rolled time after time. Let $X$ be the number of rolls until we get heads twice. Find the probability mass function $p_x$.

I thought this would entail using the geometric distribution multiplied twice; once for the first roll ($k$ attempts), second for the first roll but according to the given answers it seems my logic is incorrect.

I'd appreciate a correction to my thought process.

Since we're looking for $2$ successes (H), we need to count the number of times it took us to get our first success.

$k$ = number of attempts until first success. $n$ = number of attempts until second success

Therefore there are k+n attempts.

Using geometric distribution:

$$\left((q)^{k-1}p\right)\left(q)^{n-1}p\right)=q^{n+k-2}p^2$$

As I said this answer is incorrect. I'd like to know where I went wrong with my train of thought.

• is it a die or a coin? Commented Aug 1, 2016 at 18:45
• @CarryonSmiling coin, sorry. Commented Aug 1, 2016 at 18:46
• Your way will work, but is a bit more work than the solution by Carry on Smiling. We want $\Pr(X=x)$. Set $n+k=x$. This is the sum from $k=1$ to $x-1$ of $q^{k-1}pq^{x-k-1}p$. (I replaced your $n$ by $x-k$.) The terms are all the same, $q^{x-2}p^2$, and there are $x-1$ of them so the probability is $\dots$. For the waiting time until $w$ successes instead of $2$, the method of Carry on Smiling extends easily, but the above method becomes a little painful. Commented Aug 1, 2016 at 19:20
• Rolling a coin is a bit funny, but not as funny as flipping a die :) Commented Aug 1, 2016 at 19:46

If I'm understanding correctly you want to find the probability it takes exactly $n$ tosses to get two heads.

This is equal to the probability of getting a head on toss number $n$ multipled by the probabily of getting exactly $1$ head in the first $n-1$ rolls.

The first probability is clearly $p$, while the second is $n-1\times(p(1-p)^{n-2})$, beacause there are $n-1$ options for the first "heads" toss, and each one has probability $p(1-p)^{n-2}$ since we need $n-2$ tails and one heads.

Therefore the probability the second heads is tossed at the $n$'th trial is $(n-1)p^2(1-p)^{n-2}$

Suppose we are interested in the random number $X$ of (total) coin tosses needed to observe the $r^{\rm th}$ head, for $r \ge 1$. We can reason as follows: the outcome of each coin toss is an IID Bernoulli random variable with probability of "success" (in this case, obtaining a head) $p$. Then if we observe $X = x$, this implies that the final toss corresponded to the $r^{\rm th}$ head observed, and that the other $r-1$ heads obtained could be arranged among the previous $x-1$ tosses. The number of ways to arrange $r-1$ heads among $x-1$ tosses is $$\binom{x-1}{r-1},$$ and the probability of each such arrangement is $p^{r-1} (1-p)^{x-r}$. Then multiplying by the probability of observing heads on the last toss, we get $$\Pr[X = x] = \binom{x-1}{r-1} p^r (1-p)^{x-r}, \quad x = r, r+1, r+2, \ldots.$$ Of course, $\Pr[X < r] = 0$: in order to observe $r$ heads, we must flip the coin at least $r$ times. The above probability mass function is one parametrization of the negative binomial distribution.

In your case $r = 2$ yields the PMF $$\Pr[X = x] = (x-1) p^2 (1-p)^{x-2}, \quad x = 2, 3, \ldots.$$

If I understand the question correctly, you are flipping a coin (or conducting some kind of Bernoulli Trial) with probability $p$ of success and you want to find the probability the the 2nd success occurs on the $x$th flip. The probability of getting a success on trails $x$ and $k<x$ and no others is $(1-p)p^2$, since there are $2$ successes and $x-2$ failures with one possible ordering. However, there are $x-1$ possible values for $k$. Summing all of these possibilities gives the total probability of the 2nd success occurring on the $x$th trial.

$$P(x)=(x-1)(1-p)^{x-2}p^2$$

Let $X_1, X_2$ be independent geometric random variables with probability mass function (PMF)

$$p_{X_i} (k) := (1-p)^{k-1} p$$

for $k \geq 1$. Let

$$Y := X_1 + X_2$$

Hence, since $X_1, X_2$ are independent, the PMF of $Y$ is the convolution of the PMF's of $X_1,X_2$

$$\begin{array}{rl} p_Y (k) &= (p_{X_1} \ast p_{X_2}) (k)\\ &= \displaystyle\sum_{m=1}^{k-1} p_{X_1} (m) \, p_{X_2} (k-m)\\ &= \displaystyle\sum_{m=1}^{k-1} (1-p)^{k-2} p^2\\ &= (k-1) (1-p)^{k-2} p^2\end{array}$$

for $k \geq 2$.

As I said this answer is incorrect. I'd like to know where I went wrong with my train of thought

Well, you were almost there.   You have actually found the joint distribution: $$\mathsf P(Y=k, X-Y=n)~=~q^{n+k-2}p^2 ~~\Big[k\in\{1,..\}, n\in\{1,..\}\Big]$$

However, you need not care about $Y$ (that is when the first success happens), all you are after is the probability distribution of $X$ (that is when the second success happens).

Now, let $x=k+n$ and "sum out" the variable $k$ to obtain the marginal distribution.   Since the first success cannot occur after the second (clearly), then summation range must be $1$ to $x-1$.  So:

$$\mathsf P(X=x) ~=~ \sum_{k=1}^{x-1} \mathsf P(Y=k, X=x) ~=~ \sum_{k=1}^{x-1} q^{x-2}p^2 ~=~ (x-1)q^{x-2}p^2~~\Big[x\in\{2,..\}\Big]$$

Which is, as others have shown from first principles, the probability for obtaining exactly one success somewhere within the first $x-1$ trials, and then a second success on trial $x$.