# A morbid Python script

Comics #493 and #893 involve actuarial tables, which are tables for calculating the probability that someone of a given age will die within a given amount of time.

One evening, when I was feeling morbid, I wrote a Python script to calculate death probabilities for any collection of people: actuary.py (.txt). It takes a list of ages and genders and produces various statistics. Here’s the report for the nine living people who have walked on the moon:

```~\$ python actuary.py 81m 82m 80m 81m 80m 81m 76m 78m 77m
There is a 5% chance of someone dying within 0.08 years (by 2012).
There is a 50% chance of someone dying within 1.1 years (by 2013).
There is a 95% chance of someone dying within 4.08 years (by 2016).

There is a 5% chance of everyone dying within 10.78 years (by 2023).
There is a 50% chance of everyone dying within 16.12 years (by 2028).
There is a 95% chance of everyone dying within 22.57 years (by 2035).

Probability of all dying in 1.0 year: <0.001%
Probability of a death within 1.0 year: 46.32%```

And here’s the table for four of the main stars of the original Star Wars (Harrison Ford, Carrie Fisher, Mark Hammill, James Earl Jones):

```~\$ python actuary.py 69m 55f 60m 81m 10
There is a 5%  chance of someone dying within 0.42 years (by 2012).
There is a 50% chance of someone dying within 4.74 years (by 2017).
There is a 95% chance of someone dying within 12.83 years (by 2025).

There is a 5%  chance of everyone dying within 18.17 years (by 2030).
There is a 50% chance of everyone dying within 31.28 years (by 2043).
There is a 95% chance of everyone dying within 42.62 years (by 2055).

Probability of all dying in 10.0 years:   0.272%
Probability of a death within 10.0 years: 85.94%```

Of course, these are based on average death rates based only on age and gender. Adding more specific information about the people in question will refine the calculation. For example, I’d guess former astronauts are more likely to be in good health—and have longer life expectancies—than the rest of us.

## 382 thoughts on “A morbid Python script”

1. Maybe you’d better increase those mortality rates, they’re here!

On second thought, they’ve apparently been here for 2 years already, so you’ve probably seen this one. Anyway…

Like

2. What happened to the XKCD Forum? I miss it and would welcome it’s return. Now where do I turn to when I don’t understand a comic? 🙂

Like

3. I’m pretty sure former astronauts actually tend to die younger, due to a tendency toward risky behavior – test pilots, fast motorcycles, helicopter pilots, etc.

Like

4. Could you run another script to determine the best life insurance policies to take out on them?

Like

5. I read this post today for the first time. Just a few hours later I’ve found out Neil Armstrong has passed away. What an odd coincidence.

Like

6. Went here to see if there was a quick post about Neil Armstrong’s death, and I found out that the first table is the probability of death among the people who went to the moon. A creepy coincidence.

Like

7. the first thing i thought when i heard neil armstrong died was about this post, heh

Like

8. Just like for brian earlier, this was the first thing that came to my mind after hearing the news. Can you count what was the probability for someone dying so soon after july 12th?

Like

9. I read this article for the first time literally about 15 minutes before I heard about Mr. Armstrong’s death. I’m not normally a big xkcd fan, honestly… I just happened to be dinking around because someone on Facebook had linked to one of the comics earlier today. The coincidence was big enough to make me do a double-take.

Like

10. Andrew. “I don’t think it’s coincidence at all. I think it’s statistics.”

The tables are statistics.

The fact that they discovered this page on the day he died, minutes before learning about it, is a coincidence.

Like

11. Penelope, no, it had a probability higher than 5%.
“There is a 5% chance of someone dying within 0.08 years”
That’s within 29 days after July 12 (or the day the script was run).

Since there is already a 50% chance in 1.1 years, the probability raises pretty fast and may differ significantly from 5%.

I hope Randall gives us an update with the actual probability for this event and a new calculation of the time span now that there’s one random variable less (sorry Neil).

Like

12. I just saw Armstrong’s last interview. He said that at the time he estimated his chance of returning from the moon alive at 90%. Thus, his chance of dying in 1969 was 10%, and his chance of dying in 2012 was 5%. Statistics are odd.

Like

13. Here is the updated stats from the python script.

python actuary.py 82m 82m 81m 80m 81m 76m 78m 77m There is a 5% chance of someone dying within 0.09 years (by 2012). There is a 50% chance of someone dying within 1.21 years (by 2013). There is a 95% chance of someone dying within 4.44 years (by 2017). There is a 5% chance of everyone dying within 10.23 years (by 2022). There is a 50% chance of everyone dying within 15.77 years (by 2028). There is a 95% chance of everyone dying within 22.4 years (by 2035). Probability of all dying in 1.0 year: <0.001% Probability of a death within 1.0 year: 42.88%

Like

14. Apologies. Hopefully formatted in a more readable fashion this time.

