Created
July 7, 2022 13:59
-
-
Save timriffe/4ff8a2c9c78eae10b4578904540cc23f to your computer and use it in GitHub Desktop.
attempt to get DemoTools::lt_abrdiged to work with wpp2010 rates
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
library(DemoTools) | |
library(wpp2010) | |
library(sjmisc) | |
library(tidyverse) | |
library(janitor) | |
help(wpp2010) | |
#age-sex-specific mortality rates | |
data(mxM) | |
data(mxF) | |
data(sexRatio) | |
# TR: proposed reshaping for easier bulk calculations | |
mxm <- | |
mxM %>% | |
pivot_longer(`1950-1955`:ncol(.), | |
names_to = "period", | |
values_to = "mx") %>% | |
mutate(sex = "m", | |
age = parse_number(age) %>% as.integer()) %>% | |
janitor::clean_names() %>% | |
arrange(country, period,age) %>% | |
group_by(country, period) %>% | |
mutate(keep = !any(is.na(mx))) %>% | |
ungroup() %>% | |
filter(keep) | |
# attempt for subset | |
mxm %>% | |
dplyr::filter(country_code == 578, | |
period == "2010-2015") %>% | |
do(lt_abridged(nMx = .data$mx, Age = .data$age, OAG = TRUE)) | |
# attempt for all combinations | |
mxm %>% | |
group_by(country, period) %>% | |
# TR: note you'll want to examine the other lt_abridged arguments | |
# and adjust various parameters for different situations, this | |
# was just to see if it runs, seems that yes | |
do(lt_abridged(nMx = .data$mx, Age = .data$age, OAG = TRUE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment