Learn R Programming

MortalityLaws (version 2.2.0)

convertFx: Convert Life Table Indicators

Description

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.

Usage

convertFx(x, data, from, to, ...)

Value

A numeric vector or matrix containing the converted life table indicator. If the input was a named object, the output retains those names.

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, or data.frame containing 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", or "lx".

to

The desired output indicator. One of: "mx", "qx", "dx", "lx", "Lx", "Tx", or "ex".

...

Further arguments passed to LifeTable that may affect the results, such as sex, lx0, or ax.

Author

Marius D. Pascariu

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, and lx.

The supported output types (to) are: mx, qx, dx, lx, Lx, Tx, and ex.

There are 28 possible from-to combinations (4 inputs \(\times\) 7 outputs). All conversions pass through the full life-table computation; for example, converting mx to ex will internally compute qx, lx, dx, Lx, and Tx in sequence.

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.

Examples

Run this code
# ---- Basic conversions ----

x  <- 0:110
mx <- ahmd$mx

# Convert death rates to death probabilities
qx <- convertFx(x, data = mx, from = "mx", to = "qx")

# Convert death rates to death distribution
dx <- convertFx(x, data = mx, from = "mx", to = "dx")

# Convert death rates to survivorship
lx <- convertFx(x, data = mx, from = "mx", to = "lx")

# ---- All 28 possible conversions ----

from <- c("mx", "qx", "dx", "lx")
to   <- c("mx", "qx", "dx", "lx", "Lx", "Tx", "ex")
K    <- expand.grid(from = from, to = to)

for (i in 1:nrow(K)) {
  In  <- as.character(K[i, "from"])
  Out <- as.character(K[i, "to"])
  N   <- paste0(Out, "_from_", In)
  cat(i, " Create", N, "\n")
  assign(N, convertFx(x = x, data = get(In), from = In, to = Out))
}

Run the code above in your browser using DataLab