library(expstudies) library(dplyr) library(magrittr) library(pander) exposures <- addExposures(records) head(exposures) exposures_mod <- exposures %>% inner_join(select(records, key, issue_age, gender), by = "key") %>% mutate(attained_age = issue_age + duration - 1)
Start with the exposures_mod frame from the "Creating Exposure Intervals" article.
head(exposures_mod)
pander::pandoc.table(head(exposures_mod), split.table = Inf)
Add a death indicator and use a full exposure in the year of death when performing a mortality study.
exposures_mort <- exposures_mod %>% group_by(key) %>% mutate(exposure_mod = if_else(duration == max(duration), 1, exposure), death_cnt = if_else(duration == max(duration), 1, 0)) tail(exposures_mort, 4)
exposures_mort <- exposures_mort %>% ungroup() %>% select(-exposure, -issue_age) pander::pandoc.table(tail(exposures_mort, 4), split.table = Inf)
We then aggregate by duration to calculate mortality rates.
duration_rate <- exposures_mort %>% group_by(duration) %>% summarise(q = sum(death_cnt)/sum(exposure_mod)) duration_rate
pander::pandoc.table(duration_rate)
Or by attained age and gender.
attained_age_gender_rates <- exposures_mort %>% group_by(attained_age, gender) %>% summarise(q = sum(death_cnt)/sum(exposure_mod)) tail(attained_age_gender_rates)
pander::pandoc.table(tail(attained_age_gender_rates))
Some mortality tables have been loaded in an easy to join format so that users can conduct A/E analysis.
summary(expstudies::mortality_tables)
The "table" column includes the table identifier from the SOA website's collection of mortality tables.
head(mortality_tables$AM92$AM92_Ultimate)
pander::pandoc.table(head(mortality_tables$AM92$AM92_Ultimate))
We join the mortality table to the data frame using the attained age.
head(left_join(exposures_mort, mortality_tables$AM92$AM92_Ultimate, by = "attained_age"))
pander::pandoc.table(head(left_join(exposures_mort, select(mortality_tables$AM92$AM92_Ultimate, -table), by = "attained_age")), split.table = Inf)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.