Question: We toss a coin until we get 2 consecutive heads, but the probability, $p$, of the coin landing heads is beta distributed with parameters $p \sim \beta(6, 8)$. What is the expected number of flips until two heads show consecutively?

So, previously I have done a very similar problem that is essentially the same problem except that the probability of the coin showing heads is simply $\frac{1}{2}$, not beta distributed. In this simple case, the way that we can find the expected number of flips until 2 consecutive heads is the following:

Let $X$ be the number of coin flips until 2 consecutive heads land. Let $H_{i}$ be the event of landing heads on the $i^{th}$ toss, and same for $T_{i}$ being tails. Then $E(X)$ may be conditioned on the first and second tosses.

$$ E(X) = E(X | H_1) P(H_1) + E(X|T_1)P(T_1)$$

by law of total expectation. Now, the probabilities in this equation are easy, both are $\frac{1}{2}$. Then, we can write $E(X | T_1) = 1 + E(X)$ because landing tails on the first toss is essentially like wasting that toss and starting over. Then,

$$ E(X | H_1) = E(X|H_1, H_2)P(H_2) + E(X|H_1, T_2)P(T_2) $$

where we then condition on the second toss. The probabilities are again the same, and we can write all of the conditional expectations in terms of $E(X)$, where $E(X|H_1, H_2) = 2$ and $E(X|H_1, T_2) = 2 + E(X)$. We can then solve for $E(X)$ plugging into the original equation.

However, in this case, we do not have that these probabilities are so simple, and rather it seems to me that we must condition $X$ on the random variable $P$ for the probability. My confusion and main concern for this is that I still intuitively think that we should still set the problem up and solve it in a very similar way to the simple case in that we need to condition $X$ on the first and second tosses. I am really confused on how to condition $X$ on both the probability and the tosses at the same time and how to express this in the forms of conditional expectations.


1 Answer 1


For fixed $p\in(0,1)$ let $X_p$ the number of tosses needed to arrive at $2$ consecutive heads when the probability on heads is $p$.

Now find $f(p):=\mathbb E[X_p]$.

(Actually you have done that for special case $p=\frac12$ which gives me the impression that you can also do it for a fixed $p\in(0,1)$)

Now let $P$ be a random variable that has the beta-distribution you mentioned.

Then also $f(P)$ is a random variable and this fortunately with:$$\mathbb EX=\mathbb Ef(P)$$ where $X$ denotes the random variable prescribed in your question.

It is an application of the general rule:$$\mathbb EY=\mathbb E[\mathbb E[Y\mid Z]]$$

This with $Y:=X$ and $Z:=P$.

Another notation for $f(p)$ is $\mathbb E[X\mid P=p]$.

  • $\begingroup$ I understand with what you have said, and what I think is mostly the root of my confusion is that by doing $E(X) = E(E(X|P))$, we have that $E(X|P)$ is a function of the random variable P, and we can find this function by computing $\sum_{x=2}^{\infty}{x P_{X|P}(x|p)}$. BUT, the method in the simple case did not use a direct method like this to compute the expected value using the conditional density of X. Instead, we were able to set up an algebra problem to solve for $E(X)$. May we perform a similar simplification here? $\endgroup$
    – Eoin S
    Commented Apr 16, 2020 at 17:31
  • $\begingroup$ I don't think things can be made more simple than as how they are stated in my answer. In an effort to somehow "bypass" the "conditional" computation that you mention in your comment I deliberately introduced random variable $X_p$ connected with fixed $p$. $\mathbb EX_p$ can be found as expression in $p$ just straightforward based on its distribution and during this process you do not need to identify it with "$X$ under condition $P=p$" (an algebra problem as you call it). That comes after the process: the result is $f(p)=\mathbb E[X\mid P=p]$ and consequently $f(P)=\mathbb E[X\mid P]$. $\endgroup$
    – drhab
    Commented Apr 16, 2020 at 18:10

You must log in to answer this question.