Birthday Paradox
June 20, 2014
I decided to use the Wikipedia roster, and downloaded the “view source” to file rosters.wiki
. Then I used awk, which is a good choice for data laundry like this, to scrape the player data from the file:
# rosters.awk
BEGIN { OFS = "|" }
/Captain/ { next }
/Defender/ { next }
/headline/ { # country
sub(/^.*id=\"/,"")
sub(/\".*$/,"")
c = $0 }
/title/ { # player
sub(/^.*title=\"/,"")
sub(/\".*$/,"")
sub(/\(.*\)/,"")
p = $0 }
/bday/ { # birthday
sub(/^.*bday\">/,"")
sub(/<\/sp.*$/,"")
# print c, p, $0 }
b = substr($0,length($0)-5)
if (c == "Algeria" && p ~ /Lacen/) b = "1984-03-15"
if (c == "Chile" && p ~ /Manuel Rojas/) b = "1983-06-23"
if (c == "Chile" && p ~ /Beausejour/) b = "1984-06-01"
if (c == "Croatia" && p ~ /Badelj/) b = ""
if (c == "Germany" && p ~ /Kramer/) b = "1991-02-19"
if ( birthdays[c,b] != "" ) {
print birthdays[c,b]
print c,p,$0
print ""
countries[c]++ }
birthdays[c,b] = c OFS p OFS $0 }
END { for (i in countries) pairs++
print pairs }
The program looks for three bits of information. The /headline/
action extracts a country name from the file. The /title/
action extracts a player name from the file. The /bday/
action extracts the player’s birthday, then looks for matches among the country/birthday pairs already seen. The /Captain/
and /Defender/
actions remove unneeded lines from the output.
The five lines in the middle of the /bday/
action are interesting. When I first ran the program, without those lines, I had 20 teams with birthday pairs instead of the 16 teams of the BBC. Examining the data showed several errors in the WikiPedia data (I’m assuming the FIFA data is correct), which I fixed with those five lines of code. Here’s the output, edited to fix unicode errors:
$ awk -f rosters.awk rosters.wiki
Brazil|Hulk |1986-07-25
Brazil|Paulinho |1988-07-25
Cameroon|Eric Maxim Choupo-Moting|1989-03-23
Cameroon|Eyong Enoh|1986-03-23
Australia|Mathew Ryan|1992-04-08
Australia|Dario Vidosic|1987-04-08
Netherlands|Daryl Janmaat|1989-07-22
Netherlands|Dirk Kuyt|1980-07-22
Spain|Koke |1992-01-08
Spain|David Silva|1986-01-08
Colombia|A.C. Milan|1976-01-13
Colombia|Santiago Arias|1992-01-13
France|Remy Cabella|1984-07-29
Honduras|Wilson Palacios|1984-07-29
Switzerland|Stephan Lichtsteiner|1984-01-16
Switzerland|Reto Ziegler|1986-01-16
Switzerland|Valentin Stocker|1989-04-12
Switzerland|Blerim Dzemaili|1986-04-12
Argentina|Sergio Romero|1987-02-22
Argentina|Enzo Perez|1986-02-22
Argentina|Fernando Gago|1986-04-10
Argentina|Augusto Fernandez|1986-04-10
Bosnia_and_Herzegovina|Asmir Begovic|1987-06-20
Bosnia_and_Herzegovina|Sead Kolasinac|1993-06-20
Iran|Amir Hossein Sadeghi|1981-09-06
Iran|Pejman Montazeri|1983-09-06
Iran|Reza Haghighi|1989-02-01
Iran|Steven Beitashour|1987-02-01
Nigeria|Victor Moses|1990-12-12
Nigeria|Ramon Azeez|1992-12-12
United_States|John Anthony Brooks|1993-01-28
United_States|Chris Wondolowski|1983-01-28
Russia|Sergei Ignashevich|1979-07-14
Russia|Maksim Kanunnikov|1991-07-14
South_Korea|Kwak Tae-hwi|1981-07-08
South_Korea|Son Heung-min|1992-07-08
South_Korea|Kim Young-gwon|1990-02-27
South_Korea|Midfielder|1989-02-27
16
You can run the program at http://programmingpraxis.codepad.org/WsP4nmO9.
In Python. I took the lazy approach. Starting from the FIFA pdf file, I selected all text and copied it to a file. The an re on the dates give exactly 32 * 23 dates. Stripping off the year and splitting by team, the result is quickly obtained.
I’m so sorry.
Praxis, did you over-edit the example output? The players from France and Honduras shouldn’t be a pair, but there appears to be a different pair for each of them in the Wikipedia data (assuming my scripts don’t make stuff up).
This is an XSL Transform that extracts the data from the Wikipedia page (when given the Wikipedia page as input) and writes Scheme code. Three extra entries at end are not teams and have empty “player lists”, which I let be. I didn’t write the Scheme code to count coincidences.
Instead, I edited my XSL Transform to write Python code, thus:
This is run from the shell so:
And after importing the result to a Python session, I used it like this (some linebreaks added for presentation):
Twenty countries agrees with the official example result because I have not corrected the data in any way.
According to Wikipedia page on Jose Rojas Jose Rojas from Chile was born on 23.06.1983, which checks with the FIFA list on
FIFA list.
However on Wikipedia FIFA squads there is a birth date of 03.06.1983. There are clearly inconsistencies in Wikipedia. Maybe also in the FIFA list?!?
It appears there are 2 answers depending on the input data. In the script below I calculate the probabillities for the number of teams with equal birthdays. As expected the highest probabillity is for 16 teams, but the distribution is pretty wide. Twenty teams is still a likely outcome (probabillity is about half of the probability for 16 teams). So, even if the answer is 20, then the birthday paradox has been still “proven”. Most people would think, that only a few teams would have equal birthdays.
A really practical explanation on birthday paradox is here.: http://betterexplained.com/articles/understanding-the-birthday-paradox/
@krups. The explanation given in your link is nice, but unfortunately the formula to calculate the probability for 23 people is not correct. The correct formula can be found on Wikipedia.