1
$\begingroup$

Sorry if this is too basic a question, or the wrong place to post.

I am planning a road trip, and I'm trying to optimize the date I leave based on historically average weather for all the states I'll be visiting. I have four qualifiers for "bad weather":

  • Rain
  • Snow
  • Temp over 90F
  • Temp below 32F

I've downloaded data from the NOAA, processed a fair bit, and now I arrive at my statistics problem.

Here's what the data looks like for Zion National Park in Utah. The first item in each list is the number of days in January with that kind of bad weather, then February and so on. So March in Zion has 5 rainy days.

rainDays: [ 4.4, 5, 5, 3.3, 2.1, 1, 2.8, 3.6, 2.2, 3, 3.3, 3.8 ],
snowDays: [ 0.6, 0.5, 0.4, 0.1, 0, 0, 0, 0, 0, 0, 0.3, 0.6 ],
hotDays: [ 0, 0, 0, 1, 9.9, 24.3, 29.9, 28.8, 18.4, 3.3, 0, 0 ],
coldDays: [ 0, 0.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2 ]

The statistics question is: What are the overall odds of a bad weather day for each month?

My first approach, which seemed obviously wrong, was just to add up the categories. January has 4.4 rain days and 0.6, so on average it has 5 days of bad weather. The trouble became obvious in July, where this method yields 32.7 bad days on average. It can rain while also being hot.

My second idea is to divide each number by the number of days in the month to get odds instead of total, then... multiply? So a day in July has a 2.8/31 chance of rain and a 29.9/31 chance of being too hot. That's 83.72/961, which is far too small to be the number of bad days, so maybe that's the odds of those hot and rainy days? So maybe I should take 32.7 and subtract 83.72/961 * 31, to remove the double-counted bad days? That leaves right around 30, which seems like a reasonable number, but at this point I've made too many guesses as to how this works to be confident.

If anyone can give me an idea of how to do this, it would be greatly appreciated!

One final note: I do realize that I'm ignoring the fact that, say, snow days and cold days are likely to overlap. I'm okay with this.

$\endgroup$

2 Answers 2

0
$\begingroup$

As already discussed by unicoder, there are several problems with your data. First of all, you have only average number of days with particular condition. Second, you don't have any data about co-occurrences of the conditions. Obviously, on a given day the temperature cannot be both very high, and very cold, so if one of the conditions occurs, the other one would as well. Same applies to other conditions, but it is less obvious (for example snow is very unlikely on hot weather, but cold weather does not guarantee it, etc).

Nonetheless, remembering about the limitations, you can still get a rough approximation of the probability. If you are interested of a "bad weather day for [a] month" and you have data about average number of days with a particular condition, then you can use the following estimator

$$\Pr(\text{day with the condition}) = \frac{\text{number of days with the condition}}{\text{total number of days}}$$

So if there were $4.4$ rainy days on January, then the probability of rainy day in January would be about $4.4 / 31 = 0.14$, etc.

Next, as mentioned above a day cannot be both cold and hot, so it makes more sense to count days with "extreme" temperature (either hot, or cold).

Finally, if you assume that conditions $A$, $B$, and $C$ are independent (the fact that one of them occurred, does not make any other of them more or less likely), then you can calculate the probability of any of the conditions occurring.

$$\begin{align} \Pr(A \,\text{or}\, B \,\text{or}\, C) &= \overbrace{1 - \overbrace{\Pr(\neg A \,\text{and}\, \neg B \,\text{and}\, \neg C)}^\text{neither of them happening}}^\text{opposite of this}\\ &= 1 - \underbrace{(1-\Pr(A))\times(1-\Pr(B))\times(1-\Pr(C))}_\text{assuming independence} \end{align}$$

What leads to the results plotted below.

Estimated probabilities

In the R code this translates to:

rainDays <- c(4.4, 5, 5, 3.3, 2.1, 1, 2.8, 3.6, 2.2, 3, 3.3, 3.8)
snowDays <- c(0.6, 0.5, 0.4, 0.1, 0, 0, 0, 0, 0, 0, 0.3, 0.6)
hotDays <- c(0, 0, 0, 1, 9.9, 24.3, 29.9, 28.8, 18.4, 3.3, 0, 0)
coldDays <- c(0, 0.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2)

