## Tuesday, May 19, 2009

### Wait! What?

There is a 75% chance of rain on any given day in the next week. What is the probability that it will rain on at least 5 of the 7 days?

There's a little surprise in there. I won't spoil the fun. (Until I do. Probably tomorrow.)

Update (also in comments): The weird thing, that you might notice in the course of solving, if you calculate P(5), P(6), and P(7) separately and then add them together, is that P(5) and P(6) come out to the same thing. The probability it will rain 5 out of the 7 days is the SAME as the probability it will rain 6 out of the 7 days. Isn't that weird? If you write it out with fractions and the nCr formula you can how it happens, but the result is still counterintuitive to me. Combinations sometimes surprise me like that.

jd2718 said...

So we have a system creeping towards us, carrying a nice soaking of rain... Maybe a day and a half, two day's worth...

It could hit Monday and Tuesday, or Tuesday and Wednesday, or Wednesday and Thursday... you get. So that works out to about a 25% chance of rain on any given day, and about a 90% chance of rain on exactly 2 days...

Ouch... we don't clean the sky and start with fresh weather patterns each day... NY State may not consider the independence of events, but the real world does....

Jonathan

Kate Nowak said...

Oh you and your wanting math problems to reflect reality. :-)

Matt said...

I'm getting 75.64%. Did I miss the surprise?

Ach!
My probability skills are awful, the Australian course does not teach much probablity at all till the end of last semester which I have not yet reached...
However I did as follows:
(0.75^5)*(0.35^2) - 5 Days Rain
(0.75^6)*(0.35) - 6 Days Rain
(0.75^7) - 7 Days Rain
Add them up: 0.225/1 = 22.5% Chance of 5 days or more of rain.
Someone point out my mistake as I am loathe to go to sleep without the correct answer. Anyway to do this formally using nPr, nCr, Factorials and all that stuff?

On a side note, I really enjoy this blog despite likely being younger than the target audience. A bit of interesting maths brightens up my day.

Matt said...

Very close, shad! Think about the "five days of rain" event. That does mean five days of rain and two days without, BUT you have to take into account WHICH five days will have rain! Since there are 7C5 = 21 ways to "choose" which 5 days will be rainy, we must multiply your (0.75^5)*(0.35^2) by 7C5. (The two non-chosen days will then just automatically be non-rainy, so there's no need to multiply by anything else, like 7C2, as my students are fond of doing.) Likewise for 6 days (7C6) and 7 days (7C7). Make sense?

unapologetic said...

Shad, your first line calculates the probability that there's rain on some specified five days.

For example, 22.5% is the probability that it rains Sunday through Thursday and is dry on Friday and Saturday, or it rains Sunday through Friday and is dry on Saturday, or it rains all week. You've left out the chance that it's only dry on Tuesday and Friday.

jd is right about the fact that these events aren't actually independent in many cases. However, he evidently hasn't lived in New Orleans, where in the spring and fall this seems to be an eminently realistic model. The humidity builds up over the day. Some days it gets high enough to dump rain in the afternoon and some days it just dissipates overnight.

Finally, I don't consider this a spoiler, because I know Blogger won't parse the TeX!

$$\left(\frac{1}{4}\right)^7\sum_{k=5}^7\binom{7}{k}3^k$$

Kate Nowak said...

Hi, Shad! You're more than welcome here. Thanks Matt and unapologetic for explaining the need for nCr in the expression. This is the way I explain it to my classes (which is probably unnecessarily explain-y for this audience):

If it's going to rain 7 days, there's only one way for that to happen (let R="rains on that day"): RRRRRRR so you can calculate it with (.75)^7.

But if it's going to rain on 6 out of 7 days, there are 7 ways that can happen (let D="dry that day")

RRRRRRD
RRRRRDR
RRRRDRR
etc.

so you have to multiply your (.75)^6*(.25)^1 by 7.

Well how do you decide how many ways you can choose 1 day to rain out of 7? 7C1. 2 days out of 7? 7C2. etc.

The weird thing is that P(5) and P(6) come out to the same thing. The probability it will rain 5 out of the 7 days is the SAME as the probability it will rain 6 out of the 7 days. Isn't that weird? If you write it out with fractions and the nCr formula you can how it happens, but the result is still counterintuitive to me. Combinations sometimes surprise me like that.

Chris Wellons said...

Recursively in elisp,

(defun nck (n k)
"The binomial coefficient."
(if (or (= k 0) (= k n)) 1
(+ (nck (- n 1) (- k 1)) (nck (- n 1) k))))

(defun p-rain (n)
"Probability of rain on exaclty n days."
(* (nck 7 n) (expt 0.75 n) (expt 0.25 (- 7 n))))

(defun rain-at-least (n)
"Probability it will rain on at least n days."
(if (> n 7) 0
(+ (p-rain n) (rain-at-least (+ 1 n)))))

(rain-at-least 5)
-> 0.75640869140625

Matt said...

Huh! That IS weird, and I DID miss it! Of course, that leads one to wonder... under what circumstances does this phenomenon occur?

Kate Nowak said...

Matt - I know, right? I wonder that too. Something about the relationship between p, q, n, and r, but I haven't been able to figure it out yet.

Unfortunately the curse of blogging is that someone is just going to come bust in here and tell us the answer...hints would be better. :-)

unapologetic said...

Oh that? That's easy. Note how I factored out the 1/4 from everything, leaving the 3^k inside the sum? So when you go from 5 days to 6 days you multiply the probability term by 3.

But what about the combinations part? What's the difference between 7C5 and 7C6 (in your notation)? Write each of them all out in terms of products and they differ by an overall factor of three in the denominator.

So one part is multiplied by 3 and one is divided by 3, leaving no net change. It's weird, but ultimately it's not a particularly interesting coincidence, in the sense that it isn't connected to any real structural feature of the problem that could be generalized to lead into other problems.

Kate Nowak said...

Well, shoot.

Matt said...

I disagree, unapologetic... I think it's at least interesting enough to play with and think about for a little diversion!

I did some work on it already, and have what I think is an answer. For one thing, it tells me that if you roll a die 11 times, P(rolling exactly one Six) = P(rolling exactly two Sixes) ≈ 29.6%...

TwoPi said...

If P(x) = prob of getting rain on x days out of n tries (for fixed n, and fixed prob of rain on any one day), then P(x) is a binomial distribution. Its graph is mounded (unimodal), so in principle you'd expect pairs of numbers a,b straddling the mode with P(a)=P(b).

When this happens with a,b whole numbers, it can seem rather striking. But not completely unexpected for suitable choices of n and p.

Matt said...

So I guess the question remains... what makes a "suitable" choice of n and p? I believe I have the answer, but I'll let the reader play with it.

thesquaredcircle said...

I have been writing about games that end when a single event occurs.

http://thesquaredcircle.wordpress.com/2009/05/20/are-you-game-part-i-fair-game/

This post suggests a nice generalization that can be made to have the stopping condition be a combination of events. So thanks!