Puzzle: how often does it rain?

Weather is notoriously hard to predict. The following puzzle imagines a world where weather is simple and determined entirely by a set of probability rules.

The puzzle: weather in mathland

In Mathland, the weather is described either as sunny or rainy, nothing in between.

On a sunny day, there is an equal chance it will rain on the following day or be sunny. On a rainy day, however, there is a 70 percent chance it will rain on the following day versus a 30 percent chance it will be sunny.

How often does it rain in Mathland, on average? In other words, how many days is it expected to rain in a 365-day year (assume the first day is sunny)?

I’ll post a full solution on Wednesday. I have posted a solution in the comments section.

I’ve posted a couple of hints after the break to help you get started.

diagram generated by yUML

Hint 1
You can solve this by using the law of total probability (as an example, this is used in solution method 3 of the dice brain teaser)

Hint 2
Another solution method is to model the weather as a Markov chain. Here is a nice introduction on Markov chains: (pdf intro to Markov chains).



Share this post:

| More

Previous post:

Next post:



  • http://stackoverflow.com/users/114887/matthew-piziak Matthew Piziak

    I had a lot of fun solving this one. Thank you!

  • http://stochastix.wordpress.com Rod Carvalho

    I don’t want to wait till Wednesday to know if my solution is correct. Back-of-the-envelope calculations give me an expectancy of approx. 228 rainy days per year. Presh, is this correct?

  • http://charliechatters.wordpress.com Sharan

    I got the same thing. Presh?

  • Tristan

    I’m going to go with 227 days of expected rain, with the caveat that this is only because the first day of the year is assumed to be sunny. :) If we had assumed the first day was average then I’d agree with Rod and say 228 days of rain.

  • Eyal

    I’ll do it the very long way, just for fun/masochism:

    Start with a matrix that, given the probabilities of sun and rain in a column matrix, outputs the probabilities for sun/rain for the current day in a column. It looks like this:

    A =
    [0.5 0.3]
    [0.5 0.7]

    So if you start with a sunny day the next day is:

    [0.5 0.3] * [1] = [0.5]
    [0.5 0.7] [0] [0.5]

    Cool, it works. Now we just need to compute that matrix to the power of infinity and multiply by the start condition. No problem for eigen decomposition!

    Thanks to http://www.bluebit.gr/matrix-calculator/ I know that:

    A = Q * D * inverse(Q) where

    Q =
    [-0.707 -0.514]
    [ 0.707 -0.857]

    D =
    [0.2 0]
    [0 1]

    and Q’s inverse is (again with the website…)

    [-0.884 0.530]
    [-0.729 -0.729]

    A to the power of x for all x is the same as taking D to the power of x (write A*A in terms of Q and D and you’ll see that the Qs and their inverses cancel out).

    D to the power of infinity is
    [0 0]
    [0 1]

    because 0.2 tends to 0 and 1 stays 1.

    So Q*D*inverse(Q) is (using http://www.bluebit.gr/matrix-calculator/matrix_multiplication.aspx):

    [0.375 0.375]
    [0.625 0.625]

    The columns are identical so whatever initial column you choose, if they add up to one, you get the same answer:

    [0.375]
    [0.625]

    0.625 of the days are rainy. Multiply by 365 to get 228, same answer as everyone else here. Of course, there are a few others ways to do this much easier!

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    Everyone has gotten the correct answer. The chance of rain is 62.5 percent. If the first day is sunny, then there is expected to be 0.625(364) = 227.5 days of rain in the year.

    Thanks Eyal for posting about how to raise the transition matrix to the infinite power. That is a useful exercise. Here are a couple of ways I solved it.

    Method 1: Let R denote the average proportion of rainy days and S of sunny days. Using the law of total probability, we know that:

    R = E(rains tomorrow | sunny today) * Pr(sunny today) + E(rains tomorrow | rainy today) * Pr(rainy today)

    We can know use a clever trick. On average, the probability it is sunny or rainy on a particular day is S and R, respectively. And we also know a day is either sunny or rainy, so S = (1-R). Hence we get the following:

    R = E(rains tomorrow | sunny today) * (1-S) + E(rains tomorrow | rainy today) * R

    We can simplify this because we know the rules of weather. The first conditional expectation is 50 percent and the second is 70 percent.

    R = 0.5(1-R) + 0.7(R)

    This can be solved to find out R = 0.625.

    Method 2: The weather is a regular or ergodic Markov chain. See section 11.3 of this pdf for a reference on long-run averages.

    From that reference it is shown that for a regular transition matrix A, there is a unique row vector w called the probability vector such that wA = w. This is the probability of being in those states.

    Let us set up the transition matrix:

    A =
    [0.7 0.5]
    [0.3 0.5]

    If w = (R S), and we set wA = w, we get the equations:

    0.7 R + 0.5 S = R
    0.3 R + 0.5 S = S

    These equations can be solved to find R = 0.625, just as before.

  • http://stochastix.wordpress.com Rod Carvalho

    I disagree with the solutions that have been presented above. You seem to be computing the steady-state probability vector and using it to compute the answer. What about the transient? The error that results from neglecting the transient is very small, but it’s not zero.

  • Pingback: Rainy days « Rod Carvalho

  • Denis

    I agree with Rod, you have to justify the use of the ergodic Theorem. By instance, if the spectral gap of your transition martix were bigger than exp(-1/365) (~=0.997), you’ll have to deal differently! Well, in our case, it is equal to 0.2, so that you’re not really in trouble, but it’s worth mentioning it!

    Imho, the best solutions are given by Rod on his web site, or by the following one (I replaced O.5 by a, and 0.7 by b, for more generality)…

    Define U_n=Probality of “it rains on day n” so that:
    . U_1=0 (statement of the problem)
    . U_{n+1}=a (1-U_n) + b Un (simple application of the law of total probability)

    The whole sequence U_n can be explicitly computed (classical and useful exercise), summing over n=1,…,365 you get your result in all generality!

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    Rod and Dennis point out that my solution method is not entirely correct.

    I appreciate that Rod has done the hard work and written up a correct derivation of the answer.

    Please visit his blog for the writeup:

    http://stochastix.wordpress.com/2011/07/07/rainy-days/

Previous post:

Next post: