Number of identical blocks of weather when weather is independent across days Please help or provide some direction!
The problem is as follows:
On a given day, the weather can either be sunny (with probability 0.4), cloudy (with probability 0.4), or rainy (with probability 0.2).
Define blocks of weather to be the largest possible groups of consecutive days in which the weather is the same. For example, if it rained for eight days, followed by a day of sun, then a day of rain, we'd have three blocks.
The weather follows a first-order Markov process with the transition matrix:
\begin{bmatrix}
.5 & .25 & .25 \\
.5 & .25 & .25 \\
0 & 1 & 0
\end{bmatrix}
For example, if it's sunny or cloudy today, the probabilities for tomorrow's weather are: .5 chance of sun, .25 clouds, and .25 rain.
One can verify that the stationary distribution [.4 .4 .2] is preserved.
Across a ten-day period, what's the expected number of blocks of identical weather?
Hint: Rather than calculating the probability of each possible number of blocks, try defining the answer as a sum and using linearity of expectation.


I have solved his problem when the weather is independent across days. In this case, you find the probability of a change in weather for any given day, multiply this by $9$ (nine total changes), and then add $1$ (the number of weather blocks equals one more than the number of changes). We have:
$9 * \left(\frac{2}{5}*\frac{3}{5} + \frac{2}{5} * \frac{3}{5} + \frac{1}{5} * \frac{4}{5}\right) + 1 =$
$9*\frac{16}{25} + 1 =$
$6\frac{19}{25} = 6.76$
The Markov chain is what is throwing me.
Thanks again for any help!
 A: Let $W_k$ denote the type of weather on day $k$, so $W_k$ could be 0 (sun), 1 (clouds), or 2 (rain). Let $B$ be the number of blocks of weather; our goal is to compute $E[B]$.
The hint is telling us to define random variables $X_k$ for $2 \le k \le 10$, where $X_k = 1$ if $W_k \not = W_{k-1}]$ and $X_k = 0$ otherwise. Then we have $B = 1 + \sum_{k=2}^{10} X_k$, so $E[B] = 1 + \sum_{k=2}^{10} E[X_k]$ by linearity of expectation. That means we just need to compute the values $E[X_k]$ and then we'll be able to compute $E[B]$.
We can use the Markov chain to calculate $E[X_k | W_{k-1}]$ for each possible $W_{k-1}$.

*

*If it was sunny yesterday then there's a $50\%$ chance of different weather today, so $E[X_k | W_{k-1}=0] = .5$.

*If it was cloudy yesterday then there's a $75\%$ chance of different weather today, so $E[X_k | W_{k-1} = 1] = .75$.

*If it was rainy yesterday then it will always be cloudy today, so $E[X_k | W_{k-1} = 2] = 1$.

We start in the distribution $[.4, .4, .2]$, so we also know $P[W_k=0] = .4$, $P[W_k=1] = .4$, and $P[W_k=2]=.2$ for all $k$. (The probabilities don't change over time because we started in a stationary distribution.) Therefore we have
$$\begin{align}
E[X_k] &= \sum_{s=0}^2 P[W_{k-1} = s] \cdot E[X_{k} | W_{k-1} = s] \\
&= (.4)(.5) + (.4)(.75) + (.2)(1) \\
&= .7
\end{align}$$
and so $$E[B] = 1 + \sum_{k=1}^{10} E[X_k] = 1 + 9*.7 = \boxed{7.3}.$$

Note this computation is overall very similar to what you already wrote in your question statement. The whole setup is exactly the same; the difference is just in the details of how we compute the probability of changing weather on a given day.
