Created
November 14, 2023 13:00
-
-
Save timriffe/ae15c6a7dcab51a52b34df654a13911c to your computer and use it in GitHub Desktop.
hacky M estimation from single-age data
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
devtools::load_all() | |
# library(HMDHFDplus) | |
# mx <- readHMDweb("USA","mltper_1x1", | |
# username = Sys.getenv("us"), | |
# password = Sys.getenv("pw")) |> | |
# filter(Year == 2000) |> | |
# pull(mx) | |
mx <- c(0.00791, 0.00056, 0.00038, 0.00029, 0.00022, 0.00021, 0.00019, | |
0.00017, 0.00016, 0.00016, 0.00018, 0.00021, 0.00022, 0.00026, | |
0.00035, 0.00049, 0.00072, 0.00093, 0.00116, 0.00132, 0.00135, | |
0.00142, 0.00137, 0.00134, 0.00135, 0.00127, 0.00127, 0.0013, | |
0.00129, 0.00134, 0.00129, 0.0014, 0.00145, 0.00156, 0.00169, | |
0.00174, 0.0019, 0.00204, 0.00226, 0.00235, 0.0026, 0.00278, | |
0.003, 0.00333, 0.00359, 0.00384, 0.00419, 0.00455, 0.00502, | |
0.00523, 0.00554, 0.00588, 0.00643, 0.00683, 0.00735, 0.00825, | |
0.00901, 0.00981, 0.01076, 0.01177, 0.01267, 0.01369, 0.01531, | |
0.01674, 0.01841, 0.01974, 0.02148, 0.02364, 0.02566, 0.02785, | |
0.03064, 0.03332, 0.03745, 0.04012, 0.04332, 0.04772, 0.05175, | |
0.05643, 0.06245, 0.06951, 0.08043, 0.08598, 0.09718, 0.10638, | |
0.11855, 0.13146, 0.14549, 0.16027, 0.17495, 0.19596, 0.2124, | |
0.23314, 0.25763, 0.28428, 0.30846, 0.32839, 0.35464, 0.3818, | |
0.40972, 0.43823, 0.46716, 0.49631, 0.52548, 0.55449, 0.58312, | |
0.61121, 0.63857, 0.66507, 0.69056, 0.71495, 0.73814) | |
delta <- .01 | |
lower <- 50 | |
mx2 <- splinefun(mx ~ .5:110.5)(seq(lower,110,by=delta)) | |
dx <- -diff(c(1,exp(-cumsum(mx2*delta)),0)) | |
# Mode | |
which.max(dx) * delta + lower | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment