<s>[INST] Coin flip streak variance Let's say I flip a coin 12 times. Let $X$ be the number of streaks of 3 heads in a row. How do I calculate $var(X)$?
Example:
Let 'H' represent head And 'T' tail;
if we flip 4 times and get 'HHHH' its 2 streaks of 3 Heads.
if we flip 7 times and get 'HHHTHHH' it's also 2 streaks.
That's what I got so far:
$var(X) = E[X^2] - (E[X])^2$.
let $x_i = 1$ if its a start of 3 heads $else$ $x_i = 0$
$E[X] = E[x_1 + x_2 + ... + x_9 + x_{10}]$ = $10E[x_i] = 10P(x_i) = \frac{10}{2^3}$.
I'm stuck on how to calculate $E[X^2]$ ?
 [/INST] $$X=\sum_{i=1}^{10}X_i$$
\begin{align}
E[X^2] = E\left[\sum_{i=1}^{10}X_i\right]+2E\left[ \sum_{i<j}X_iX_j\right]
\end{align}
Note that we have  $E[X_iX_j]=\begin{cases} \frac1{2^4}, &j=i+1\\  \frac1{2^5}&, j=i+2\\ \frac1{2^6} &, j> i+2\end{cases}$
Let me compute the crossed terms:
\begin{align}
E\left[\sum_{i=1}^{9}\sum_{j=i+1}^{10}X_iX_j\right] &= \sum_{i=1}^7\sum_{j=i+1}^{10}E[X_iX_j]+E[X_8X_9]+E[X_8X_{10}] + E[X_9X_{10}]\\
&=\sum_{i=1}^7\left(\frac1{2^4}+\frac1{2^5}+\sum_{j=i+3}^{10}\frac1{2^6}  \right)+ \frac1{2^4} + \frac1{2^5} + \frac1{2^4}\\
&= 7\left( \frac1{2^4}+\frac1{2^5}\right)+\sum_{i=1}^7\frac{8-i}{2^6}+\frac{2}{2^4}+\frac1{2^5}\\
&=\frac9{2^4}+\frac{8}{2^5}+\frac{7}{2^3}-\frac{7(8)}{2}\cdot \frac1{2^6}\\
&=\frac9{2^4}+\frac{8}{2^5}+\frac{7}{2^3}-\frac{7}{2^4}\\
&=\frac2{2^4}+\frac{8}{2^5}+\frac{7}{2^3}\\
&= 1.25
\end{align}
I believe you can compute the variance now.
</s>