Last active
August 29, 2015 14:01
-
-
Save timriffe/125666133e6a68d0e70c to your computer and use it in GitHub Desktop.
chances of living from 33 to 99
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see install instructions here: | |
# https://github.com/UCBdemography/DemogBerkeley | |
library(DemogBerkeley) | |
us <- userInput() | |
pass <- userInput() | |
mltper <- readHMDweb("USA","mltper_1x1",username = us, password = pass) | |
lx <- mltper$lx[mltper$Year == 2010] | |
lx <- lx / 1e5 | |
# lx is at exact cutpoints, like today for me! | |
lx[100] / lx[34] # my chances if mortality is held constant at US 2010 levels, and if I'm totally average | |
# mx refers to an interval of time- 1 year | |
mx <- mltper$mx[mltper$Year == 2010] | |
# 1% improvement | |
# we need mx's up through age 98 to get me to age 99: | |
mx1pct <- mx[34:99] * .99 ^ c(1:66) | |
exp(-cumsum(mx1pct)) # nifty direct path from rates to survival | |
# 2% improvement | |
mx2pct <- mx[34:99] * .98 ^ c(1:66) | |
exp(-cumsum(mx2pct)) | |
# compare with Japan | |
mltperJ <- readHMDweb("JPN","mltper_1x1",username = us, password = pass) | |
# life expectancy at birth, 2012: | |
e02012 <- mltperJ$ex[mltperJ$Year == 2012][1] | |
# how long would it take US mortality to catch up with 2012 Japan at 1% improvement/year? | |
mx1pct2 <- outer(mx, .99 ^ c(1:50),"*") | |
plot(2011:2060,apply(mx1pct2,2,function(.mx){ | |
sum(exp(-cumsum(.mx))) | |
}),type='l') | |
abline(h=e02012) | |
# 2% ? | |
mx2pct2 <- outer(mx, .98 ^ c(1:50),"*") | |
plot(2011:2060,apply(mx2pct2,2,function(.mx){ | |
sum(exp(-cumsum(.mx))) | |
}),type='l') | |
abline(h=e02012) | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment