My mother has a theory: “The nicest weather is when you are at work, and then it rains on the weekend.” Hearing this from her once again, I think it is time to expose her theory to the facts and prove her wrong.

We’ll start by setting up some tools to help retrieve and categorize the data in terms of the type of day. In the United Kingdom, the weekend is Saturday and Sunday.

Now we can take the available weather data and split it into weekend values and weekday values, and discard dates where no value was recorded…

Finally, we need to average the data and present it clearly. We’ll do this as a separate step, as we’ll also want to access the raw data for further analysis.

OK, now I am ready to start. In the UK, the definition of “nice” weather is simple: the dryer the better and the hotter the better. Let’s look at the rain first…

Oh dear, she might be on to something. There has been on average nearly 0.02mm more rain on weekend days. Before conceding defeat, we have to know whether that is a significant result. Fortunately, *Mathematica* has all the statistics we need to test this.

If you take two sample sets from the same data then they are unlikely to have exactly the same mean. The question is, how likely is it that the means would be as different as these are purely because of the randomness of sampling? If the difference is very unlikely (the standard test is 5% of the time) then we conclude that it is significantly likely that the difference is because there is another cause (i.e., that they are being sampled from different data that actually has different means).

My hypothesis is that the weather has no bias for weekends, and therefore both sets of data are from the same data. So we give the test parameter for the difference in means as zero, and say the variances of both populations is equal and it is a `TwoSided` test, as the hypothesis is symmetrical.

We’ll create a shortcut function for this as we will do this test several times.

Phew! This tells us that the difference isn’t significant. Randomly dividing the data into two sets will produce this much difference in mean about 20% of the time.

What about temperature?

The average weekend temperature is 0.03°C higher—the opposite of her prediction—but again, let’s see if that is significant…

Not surprisingly, this isn’t significant either. But “niceness” is a combination of both values, and we don’t like it too windy either. Let’s factor in windiness; perhaps there is some complexity about combining the three data sets.

The weighting between the three values is somewhat subjective, but here is my formula. You will have to come up with your own to suit your climate and tastes.

Unfortunately, the weather stations that *Mathematica* is querying sometimes have missing data points when individual instruments or weather stations have been offline. We have to collect the data by day, reject any days where any of the values is missing, apply the “niceness” metric, and categorize as weekend or not. This is the kind of complicated data analysis that is made easy by *Mathematica*.

We are retrieving three data sets with around 20,000 points in each. My first naive approach was to search each set nearly 20,000 times. This was a bit slow, so instead we’ll tag the data with the type of data that it is, throw it all in together, and let the built-in *Mathematica* command `GatherBy` match up the dates. As a rule of thumb, if there is a built-in command close to what you want, try to use it rather than replicating it with something similar. This version takes a couple of seconds.

Not significant again.

At this point, I present the results. Peer review does not go well. My mother alleges selective choice of Oxford, a place where she has never lived.

I sense that it is time to change the goal of my research. Where is her theory MOST true? Let’s scan the largest 68 cities in the UK to see if it applies somewhere…

The places with the greatest variance are at the ends of the sorted list.

While both of these are significant with the 5% test, doing so on data which we have systematically selected for being the greatest outliers of 68 points is a sufficient abuse of statistical method to be meaningless. And I point out that Brighton, the place where her theory is least true, IS somewhere that she has lived.

We agree that the definitive answer would be to take into account every single UK weather station (or perhaps all those that she has lived near, weighted by how long she was there). It will only take a few more lines of *Mathematica* code, but I have concluded that if I want to still get birthday cards, it would be best to leave it as a mystery.

## 11 Comments

Your statement “Randomly dividing the data into two sets will produce this much difference in mean about 20% of the time.” is not what the p-value tells us. It tells us that IF the assumption of no difference in means is correct then 20% of the time we will see a test statistic at least this large. That’s all it tells us.

It’s a bit like saying an 80% confidence interval for the means tells us we will see this difference in means lying in the CI 80% of the time we sample – absolutely incorrect, and easily seen to be so by a simple (Mathematica !) simulation. The CI tells us NOTHING about the observed differences in means. It says that 80% of the time we sample we will see the true difference in means lying in that – freshly re-calculated – CI. But it says nothing about an 80% chance of lying in a particular CI. Similar interpretation of p-values.

Something I’ve noticed, is that precipitation seems to have a one week periodicity: e.g., if it’s rainy this Monday, it seems especially likely to be rainy next Monday.

Care to whip up a test for this?

Weather reports are popular. Everyone wants to know what to expect tomorrow. If you happen to miss the weather forecast I would like to suggest a simple rule for forecasting tomorrows weather . The rule is: the weather tomorrow will be very similar to what it has been today. Obviously the rule is not always correct but I guess that it is correct a surprisingly high proportion of the time. It would be interesting for someone to evaluate the rule or variants of it using Matematica.

Your mother’s theory is correct. It had been proven by experimetal data already. The explanation is quite simple. In order to form rain drops condensation cores are needed. Normally some piece of dirt works fine. During the week there is lots of dirt in the air from exhaust fumes. During the weekend it will clear up. It leads to less rain in the beginning of the week.

Why is the Brighton value rejected ? Surely you can select data all you want, as long as you select data based on a variable that doesn’t have anything to do with what you’re searching for.

Perhaps one could make the argument that selecting in your sorted set was not independant of the variable. However I doubt it’ll cheer up the weekends of the people in Bristol.

@ republicofmath

You are, of course, correct. I apologise for the over-simplified description. The test statistic is StudentT and so is based on the difference in means, but also on the observed variance, and the number of sample points.

@ George

The other item I wrote about whether is probably closer to your question:

http://blog.wolfram.com/2010/01/15/mathematica-tests-the-st-swithuns-day-proverb/

Michael’s theory seems to be validated by Jon’s data. Prevailing wind across southern England is from the south-west. Southend is directly in the lee of London, the UK’s largest centre of popultaion, and close enough for the weekend effect to be felt almost instantaneously on Saturday/Sunday, rather than Sunday/Monday. Brighton is on the south coast, so is not normally exposed to airborne pollution from other English towns. The major pollutants coming over from the French coast are emissions from the string of nuclear power stations and would not have the same effect on climate. It would be interesting to test this theory by looking at the location of other cities at the extremes of [cityNicenessData]. Are Swansea and Plymouth close to Brighton in the distribution? Are cities grouped with Southend in the lee of other conurbations?

john hangman game only has 8 spaces for letters. how can you give words for more than 8 spaces and call them winning words?

With this amount of data, you might collect some small effects, e.g. weather stations are more prone to defects in very hot weather and are less likely to be repaired immediately on weekends

Well done!