# Expected number of blocks of identical weather

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$). Assume weather is independent across days.

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.

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.

Even with the hint, I'm not sure how to approach it past the 1 block case.

Let $\{X_n:n=0,1,\ldots\}$ be a sequence of iid random variables with distribution $$\mathbb P(X_0=S)=\frac25,\ \mathbb P(X_0=C)=\frac25,\ \mathbb P(X_0=R)=\frac15.$$ Then $\{X_n:n=0,1,\ldots\}$ is a Markov chain on state space $\{S,C,R\}$ with initial distribution that of $X_0$ and transition probabilities $$P=\begin{bmatrix}\frac25 & \frac25& \frac15\\\frac25 & \frac25& \frac15\\\frac25 & \frac25& \frac15\end{bmatrix}.$$ Let $T_1=0$ and for $n>1$, $$T_{n+1}=\inf\{k>T_n: X_k\ne X_{T_n} \}.$$ Define $\tau_n:=T_{n+1}-T_n$. Conditional on $\{X_{\tau_n}\in\{S,C\}\}$, $\tau_{n+1}$ has $\mathsf{Geo}\left(\frac35\right)$ distribution, and conditional on $\{X_{\tau_n}=R\}$, $\tau_{n+1}$ has $\mathsf{Geo}\left(\frac45\right)$ distribution. Since $\mathbb P(X_1\in\{S,C\})=\frac45$ and $\mathbb P(X_1=R)=\frac15$ it follows that $$\tau_{n+1}=WY+(1-W)Z$$ where $Y\sim\mathsf{Geo}\left(\frac35\right)$, $Z\sim\mathsf{Geo}\left(\frac45\right)$, and $\mathbb P(W=1)=\frac45 = 1-\mathbb P(W=0)$. So for a positive integer $k$ we have \begin{align} \mathbb P(\tau_{n+1}=k) &= \mathbb P(\tau_{n+1}=k\mid W=1)\mathbb P(W=1) + \mathbb P(\tau_{n+1}=k\mid W=0)\mathbb P(W=0)\\ &= \frac35\left(\frac25\right)^{k-1}\frac45 + \frac45\left(\frac15\right)^{k-1}\frac15\\ &= 3\left(\frac25\right)^{k+1} + 4\left(\frac15\right)^{k+1}. \end{align} Since $\{X_n\}$ is a stationary process (as a Markov chain with initial distribution equal to that of its stationary distribution), we may compute the expected number of transitions to a different state by time $n$ as follows: \begin{align} \mathbb E\left[\sum_{k=1}^\infty \mathsf 1_{(0,n]}(T_k) \right] &= \sum_{k=1}^\infty \mathbb E(\mathsf 1_{(0,n]}(T_k))\\ &= \sum_{k=1}^\infty \mathbb P(T_k\leqslant n)\\ &= \sum_{k=1}^{n-1}\mathbb P(T_k=1)\\ &= (n-1)\left(3\left(\frac25\right)^2 + 4\left(\frac15\right)^2\right)\\ &= \left(\frac45\right)^2(n-1). \end{align} So for $n=10$, the expected number of blocks is $$1 + \left(\frac45\right)^2(10-1) = \left(\frac{13}5\right)^2.$$
On the first day we have at least 1 weather block with probability 1. On the next day, the probability of the weather changing and giving us another block is $$\frac{4}{5}\times\frac{3}{5} + \frac{1}{5} \times \frac{4}{5}$$
This occurs $n-1$ days and thus the expected number of weather blocks for $n$ days is given by $$E(X_n) = 1 + (n-1) \frac{16}{25}$$
Plugging in $n = 10$ we expect $\frac{169}{25}$ or roughly $6.76$ weather groups.