monthDays <- c(31, 28.25, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

probs_marginal <- data.frame(
  rain = rainDays / monthDays,
  show = snowDays / monthDays, 
  hot_or_cold = (hotDays + coldDays) / monthDays
)

1 - apply(1 - probs_marginal, 1, prod) 
## [1] 0.1585432 0.1972812 0.1721124 0.1425344 0.3654631 0.8163333 0.9677211 0.9372737 0.6416889
## [10] 0.1929240 0.1189000 0.145114

As stated above, you should not treat those values as "correct" probabilities, since they follow from ill-defined assumptions (e.g. show can appear on day with hot weather). Treat them as rough approximation. To get more precise estimates, you would need to know the joint probabilities, so the joint counts (e.g. average count of days with "cold weather, show, but without rain").

Also notice, that if you want to use this as a criteria for making decision about the trip, then this is not the best one. First of all, probability "a day" of bad weather for a month does not seem very relevant, since if you had $30$ days with great weather and single rainy day, then you would probably remember this as a great holiday. Second, by doing above calculation you would weight equally all the conditions. Are they really equal? If you have adequate clothes, then snow in winter can be less problematic, then rainy weather. Is hot summer really worse, then some snow in winter, or few days of rain in autumn?

$\endgroup$
1
  • $\begingroup$ Thank you for this answer, I think it is exactly what I was looking for. The road trip will have about 50 stops and should last 6 months, so I do think this is a useful criteria. Questions like should I start the loop by heading east or south, given a start date, seems hard without a measure like this. Thanks again, this is what I needed, diving back into the coding now. $\endgroup$ May 28, 2019 at 22:14
0
$\begingroup$

Your goal is admirable, and I wish you all the best on your trip! Now onto the math...

Given your data, you are stuck making month-level prediction. You cannot predict which precise days of the month will have bad weather based on monthly averages, for a number of reasons (e.g. months do not represent fixed seasonal boundaries; averages do not convey day-to-day conditional information). From the monthly averages alone, you can only estimate which months will have bad weather.

If you want to determine which month is best to leave during, summation offers a fine quick and dirty solution. Unless you are a lizard, steer clear of Zion in July and August. Any time between November and January should be fine.

If you want to get technical, and scale your coefficients so each month is perfectly comparable, you need to determine the conditional probability for each pair of of events (e.g. the probability that it will rain given that it is hot) and then multiply the set of conditional probabilities. You cannot derive the conditional probabilities from the averages, and will need to go back to the raw data. If you are hardcore, you can also compute the conditional probabilities for monthly minimums and maximums to get a sense of how much you can trust your average-based estimates for each month.

$\endgroup$
3
  • $\begingroup$ I do understand that I can't predict what the weather will be on a specific day given the monthly data. What I'm hoping for is the odds of bad weather for a location across the whole month. So like, 80% of the days in Zion in July will be bad. Then across the whole trip (50 stops, 6 months), I can add up all the averages and say if I leave in May, 20% of my days will be rainy but if I leave in October 80% will be. I can currently do this for one of the categories, say optimize a trip to avoid rain, but I'm looking for a sensible math way to combine the four. $\endgroup$ May 28, 2019 at 19:19
  • $\begingroup$ Bit of context -- I don't know much statistics, but I am a programmer looking for a math way to do this. Currently using a genetic algorithm to find an optimal route, looking for a way to account for weather in the scoring function. $\endgroup$ May 28, 2019 at 19:28
  • $\begingroup$ Understood. To make sure that your values are scaled (i.e. the probability value for bad weather is between 0 and 1) you need to calculate the conditional probability for each bad weather event. Here is a clear mathematical description followed by a simple code example: stat.yale.edu/Courses/1997-98/101/condprob.htm $\endgroup$
    – unicoder
    May 28, 2019 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.