prep.life.table {mortAAR}R Documentation

Creates the input for the function life.table

Description

Prepares the input for life.table(). An individual based approach is supported as well as already pooled data (e. g. from an already existing life table). In the latter case, the user has to specify a numerical variable (dec) which defines the count for each age class. If no life table exists, this function will process a dataframe including the age ranges of individuals or groups of individuals to discrete the age classes. The age range is spread to single years. agebeg has to be specified for the beginning of an age range, as well as ageend for the end of an age range. If a data-set with year-known individuals is used, ageend can be omitted but then the parameter agerange has to left on its default value (included). The method defines in which way the single years between the different age classes are split. If the data set comprises a grouping variable (e.g., sex), this can be specified with group.

Usage

prep.life.table(
  x,
  dec = NA,
  agebeg,
  ageend = NA,
  group = NA,
  method = "Standard",
  agerange = "included"
)

Arguments

x

single dataframe containing sex age and quantity of deceased (individuals or group of individuals).

dec

column name (as character) of the count of deceased, optional.

agebeg

column name (as character) for the beginning of an age range.

ageend

column name (as character) for the end of an age range, optional.

group

column name (as character) of the grouping field (e.g., sex), optional. Default setup is: NA.

method

character string, optional. Default options is Standard, which will create age classes beginning with 1 year, up to 4 years, followed by steps of 5 years (1,4,5,5,...) until the maximum age is reached. Equal5 will create age classes with an even distribution, stepped by 5 years (5,5,...) until the maximum age is reached. If method is a single numeric, this number will be repeated until the maximum age is reached. Thereby, it is possible to create a year-wise life table.

agerange

character string, optional. Default setup is: included. If the age ranges from "20 to 40" and "40 to 60", excluded will exclude the year 40 from "20 to 40", to prevent overlapping age classes. included is for age ranges like "20 to 39" where the year 39 is meant to be counted.

Value

A list of input parameter needed for the function life.table.

Examples

# Separate age ranges in your data set.
df <- dplyr::mutate(
  tidyr::separate(
    replace(
     magdalenenberg,
     magdalenenberg=="60-x", "60-69"
    ),
    a,
    c("from", "to")
  ),
  from = as.numeric(from),
  to = as.numeric(to)
)

# Apply prep.life.table to a data set containing the age ranges.
magda_prep <- prep.life.table(
  df,
  dec = "Dx",
  agebeg = "from",
  ageend = "to",
  method = "Equal5",
  agerange = "included"
)

# Create a life.table.
life.table(magda_prep)


[Package mortAAR version 1.1.6 Index]