View source: R/input_functions.R
prep.life.table | R Documentation |
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.
prep.life.table(
x,
dec = NA,
agebeg,
ageend = NA,
group = NA,
method = "Standard",
agerange = "included"
)
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: |
method |
character string, optional. Default options is |
agerange |
character string, optional. Default setup is: |
A list of input parameter needed for the function life.table
.
x or Age: age interval.
a: years within x.
Dx: number of deaths within x.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.