# python actuary.py 82m 82m 81m 80m 81m 76m 78m 77m
There is a 5% chance of someone dying within 0.09 years (by 2012).
There is a 50% chance of someone dying within 1.21 years (by 2013).
There is a 95% chance of someone dying within 4.44 years (by 2017).

There is a 5% chance of everyone dying within 10.23 years (by 2022).
There is a 50% chance of everyone dying within 15.77 years (by 2028).
There is a 95% chance of everyone dying within 22.4 years (by 2035).

Probability of all dying in 1.0 year: <0.001%
Probability of a death within 1.0 year: 42.88%

Like

15. And finally in response to commenters asking about the probability (according to the tables) of this happening from the date is was calculated…

44 days is around 0.12047 of a 365.25 day year.

Probability of his death alone within 0.12047 years: 0.937%
Probability of a death in the group within 0.12047 years: 7.401%

However he did turn 82 earlier this month, given the script does not take this into account the odds would have been slightly higher. His age would have been 81 years and 342 days or 81.93ish (deciding what year length to use is tricky) at the time the computation was run. With this in mind my final answer would be.
Probability of his death alone within 0.12047 years: 1.031%
Probability of a death in the group within 0.12047 years: 7.489%

Note: age adjusted only for Neil Armstrong. None of the others have had a birthday since but the amounted variance would create a shift in the stats.

Sorry for the triple post.

Like

16. The 5% chance just kicked in yo.

Like

17. I can’t believe I read this entry within hours of hearing that Neil Armstrong was dead.

Like

18. Omigosh, I did a double take! I came to know about Armstrong’s death hours before I randomly decided to read this post! O_O

Like

19. Totally weird that Neil Armstrong died so quickly after you put this up

Like

20. Christian said in response to Andrew:

“The tables are statistics.

The fact that they discovered this page on the day he died, minutes before learning about it, is a coincidence.”

I don’t know the numbers, but I’d hypothesize that this blog gets fairly continuous traffic. It seems highly improbable that there wouldn’t be at least /somebody/ reading this post shortly before or after hearing the news to have been struck by the “creepy coincidence.” The likelihood that at least one of said persons would be spurred to comment on it seems pretty high given that they’d’ve been primed either by the news itself or by this entry to be attentive to astronaut mortality.

The thing that might more likely be deemed coincidental is that this was the most recent post at the time that the news broke. However, given the frequency of these blag entries (less than once a month over the past year), if the simulation were actually fairly accurate, there was a greater than 5% chance that this might happen.

I don’t have the data to be more than hand-wavy on the matter, but my point remains that Andrew hit it on the nose.

Like

21. I’m guessing the life expectancy numbers used were from the USA. It would be interesting to add other countries in the script as sadly the US are quite in the lower end compared to other developped countries.

Like

22. If you’re going to predict deaths, I think grouping the celebrities the way you did is much less creepy than deathlist.net or other celebrity death prediction sites where a particular person is named. How depressing would it be to see your name on a list for those expected to die this year? It’s still morbid, and a little creepy, to see the probability that someone in your group of friends is going to die – but it does give you the chance to deny the possibility your own imminent demise if you’re not ready to face that reality just yet.

Like

23. I liked today’s comic, about the license plate with I’s and 1’s. It reminded me a bit of a day back in high school when we had to do teacher evaluations. One (somewhat dim) kid, as he turned in his evaluation, told the teacher, “I wrote my evaluation with my left hand, so you wouldn’t be able to read my handwriting.”

Like

24. Air Cargo Service
http://www.delvi.com
Overnight Air Cargo to Panama. This service usually goes by weight and is used for documents, or any time sensitive materials you want in Panama overnight.
Air Cargo to Panama, This service usually goes by weight our daily consolidation of air cargo to Panama is a great way to share the space and save on price. We recommend cargo Under to 10 LBS be shipped by air to Panama. As container cargo usually has a \$20 price tag just for customs and clearance paperworks.

Like

25. Unit cancellation may be weird, but it’s one of the best non-computational tests to ensure that you’ve set up your physics problem properly. And you know this as well as, or better than, I do.

Like

26. Regarding today’s comic (Sports Cheat Sheet), you need at least one extra column labeled “Canada,” for which all twelve months would be hockey.

Like

27. #1107 Of the comic is pretty much wrong. If your country has any area inside the arctic circle it is 90% hockey and the remaining 10% (summer) all kinds of sports. Look at canada, USA, finland, russia, sweden, norway and… oh wait there are no more i think =C

Like

28. I agree with the above comments about today’s comic. Next-to-nobody I know argues about football at any time in the year. I’m from Canada, and I’ve lived in multiple provinces now, and it’s all hockey. Even the athletes in other sports love to discuss hockey.

Like

29. Pingback: Quirl Blog – Physics and stuff