Easily convert between different life table indicators (e.g., from death
rates mx to death probabilities qx, or from survivorship
lx to life expectancy ex). The function wraps
LifeTable internally, so the conversion relies on the
same constant-force-of-mortality (CFM) assumption and life-table
methodology used throughout the package.
Arguments
- x
Numeric vector of ages at the beginning of each age interval. For a full life table, use single-year ages (e.g.,
0:110). For an abridged life table, use the lower bound of each interval (e.g.,c(0, 1, 5, 10, ..., 110)).- data
A numeric
vector,matrix, ordata.framecontaining the mortality indicator to be converted. Each row should correspond to an age, each column to a separate population or time period.- from
The type of indicator supplied in
data. One of:"mx","qx","dx","lx", or"ex".- to
The desired output indicator. One of:
"mx","qx","dx","lx","Lx","Tx", or"ex".- ...
Further arguments passed to
LifeTablethat may effect the results, such assex,lx0,ax, or the closing argumentsclose,omegaandfit_from. Whenomegaextends the table beyond the input's open age, the result carries the extended ages (vector names, or matrix row names) rather than the input ages.
Value
A numeric vector or matrix of class "convertFx" containing
the converted life table indicator. If the input was a named object, the
output retains those names. The result carries the ages it is indexed by
(x), the conversion (from, to) and the input curve
(input) as attributes, which is what
plot.convertFx draws. It behaves like the underlying
numeric vector or matrix in every other respect; subsetting returns the
bare values.
Details
This function provides a convenient interface for converting a single
mortality indicator into another, without having to call
LifeTable directly and extract the desired column.
The supported input types (from) are:
mx, qx, dx, lx, and ex.
The supported output types (to) are:
mx, qx, dx, lx, Lx, Tx, and
ex.
There are 35 possible from-to combinations (5 inputs
\(\times\) 7 outputs). Conversions that need a single life-table
identity, such as mx to qx or dx to lx, are
computed directly from that relation. All the other conversions are
obtained from the full life-table computation; for example, converting
mx to ex will internally compute qx, lx,
dx, Lx, and Tx in sequence. A ex input is
converted by building the life table that reproduces the supplied curve
(see LifeTable).
When data is a vector, the function returns a named vector.
When data is a matrix or data.frame with multiple
columns, the function applies the conversion column-wise and returns a
matrix with the same row and column names as the input.
See also
LifeTable for the underlying life-table construction;
LawTable for generating life tables from parametric
mortality laws; plot.convertFx for plotting a conversion.
Examples
# ---- Basic conversions ----
x <- 0:110
mx <- ahmd$mx
# Convert death rates to death probabilities
qx <- convertFx(x, data = mx, from = "mx", to = "qx")
#> 'mx' contains missing or non-finite values at age(s) 107, 108, 109, 110. Rows below age 100 are returned as NA with the survivorship bridged across the gap; rows from age 100 are replaced with the highest rate observed there.
# Convert death rates to death distribution
dx <- convertFx(x, data = mx, from = "mx", to = "dx")
#> 'mx' contains missing or non-finite values at age(s) 107, 108, 109, 110. Rows below age 100 are returned as NA with the survivorship bridged across the gap; rows from age 100 are replaced with the highest rate observed there.
# Convert death rates to survivorship
lx <- convertFx(x, data = mx, from = "mx", to = "lx")
#> 'mx' contains missing or non-finite values at age(s) 107, 108, 109, 110. Rows below age 100 are returned as NA with the survivorship bridged across the gap; rows from age 100 are replaced with the highest rate observed there.
# Convert death rates to life expectancy
ex <- convertFx(x, data = mx, from = "mx", to = "ex")
#> 'mx' contains missing or non-finite values at age(s) 107, 108, 109, 110. Rows below age 100 are returned as NA with the survivorship bridged across the gap; rows from age 100 are replaced with the highest rate observed there.