Friday, 25 April 2014

More Fun with Probability and Birthdays

In my previous post I examined the probability of there being a shared birthday in a random group of n people. Let's take this analysis a little further and look at the probability of there being birthdays within a certain proximity to each other, say for example within 4 days time. After all, it is common to hold birthday celebrations on a weekend when they're more convenient, so two people with a birthday within 4 days of each other could conceivably choose to celebrate their birthdays on the same day. This problem gets a little more complicated than the same-day birthday. The probability of two randomly selected people having a birthday within 4 days of each other is 9/365 (about 2.47%), because B could have his birthday on the same day as A, or in any of the four days before, or in any of the four days after. Just as before, it is simpler to calculate the probability of there being no shared birthday as we increase our group size and then subtract from 100%. When we add a third person we now have two possibilities. One possibility is that A and have their birthdays at least 9 days apart, in which case there are 18 days where C can't have his birthday. A second possibility is that A and have their birthday more than 4 days apart but less than 9 days apart, in which case there is some overlap and there could be as few as 14 days eliminated for C. This brackets the probability of there being no birthdays close together in a group of three people to somewhere between 6.20% and 7.28% (exact solution is 7.26%; formula is given a few lines down). Adding a fourth similarly means there are as few as 19 and as many as 27 days eliminated, bracketing the probability of there being no birthdays close together in a group of four people to between 11.09% and 14.13% (exact solution is 14.08%).

There is an exact solution that accounts for the probability of the overlaps in the spacing between birthdays, but the explanation of how that's accomplished would be a little math intensive and there's already more than enough math in this post. Just take my word for it that the total possible permutations of n people's birthdays spaced at least k days apart from each other is equal to:
which, in factorial notation, looks like this:

With this result we can move on to calculating the probability that no birthdays in a group of random people are within k days of each other. Subtract that from 1 and you get the the probability that there is at least one birthday in the group within k days of another person's. That equation looks like this:

It looks more complicated than the formula for probability of same-day birthdays, but the general form is the same. It converges to 1 pretty rapidly as n increases. And the larger k is, the faster it converges. If we take k = 0, the equation reduces to the earlier expression for birthdays on the same day. In the graph and table below you can see the results for yourself.



As you can see, among just 10 people there's a pretty good chance there are two or more birthdays in the same week. What I think is pretty cool is the huge difference between k = 0 and k = 1. For instance, in a group of 25 people, there's about 57% probability that two people have the same birthday, but almost 93% probability that two people have birthdays within one day of each other (i.e. on the same day or on consecutive days). Test it out among your co-workers or a sample of your Facebook friends and see for yourself. If you're clever, you might even be able to use this knowledge to make some bets and relieve a few naive people of their money.

Saturday, 19 April 2014

The Surprising Probability of Shared Birthdays

Have you ever wondered why, in a group of maybe a few dozen people (say a class of students or the staff in an office), it is fairly common for there to be a shared birthday? There are 365 days in a year but only 20 to 30 people in a typical elementary school classroom. Commonsense says shared birthdays in a small group ought to be rare, right?

When it comes to understanding probability and randomness, our commonsense often leads us astray. Our brains are better suited at comprehending patterns, structure, and order, so much so that when faced with chaos and randomness we tend to search for patterns and attempt to impose order. Our belief of what a random sample should look like is often not very random at all. So when we have a group of 20 random people, we'd like to believe that their birthdays should be evenly distributed throughout the year.

Let's analyze the shared birthday problem and find out how probable shared birthdays really are. First off, what are the chances that two randomly selected people have the same birthday? This is a rather straightforward problem, assuming that birthdays are evenly distributed among the 365 calendar days (let's neglect those leap-year birthdays). The probability is 1/365 (about 0.27%). Nothing counter-intuitive about that; our gut feeling should be that it's unusual for two random people to have the same birthday.

Where our intuition starts to lead us astray is when we start adding more random people to the sample. Let's go up to three people now (A, B, and C). There is a 1/365 chance that B has the same birthday as A. Equivalently, there's a 364/365 chance that B doesn't share a birthday with A. Having taken up two days of the year with A and B means that C has a 363/365 chance of not sharing a birthday with either A or B. The probability of there being no shared birthday in the group is therefore [364/365] * [363/365] (about 99.18%). To find the probability of there being a shared birthday, just subtract the probability of there being no shared birthday from 100%. In other words, there's about a 0.82% chance that there is a shared birthday among three randomly selected people. The probability is small, but keep in mind all we did was add a third person and we nearly tripled the probability of a shared birthday in the group. If we add a fourth person, we get a probability of 1 - {[364/365] * [363/365] * [362/365]}, which is about 1.64%. That's about double the chance of a shared birthday in the group of three.

We can calculate the probability of there being a shared birthday in any size of random sample using the following complicated-looking equation:
Probability of a shared birthday in a group of n randomly selected people.
where n is the number of randomly selected people in the group and the ! indicates the factorial function. The probability of a shared birthday rapidly approaches 100% because that 365^n factor in the denominator makes that whole fraction really small really fast as n increases. You can see for yourself if you plot the equation at different value of n like I have below:

Looking at it in a slightly different way, we can show what's the minimum size of group you need to have for a given chance of there being a shared birthday:

The results may be surprising. You might find them hard to believe. Intuitively, we know that a group of 366 or more people must have 100% probability of a shared birthday, and a group of 1 person has a 0% probability of a shared birthday. But beyond that, most folks' intuition is way out to lunch. You probably didn't guess that with just 23 people, it is more likely than not (50.73% chance) that there is a shared birthday in the group, or that in a group of 70 people there's only about a 1 in 1000 chance of there not being a shared birthday. But now that you've seen the analysis, hopefully it's no longer surprising that there were shared birthdays in your classes or workplace.