I have this problem which I cant seem to solve. I would really appreciate some help in figuring out where I go wrong. I'm only doing the HH-part below.
(See edit below)
So the problem is
"A fair coin is flipped repeatedly and we count the number of flips required until the first occurence of the pattern HH. Let $X$ be this number and find the expected value of $X$. Then compute the variances of the waiting times for the patterns HH and TH. Use a recursive approach."
So, the first part involving finding the expected value of $X$ (for HH) is solved in the book with an recursive approach using the law of total expectation and conditioning on the outcome of the first two flips.
"There are three different possibilities: (1) the first flip gives T and we start over, (2) the first two flips give HT and we start over and (3) the first two flips gives HH and we are done."
They then solve this recursive equation by simply $E[X] = \mu = E[X|T]P(T)+E[X|HT]P(HT) + E[X|HH]P(HH)$ which gives
$\mu = (1+\mu)\frac{1}{2}+(2+\mu)\frac{1}{4} + 2\frac{1}{4} \implies \mu = 6$.
So far so good, I understand whats going on.
When I now, however, try to use the same approach in calculating $E[X^2]$ (which I later plan to use in Steiner's formula for $var(X)$) something goes wrong. I dont know why, because this should work. Perhaps I misunderstand the problem right from the start.
So, $E[X^2] = t = E[X^2|T]P(T)+E[X^2|HT]P(HT) + E[X^2|HH]P(HH)$
Now I note that $E[X^2|HH] = 2^2 = 4$ and $E[X^2|HT] = E[(X+2)^2]$ because we start over after two flips and thus it becomes $(X+2)^2$. In the same manner,
$E[X^2|T] = E[(X+1)^2]$.
After this, we simply solve for $t = E[X^2] = 8\mu +10$ (after some manipulation of the equation above).
Now, the $var(X) = E[X^2] - (E[X])^2 = 22$. According to the book the answer should however be $10$ (for HH). How can this be?
I would be very glad if someone could help me out on this one. Just nudge me in the right direction.
EDIT: It seems I was right in all my calculations above. Indeed, the answer in the book is wrong. However, I now struggle with the other part of the problem. I.e. for pattern TH. So let now $X$ denote the number of rolls until pattern TH.
I try to solve it in similar way. The difference this time is that if we condition on the first roll, we can either get H or T. And because $X|T \sim Geom(1/2)$, we get a slightly different calculation. I manage to get it wrong either way. The answer should be that the $var(X) = 4$ for TH (this is definitly correct).
We know (from the book) that, $E[X] = \mu = 4$. And $E[X^2] = E[X^2|H]*1/2 + E[X^2|T]*1/2 = E[(X+1)^2]*1/2 + E[X^2|T]*1/2$
and in general for $Y \sim Geom(p)$ we have $E[Y^2] = \frac{2-p}{p^2}$. Thus, in our case $E[X^2|T] = \frac{2-1/2}{1/4} + 1 = 6+1 =7$ and after some simple manipulation of the equation above we have
$E[X^2] = 2\mu + 8$. But this gives (for $\mu =4$) that the $var(X) = 0$ (?!).
What am I doing wrong now? Anyone?