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.

365 thoughts on “A morbid Python script

  1. Python question: why are you always doing stuff like:
    float_value = 1*float_num
    ??

  2. Here are the numbers for replacements to the Supreme Court of the United States during the next Presidential term of office:
    bash$ python actuary.py $(($Y-1955))m $(($Y-1936))m $(($Y-1936))m $(($Y-1948))m $(($Y-1933))f $(($Y-1938))m $(($Y-1950))m $(($Y-1954))f 4
    There is a 5% chance of someone dying within 0.2 years (by 2012).
    There is a 50% chance of someone dying within 2.56 years (by 2015).
    There is a 95% chance of someone dying within 8.2 years (by 2020).

    There is a 5% chance of everyone dying within 20.88 years (by 2033).
    There is a 50% chance of everyone dying within 30.66 years (by 2043).
    There is a 95% chance of everyone dying within 39.86 years (by 2052).

    Probability of all dying in 4.0 years: <0.001%
    Probability of a death within 4.0 years: 68.51%

  3. Here are comparable numbers for the current members of the United States House of Representatives:

    bash$ python actuary.py 78.1848049281314m 65.5496235455168m 55.1403148528405f 50.2861054072553m 75.8685831622177m 70.2149212867899m 61.5879534565366m 49.5030800821355m 79.0554414784394f 71.6659822039699f 61.9849418206708m 47.6194387405886m 70.3791923340178m 66.4093086926762m 65.4674880219028m 48.8405201916496m 69.7850787132101m 41.1252566735113m 68.6707734428474m 67.5373032169747m 87.8439425051335m 87.8329911019849m 69.1937029431896m 61.1471594798084m 67.6386036960986m 52.8240930869268m 80.2710472279261m 69.1581108829569m 78.8172484599589m 72.6461327857632m 76.227241615332m 58.1218343600274m 70.3901437371663m 49.5112936344969m 56.6351813826146f 51.192334017796m 65.388090349076f 59.5947980835045f 75.9780971937029f 68.7693360711841m 68.5859000684463m 52.8323066392882m 78.0396988364134m 62.2039698836413f 61.1444216290212m 52.1314168377823f 74.5954825462012m 61.0212183436003m 62.5023956194387m 58.9678302532512f 70.5845311430527m 55.8904859685147m 71.1540041067762m 62.0670773442847m 72.6105407255305m 52.1724845995893m 65.4537987679671f 44.041067761807f 88.4681724845996m 58.5270362765229m 68.7748117727584m 64.1505817932923m 61.6344969199179m 45.5906913073238f 59.129363449692f 56.6160164271047m 64.3340177960301m 55.3319644079398m 59.6714579055441m 56.5639972621492m 77.6509240246407m 64.3285420944559m 63.192334017796m 55.7152635181383m 52.2464065708419m 50.6502395619439m 62.6639288158795m 56.7282683093771m 60.8596851471595m 57.0102669404517m 65.5386721423682m 51.5099247091034m 72.0246406570842m 59.8822724161533m 68.974674880219f 60.4407939767283m 78.3080082135524m 41.1060917180014m 72.2819986310746m 70.8418891170431m 66.4202600958248m 57.574264202601m 61.7522245037645f 53.7467488021903f 75.066392881588m 64.8843258042437m 77.4264202600958m 57.2621492128679m 68.4435318275154m 59.9753593429158m 2
    There is a 5% chance of someone dying within 0.02 years (by 2012).
    There is a 50% chance of someone dying within 0.28 years (by 2012).
    There is a 95% chance of someone dying within 1.22 years (by 2013).

    There is a 5% chance of everyone dying within 42.82 years (by 2055).
    There is a 50% chance of everyone dying within 49.16 years (by 2061).
    There is a 95% chance of everyone dying within 56.86 years (by 2069).

    Probability of all dying in 2.0 years: <0.001%
    Probability of a death within 2.0 years: 99.36%

  4. I’m an actuary and curious what table you are using. You can get some pretty widely disparate results using different tables that are designed for different population subsets…

  5. There is a .059% chance that neither my wife nor I will see our daughter turn 18, and a 5.363% chance that neither of us will. Thanks, Randall.

    python actuary.py 30.5m 25.75f 16.75
    There is a 5% chance of someone dying within 16.1 years (by 2028).
    There is a 50% chance of someone dying within 44.74 years (by 2057).
    There is a 95% chance of someone dying within 60.33 years (by 2072).

    There is a 5% chance of everyone dying within 42.37 years (by 2054).
    There is a 50% chance of everyone dying within 59.95 years (by 2072).
    There is a 95% chance of everyone dying within 71.71 years (by 2084).

    Probability of all dying in 16.75 years: 0.059%
    Probability of a death within 16.75 years: 5.363%

  6. As promised here is the data for the actual US House of Representatives

    bash$ python actuary.py 53m 36f 54m 47m 58m 65m 47f 79m 54m 55m 36m 69m 50m 50m 64m 46m 44m 55m 51m 61m 67m 66m 56m 68f 75f 67m 72f 66f 67m 61m 62f 81m 70f 71m 65f 71m 53m 45m 60m 39m 47m 74f 68m 74m 60m 58m 71m 52m 73m 54m 59f 59f 71f 74f 60f 50f 76f 43f 61m 78m 64m 65m 59m 51f 65m 52f 57m 59m 61m 70m 36m 68f 55f 37m 56m 38m 58m 57m 59m 64m 59m 69f 46m 39m 56m 53m 47m 66f 68m 61m 71m 69m 63m 49m 82m 46f 53m 61m 45f 65m 42m 70f 60f 46m 46f 51m 51m 76m 56f 47m 57m 65m 62f 58m 72m 58m 42m 43m 42m 66m 70m 57m 66m 61f 65f 45m 62m 66m 47m 46m 59m 54m 51m 71m 51m 68f 43m 34m 63m 75f 46m 66m 68m 48m 31m 54m 63m 57m 36m 42m 74m 53m 38m 50m 40m 55m 60m 78m 64m 63m 44m 49f 36m 49m 69m 48m 65m 54m 75m 53m 47m 39m 42m 61m 66m 55m 56m 57m 57m 55m 66m 50m 54f 73m 86m 61m 53m 76m 63m 53m 72m 66m 61m 66m 60m 57m 60m 60m 43m 32m 59m 83m 59m 61m 49m 54m 58f 47m 81m 55m 83m 86m 48m 65m 47m 58f 49m 56f 68m 53m 54m 64m 56m 42m 56m 65m 54m 52m 68m 49m 57m 62f 52m 57m 52m 50m 42m 61f 54m 51m 42m 60m 55m 66m 39m 59m 53m 61m 60m 75m 60m 66m 64m 61m 41m 65m 40m 62m 54m 68m 68f 70m 59m 50m 65m 71m 78m 48f 59f 42m 64f 82m 69m 65m 75f 53f 48m 63m 74f 63m 61m 61f 54f 53m 83f 41m 65m 48f 69m 72m 69f 81m 56m 61m 71f 37m 41m 67m 59m 53m 59m 61f 52m 48m 56m 58m 54m 63m 66f 66m 60f 50m 49f 58m 47m 54m 39m 58m 47m 39m 52m 63m 44m 58f 55m 64m 65m 61m 67m 56m 64m 44m 53m 57m 57m 49m 51m 60m 56m 50m 64f 59m 52m 73m 55m 60m 50m 51m 48m 47m 65m 46m 48m 45m 72m 41f 67m 65m 50m 48m 58m 61f 60f 39m 63m 59m 64m 82m 89m 55m 63m 56m 57m 65m 50m 64m 69f 54m 77m 72m 68m 58m 62f 63m 67m 65m 50m 63m 61m 66m 62m 51m 57m 65m 77f 71m 57m 61m 52m 45m 65m 53m 52m 65m 60m 43m 60m 49m 67m 54m 73m 62m 47m 34f 71m 43f 72m 76m 62m 47m 65m 59f 63m 42m 50f 49m 61f 69m 72m 41m 56m 58f 1
    There is a 5% chance of someone dying within 0.0 years (by 2012).
    There is a 50% chance of someone dying within 0.1 years (by 2012).
    There is a 95% chance of someone dying within 0.46 years (by 2012).

    There is a 5% chance of everyone dying within 55.6 years (by 2068).
    There is a 50% chance of everyone dying within 60.55 years (by 2073).
    There is a 95% chance of everyone dying within 67.12 years (by 2079).

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

  7. You should also mention that both former astronauts and wealthy film stars probably have better health care than the average schmuck.

  8. Here are statistics on the 4 living former Presidents (George H W Bush, George W Bush, Bill Clinton, Jimmy Carter):

    bash$ python actuary.py 87m 88m 65m 66m
    There is a 5% chance of someone dying within 0.14 years (by 2012).
    There is a 50% chance of someone dying within 1.89 years (by 2014).
    There is a 95% chance of someone dying within 6.35 years (by 2018).

    There is a 5% chance of everyone dying within 9.8 years (by 2022).
    There is a 50% chance of everyone dying within 21.53 years (by 2034).
    There is a 95% chance of everyone dying within 31.48 years (by 2044).

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

  9. You haven’t taken into account the time dilation effect of relativity that they experienced while “astronauting”. (I think that should be a verb. I’m sure @neiltyson would agree)

  10. Wouldn’t get away with those tables as a UK pensions actuary! They have to use 2D tables, so the probability of an 80 year old dying in 2032 is less than the probability of an 80 year old dying in 2012. The 1D tables are expected to overestimate the probability of death more as you get further into the future.

    But I’ve moved into health insurance now, so I’m not bothered. (Well, trying not to be. Us actuaries are a picky bunch!)

  11. Love it. (I’m an actuary.) I’m also idly curious about which mortality table was used. For the curious, the Society of Actuaries publishes many tables for free here: http://soa.org/Professional-Interests/Technology/tech-tables.aspx

    For those running this script on your family, note that it doesn’t account for systemic risk (the shared risk of death that you are exposed to by driving in the same car, catching the same diseases, etc.) As a result it understates “Probability of all dying” and overstates “Probability of a death.” Also, as Jon Ahearn mentioned, I don’t think it takes into account the mortality improvement that we expect to see in the future (it would need to be a 2D table with attained age on one axis and years-from-table-publication on the other).

    This isn’t intended as a criticism though… I think it’s a very useful first approximation and I like the idea of people becoming more familiar with the dynamics of mortality.

  12. I looked up the actuary tables for the Netherlands ( http://www.kps.nl/media/rapport-prognosetafel-2010-2060-508.pdf (starting at page 25, and yes, they are 2D)). A 50 year male in 2012 has a death rate of 0.0026446 in the Netherlands, compared to 0.00573 in the script (I guess the US). For a 70-year old male it is 0.0182732 in the Netherlands and 0.02729 in the script.

    It gives the Dutch courage.

  13. Anyone else familiar with the actuarial unit called a “micromort?” It represents a 1-in-a-million chance of dying. I think that’s excellent.

  14. I’d never heard of a micromort, but I think the most disturbing thing about it is the implication that there might exist, for example, a kilomort.

  15. Seems like a kilomort should be a 1 in a 1000 chance *not* to die. And that makes me wonder what unit you need to talk about the man who survived both Hiroshima’s and Nagasaki’s nuclear attacks.

  16. > You can get some pretty widely disparate results using different tables that are designed for different population subsets…

    Indeed. Wikipedia “Simpson’s paradox”. There is no such thing as neutral stratification. Quite post-modern if you askk me.

  17. Harrison Ford just aged to 70.
    So you may update that?
    Also when you are on it you could send this to his Email.
    I guess that it’s something nice to read for his birthday.

  18. Yes, wealthy Carrie Fisher probably does have very good health care, but between all the cocaine she did, and the electroshock therapy, which seems to have caused massive amounts of memory loss– to the extent that she doesn’t really remember Star Wars (if her memoir Wishful Drinking* is to be believed), she’ll probably be in the lower percentiles. She’s abused herself quite a bit, and there’s only so much of that you can buy back with good doctors and sobering up.

    *worth reading

  19. Interesting stats on SC, Senate, & House, but my hunch is they overstate the risk of death of those particular populations. 99.3% chance of a senator dying every two years? That doesn’t seem to fit with my memory. Could these folks be healthier than the average bloke?

  20. I remember reading an interesting piece a while back on a lot of the negative health effects (largely having to do with muscle atrophy, if I recall) of going into space at all, so that kind of thing might be worth taking into consideration when considering the specific health concerns of astronauts.

    Also, re: Roger’s comment–I thought about this, and not being an actuary myself, I came to two conclusions anyway.

    1. You don’t often hear about a representative dying in office; that’s true–but the script seems to be calculating the likelihood of any of the 435 (or whatever) members dying from here to x years in the future. So I’d think the reps who know they’re getting old and death is knocking are far more likely to retire or stop running, and their 95% likely death (out of office) isn’t widely talked about outside of their district. Or something along these lines.

    2. You’re probably right. 99.84% chance of a death within a year? That does sound wrong. If the tables are based on the general population, isn’t that blatantly ignoring that the House is not made up of a deeply diverse sampling of people?

    But this is all just me thinking off the top of my head.

  21. Data for Sweden.

    bothtables=[[0.00224, 0.0003, 0.00005, 0.00014, 0.00014, 0.00004, 0.00007, 0.00013, 0.00004, 0.00014, 0.00006, 0.00008, 0.00006, 0.00012, 0.00012, 0.00018, 0.00019, 0.0004, 0.00039, 0.00059, 0.00045, 0.0007, 0.00061, 0.00071, 0.00066, 0.00064, 0.00065, 0.00065, 0.00069, 0.00064, 0.00063, 0.00089, 0.00054, 0.00058, 0.00077, 0.0007, 0.00077, 0.00066, 0.00079, 0.00081, 0.00099, 0.0009, 0.00093, 0.00123, 0.00163, 0.0014, 0.00167, 0.00192, 0.00221, 0.00256, 0.00264, 0.00294, 0.00273, 0.00341, 0.00369, 0.00448, 0.00505, 0.00456, 0.00615, 0.00696, 0.00672, 0.00762, 0.00788, 0.00911, 0.01018, 0.0119, 0.01301, 0.01374, 0.01586, 0.01753, 0.01838, 0.0205, 0.02215, 0.02538, 0.02763, 0.03109, 0.03748, 0.04118, 0.04628, 0.05178, 0.05659, 0.06073, 0.07217, 0.08591, 0.09525, 0.1062, 0.11805, 0.13371, 0.14202, 0.16468, 0.1806, 0.20522, 0.22203, 0.23959, 0.25786, 0.27681, 0.29642, 0.31667, 0.33753, 0.35902, 0.38113, 0.40387, 0.42728, 0.45139, 0.47621, 0.5018, 0.52816, 0.55531, 0.58325, 0.61192, 0.64125, 0.67112, 0.70136],[0.00196, 0.00021, 0.00004, 0.00009, 0.00007, 0.00008, 0.00004, 0.00008, 0.00018, 0.00012, 0.00015, 0.00011, 0.00006, 0.00004, 0.00008, 0.00012, 0.00014, 0.00022, 0.0003, 0.0002, 0.00027, 0.00019, 0.00024, 0.00021, 0.00032, 0.00032, 0.00029, 0.00028, 0.00025, 0.00041, 0.00024, 0.00031, 0.00034, 0.00046, 0.00045, 0.00039, 0.00049, 0.00041, 0.00052, 0.00061, 0.00037, 0.00057, 0.0008, 0.00064, 0.00089, 0.00102, 0.00115, 0.00129, 0.00106, 0.0014, 0.002, 0.00172, 0.00168, 0.00262, 0.00257, 0.00323, 0.00305, 0.00332, 0.00349, 0.0036, 0.00489, 0.00466, 0.00511, 0.00584, 0.00706, 0.00711, 0.00768, 0.00852, 0.00894, 0.01086, 0.01154, 0.01381, 0.01554, 0.01569, 0.01785, 0.02038, 0.02313, 0.02432, 0.02716, 0.03397, 0.03798, 0.04403, 0.05085, 0.05546, 0.06459, 0.07389, 0.08765, 0.09624, 0.11183, 0.13017, 0.14155, 0.16528, 0.18016, 0.19587, 0.21241, 0.22973, 0.24782, 0.26664, 0.28617, 0.30639, 0.32726, 0.34879, 0.37097, 0.39381, 0.41733, 0.44154, 0.46648, 0.49216, 0.51862, 0.54586, 0.57387, 0.60262, 0.63203]]

    pulled from here: http://www.google.se/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CE4QFjAA&url=http%3A%2F%2Fwww.scb.se%2FStatistik%2FBE%2FBE0101%2F2011A01C%2FBe0101Livsl%25C3%25A4ngdstabeller_11.xls&ei=uV4BULXCIsrl4QSU1YS9CA&usg=AFQjCNGDxnSVlsVYVIdwmUi_t7j0uNE_4g

  22. Pingback: The Final Frontier | SlowerBuffer

  23. I imagine you’ve got some pretty solid demographic knowledge about your reader base. By when are *we* going to be halved by death?

  24. i started reading this and began to think that John Cleese and co used to be lot funnier than this, then i reread the title.

  25. I was born to an elderly couple (by the day’s standards) almost 30 years ago. Both of my parents are alive and relatively well. Looking back, I feel lucky.

    Probability of all dying in 29.5 years: 5.207%
    Probability of a death within 29.5 years: 43.31%

    Morbidity is in the eye of the beholder, I’d say.

  26. Pingback: » A morbid Python script. Gordon's shares

  27. Pingback: sigh

  28. Can you write a Python script to calculate death probabilities for skydivers, stuntmen, motorcyclists, carracers and rockstars? I think it would be very interesting…

  29. Not so sure about former astronauts – if they’re pilots, they’ll generally have higher radiation exposure over the course of the career than the average Joe (or Jill), and that doesn’t even take into account the exposure they may get in space (which is a good question- I don’t know what that is). Couple that with prolonged exposure to jet and/or rocket fuel (Benzene, it’s what’s for dinner!) and I would expect you’ve got a fair counter-balance to being in good physical shape.

    –JT

  30. I’m sure the trip to and from the moon took some years off…as well as the cocaine when they returned. But I also suspect everyone on the millennium falcon took 10 years off their lives while they were filming it.
    love your stuff

  31. python actuary.py -50m 1
    There is a 5% chance of someone dying within 10.56 years (by 2023).
    There is a 50% chance of someone dying within 34.06 years (by 2046).
    There is a 95% chance of someone dying within 47.45 years (by 2060).

    so, a 95% chance that someone born in 2062 will never be born???

  32. Of course, if you include the other star of Star Wars, the probability of a death in the next ten minutes rises to 100%.

  33. James Earl Jones wasn’t actually in Star Wars (the movie later to be dubbed Star Wars: Episode IV).

    David Prowse played Darth Vader and he also did the voice. Empire strikes back had James Earl Jones to do the voice of Darth and Lucas later overdubbed David Prowse with James Earl Jones on the newer editions of Star Wars as well, this was done even before the CG crap was added to it and Han Solo got nerfed by having greedo shoot first etc etc.

  34. Fortunately, we can still get the original via Amazon (the new Empire? “. . . meet the new boss, same as the old boss . . .”), on DVD no less: a two disc set that includes the original theatrical releases of the first three movies. So yes, in one parallel universe at least, Han is still a cold-blooded killer.

    Hey, Randall? How about a physics question that explores string theory and unwanted sequels and/or “enhancements”? Just sayin’ . . .

  35. @AndersBackman

    I was surprised to hear about James Earl Jones having re-dubbed the voice of Darth Vader for Star Wars and not being in the original cast. After doing a little research on imdb.com, it would appear that he did do the voicework in March of 1977, though he refused to have his name in the credits.

    I’m sure Prowse did all his lines on camera though.

    Harmless facts. he did all his lines in one day and was paid $9000 for his work.

  36. Your code is really hard to read– and that’s saying something, given that the script is written in Python, hehe. If not for your programmer fans, you should work on it so you’ll at least be able to look back and remember what you were doing. Just use a lot more whitespace (“a<b" is for chumps), always use underscores or camel-case in your variable/method names, and generally make the names more descriptive of what the variables represent (even if they're hideously long), then you'll be golden. Believe me, you'll thank yourself for doing it.

  37. Of course JEJ was the voice the entire time but whatever. Like star-wise it would have been more appropriate to include Sir Alec Guinness and Peter Cushing, but they’ve been gone since 2000 and 1994 respectively.

    What would also be interesting is to do tables for everyone involved in writing, directing, doing special effects, acting, and so on in Star Wars (credited in the 1977 original material or not) as of 1977, as if it were still 1977. Or just the actors not there besides Guinness and Cushing, such as Kenny Baker, Anthony Daniels, Peter Mayhew, Phil Brown, Shelagh Fraser, and Dennis Lawson. Regardless of who’s included, make it at least 10 or 20 or more, and then see how the predictions worked out now, as if they were made before the fact, instead of in hindsight.

    Or not.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>