life_table: Generate a standard life table

life_tableR Documentation

Generate a standard life table

Description

Generates a standard life table given a data.frame or data.table with basic essential attributes.

Usage

life_table(
  ph.data,
  myages = "ages",
  mydeaths = "deaths",
  mypops = "pop",
  myprops = "fraction",
  group_by = NULL,
  ci = 0.95
)

Arguments

ph.data

a data.table or data.frame. Must contain aggregated deaths and corresponding populations, as well as the age interval and the average fraction of years lived in the interval by those who die in the interval. It is highly recommended, though not necessary, that you use life_table_prep to prepare ph.data.

The default value is ph.data = NULL.

myages

a character vector of length one identifying a column specifying the beginning and end of each age interval separated by a hyphen. Note, the start of each interval should be the end of the previous interval, e.g., '5-10', '10-15', '15-20', etc. Think of this as short-hand for [5, 10), [10, 15), [15, 20), etc.. The final interval should be open ended with the starting value followed by a '+' (e.g., '85+', '90+', etc.). The maximum age cannot exceed 100 in order to align with WA State population estimates. Leave the value blank (i.e., NA) for the total deaths at an unknown age. These deaths will be distributed proportionately over the other age groups.

The default value is myages = "ages".

mydeaths

a character vector of length one identifying a numeric column with the total deaths for the given age interval in the given year(s).

The default value is mydeaths = "deaths".

mypops

a character vector of length one identifying a numeric column with the total population in the age intervals corresponding to mydeaths. This is technically the mid-year population. In practice we usually use OFM population estimates available from get_population.

The default value is mypops = "pop".

myprops

a character vector of length one identifying a numeric column with the average proportion of the interval lived by those who died in the interval. For example, if those who died in '80-85' lived an average of 1000 days past their 80th birthday, myprops would be 0.54 (1000/(365.25*5)).

The default value is myprops = "fraction".

group_by

a character vector used to specify all the variables by which you want to group (a.k.a. stratify) the results. For example, if you specified group_by = c('chi_sex', 'chi_race_6'), the results would be stratified by each combination of sex and race.

The default is group_by = NULL

ci

a numeric value representing the confidence level, which must be greater than 0 and less than 1.

The default value is ci = 0.95.

Details

The function returns the following life table columns:

  • mx: age interval specific death rate

  • qx: probability of dying in the age interval

  • lx: # of (theoretical) persons alive at the start of the age interval

  • dx: # of deaths during the age interval

  • ax: average fraction of the interval lived by those who died in the interval

  • Lx: total person years lived in the age interval

  • Tx: total person years lived beyond the start of the age interval

  • ex: expectation of life (a.k.a., life expectancy) at the start of the age interval. The value of ex for those under one year of age is typically referred to as 'Life Expectancy at Birth'.

Value

a data.table with the pre-existing columns plus the standard life table columns

References

Chiang, Chin Long & World Health Organization. (1979). Life table and mortality analysis / Chin Long Chiang. World Health Organization. https://apps.who.int/iris/handle/10665/62916

Silcocks PB, Jenner DA, Reza R. Life expectancy as a summary of mortality in a population: Statistical considerations and suitability for use by health authorities. J Epidemiol Community Health 55(1):38–43. 2001

Examples


# 1970 CA abridged death data
dt <- data.table::data.table(
  ages = c("0-1", "1-5", "5-10", "10-15", "15-20", "20-25", "25-30", "30-35",
           "35-40", "40-45", "45-50", "50-55", "55-60", "60-65", "65-70",
           "70-75", "75-80", "80-85", "85+"),
  deaths = c(6234, 1049, 723, 735, 2054, 2702, 2071, 1964, 2588, 4114, 6722,
             8948, 11942, 14309, 17088, 19149, 21325, 20129, 22483),
  pop = c(340483, 1302198, 1918117, 1963681, 1817379, 1740966, 1457614,
          1219389, 1149999, 1208550, 1245903, 1083852, 933244, 770770,
          620805, 484431, 342097, 210953, 142691),
  fraction = c(0.09, 0.41, 0.44, 0.54, 0.59, 0.49, 0.51, 0.52, 0.53, 0.54, 0.53,
               0.53, 0.52, 0.52, 0.51, 0.52, 0.51, 0.50, NA))

# Create arbitrary small variations for 'demographic' groups
# first create an empty table
mygroups <- data.table::CJ(shape = c('circle', 'square'), color = c('blue', 'orange'))
dt_groups <- merge(data.table::copy(dt)[,constant := 1],
                   mygroups[, constant := 1],
                   by = 'constant',
                   allow.cartesian = TRUE)[, constant := NULL]
# now modify the values
set.seed(98104)
dt_groups[, deaths := round(deaths * sample(seq(.75, 1.25, .01), .N, replace = TRUE))]
dt_groups[, pop := round(pop * sample(seq(.75, 1.25, .01), .N, replace = TRUE))]


nogroups <- life_table(ph.data = dt,
                     myages = 'ages',
                     mydeaths = 'deaths',
                     mypops = 'pop',
                     myprops = 'fraction',
                     group_by = NULL,
                     ci = 0.95)
head(nogroups)

yesgroups <- life_table(ph.data = dt_groups,
                      myages = 'ages',
                      mydeaths = 'deaths',
                      mypops = 'pop',
                      myprops = 'fraction',
                      group_by = c('shape', 'color'),
                      ci = 0.95)
head(yesgroups)



PHSKC-APDE/rads documentation built on April 14, 2025, 10:47 a.m.