Start with the exposures_mod frame from the “Creating Exposure Intervals” article.

head(exposures_mod)
key duration start_int end_int exposure issue_age gender attained_age
B10251C8 1 2010-04-10 2011-04-09 0.9993 35 M 35
B10251C8 2 2011-04-10 2012-04-09 1.002 35 M 36
B10251C8 3 2012-04-10 2013-04-09 0.9993 35 M 37
B10251C8 4 2013-04-10 2014-04-09 0.9993 35 M 38
B10251C8 5 2014-04-10 2015-04-09 0.9993 35 M 39
B10251C8 6 2015-04-10 2016-04-09 1.002 35 M 40

Add a death indicator and use a full exposure in the year of death when performing a mortality study.

key duration start_int end_int gender attained_age exposure_mod death_cnt
D68554D5 12 2016-01-01 2016-12-31 F 41 1.002 0
D68554D5 13 2017-01-01 2017-12-31 F 42 0.9993 0
D68554D5 14 2018-01-01 2018-12-31 F 43 0.9993 0
D68554D5 15 2019-01-01 2019-04-04 F 44 1 1

We then aggregate by duration to calculate mortality rates.

duration q
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0.5002
10 0
11 0
12 0
13 0
14 0
15 1

Or by attained age and gender.

attained_age gender q
41 M 0
42 F 0
42 M 0
43 F 0
43 M 1
44 F 1

##Expected mortality

Some mortality tables have been loaded in an easy to join format so that users can conduct A/E analysis.

summary(expstudies::mortality_tables)
##                                         Length Class  Mode
## AM92                                    3      -none- list
## GAM1983                                 3      -none- list
## UP1984                                  3      tbl_df list
## VBT2015_SmokerDistinct_ALB              2      -none- list
## CSO2017_Unloaded_PreferredStructure_ALB 2      -none- list
## CSO2017_Loaded_PreferredStructure_ALB   2      -none- list

The “table” column includes the table identifier from the SOA website’s collection of mortality tables.

head(mortality_tables$AM92$AM92_Ultimate)
table attained_age q_ult
t2360 19 0.000587
t2360 20 0.000582
t2360 21 0.000577
t2360 22 0.000572
t2360 23 0.000569
t2360 24 0.000567

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"))
key duration start_int end_int gender attained_age exposure_mod death_cnt q_ult
B10251C8 1 2010-04-10 2011-04-09 M 35 0.9993 0 0.000689
B10251C8 2 2011-04-10 2012-04-09 M 36 1.002 0 0.000724
B10251C8 3 2012-04-10 2013-04-09 M 37 0.9993 0 0.000765
B10251C8 4 2013-04-10 2014-04-09 M 38 0.9993 0 0.000813
B10251C8 5 2014-04-10 2015-04-09 M 39 0.9993 0 0.00087
B10251C8 6 2015-04-10 2016-04-09 M 40 1.002 0 0.000937