# Expected number of days until it rains d days in a row when P(rain)=p

What is the expected number of days until it rains $d$ days in a row (including the $d$ days) when the probability it rains on a single day is $p$?

I managed to figure out a solution for the case $d=2, p=1/2$ but don't know how to generalize it to different values of $d$ and $p$ when the probabilities don't line up nicely with the Fibonacci series.

My proof

Let $P_u(n)$ denote the chance it rained for $d$ consecutive days during any of $n$ days.

I managed to work out the value of $P_u(n)$ using this question.

Let $a_n$ be the number of combinations of $n$ days such that there were no $2$ consecutive rainy days and the last day was rainy. Let $b_n$ be the number of combinations of $n$ days where there were no $2$ consecutive rainy days and the last day was not rainy.

$$a_1 = 1, \; b_1 = 1 \\ a_n = b_{n-1}, \; b_n=a_{n-1}+b_{n-1}$$

Calculating the first few values we get

$$a_2 = 1, \; b_2 = 2 \\ a_3 = 2, \; b_3 = 3 \\ a_4 = 3, \; b_4 = 5$$

We can notice that (where $F_n$ is the $n^{th}$ number in the Fibonacci sequece)

$$a_n = F_n, \; b = F_{n+1}$$

The total number of days it didn't rain $2$ consecutive days is then $a_n + b_n = F_n + F_{n+1} = F_{n+2}$ with the total number of combinations being $2^n$, so

$$P_u(n) = 1 - \frac{F_{n+2}}{2^n}$$

Let $P_e(n)$ denote the chance the chance $n$ is the last of the $d$ days in which it rained and it is the first time it rained for $d$ consecutive days.

$$E_{days} = 1P_e(1) + 2P_e(2) + 3P_e(3) + 4P_e(4) + ... \\ = P_e(\ge1) + P_e(\ge2) + P_e(\ge3) + P_e(\ge4) + ... \\ = (1 - P_u(0)) + (1 - P_u(1)) + (1 - P_u(2)) + ... \\ = \frac{F_{0+2}}{2^0} + \frac{F_{1+2}}{2^1} + \frac{F_{2+2}}{2^2} + ... = \sum_{n=0}^{\inf} \frac{F_{n+2}}{2^n}$$

$$E_{days} = \sum_{n=0}^{\inf} \frac{F_{n+2}}{2^n} = \sum_{n=0}^{\inf} \frac{F_n}{2^n} + \sum_{n=0}^{\inf} \frac{F_{n+1}}{2^n} \\ = \frac14 \sum_{n=0}^{\inf} \frac{F_n}{2^{n-2}} + \frac12 \sum_{n=0}^{\inf} \frac{F_{n+1}}{2^{n-1}} \\ = \frac14(E_{days} + 2) + \frac12(E_{days} + 2)$$

$$E_{days} = \frac34E_{days} + \frac32$$

$$E_{days} = 6$$

Consider $d=2$ first. Let $M:=E_{days}$ be the requested expected number of days.

Consider recurrent relation for $M$. We are waiting for the first rainy day during the random number of days with geometric distribution and with expected value $\frac1p$.

Next day, we have rainy day with probability $p$ and then the trials are finished. In this case the expected number of days we are waiting for two successfull rainy days equals to $\frac1p+1$. If the next day is not rainy we start trials again. This case we again are waiting for two successfull rainy days until $M$ days in an average. This case the total average number of days is $\frac1p+1+M$.

Combining this two cases by Law of Total Expectation, we have: $$M=p\cdot \left(\frac{1}{p}+1\right) + (1-p) \cdot \left(\frac1p+1+M\right).$$ From this equation, $$M=\frac{p+1}{p^2}.$$ Note that for $p=\frac12$, $M=6$.

Next consider arbitrary $d\geq 2$. Again we are waiting for the first rainy day for an average $\frac1p$ days. And next few days we obtain the following possibilities. Here $R/C$ denotes rainy/clear day.

• $C$ with probability $1-p$: this case $M=\left(\frac1p+1+M\right)$,

• $RC$ with probability $p(1-p)$: this case $M=\left(\frac1p+2+M\right)$,

• $RRC$ with probability $p^2(1-p)$: this case $M=\left(\frac1p+3+M\right)$,

so on

• $\underbrace{R\ldots R}_{d-2}C$ with probability $p^{d-2}(1-p)$: this case $M=\left(\frac1p+d-1+M\right)$,

and finally

• $d-1$ rainy days $R\ldots R$ with probability $p^{d-1}$: then $M=\left(\frac1p+d-1\right)$.

By Law of Total Expectation we get $$M=(1-p)\left(\frac1p+1+M\right)+p(1-p)\left(\frac1p+2+M\right)+p^2(1-p)\left(\frac1p+3+M\right)+\ldots+p^{d-2}(1-p)\left(\frac1p+d-1+M\right)+p^{d-1}\left(\frac1p+d-1\right).$$

Find $M$ from this equation and obtain $$M=\frac{1-p^d}{(1-p)p^d}.$$

Let $q=1-p$. Rewrite the last equation as $$\tag{1}\label{1} M=q\left(\frac1p+M\right)\left(1+p+\ldots+p^{d-2}\right)+q\left(1+2p+3p^2+\ldots+(d-1)p^{d-2}\right) + p^{d-1}\left(\frac1p+d-1\right).$$ Here $$1+p+\ldots+p^{d-2} = \frac{1-p^{d-1}}{q},$$ $$1+2p+3p^2+\ldots+(d-1)p^{d-2}=\frac{d}{dp}(p+p^2+\ldots+p^{d-1})=\frac{d}{dp}(1+p+p^2+\ldots+p^{d-1})=\frac{d}{dp}\left(\frac{1-p^d}{1-p}\right)=\frac{(d-1)p^d-dp^{d-1}+1}{q^2}$$ Substitute this value into (\ref{1}): $$M=\left(\frac1p+M\right)(1-p^{d-1}) + \frac{(d-1)p^d-dp^{d-1}+1}{q} + p^{d-1}\left(\frac1p+d-1\right)$$ Simplifying this equation and leading r.h.s. to a common denominator, obtain $$Mp^{d-1}=\frac{1-p^d}{pq}$$