convertFx: Convert Life Table Indicators

Description Usage Arguments Author(s) See Also Examples

View source: R/convertFx.R

Description

Easy conversion between the life table indicators. This function is based on the LifeTable function and methods behind it.

Usage

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

Arguments

x

Vector of ages at the beginning of the age interval.

data

Vector or data.frame/matrix containing the mortality indicators.

from

Specify the life table indicator in the input data. Character. Options: mx, qx, dx, lx.

to

What indicator would you like to obtain? Character. Options: mx, qx, dx, lx, Lx, Tx, ex.

...

Further arguments to be passed to the LifeTable function with impact on the results to be produced.

Author(s)

Marius D. Pascariu

See Also

LifeTable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Data ---
x  <- 0:110
mx <- ahmd$mx

# mx to qx
qx <- convertFx(x, data = mx, from = "mx", to = "qx")
# mx to dx
dx <- convertFx(x, data = mx, from = "mx", to = "dx")
# mx to lx
lx <- convertFx(x, data = mx, from = "mx", to = "lx")


# There are 28 possible combinations --------------------------------
# Let generate all of them.
from <- c("mx", "qx", "dx", "lx")
to   <- c("mx", "qx", "dx", "lx", "Lx", "Tx", "ex")
K    <- expand.grid(from = from, to = to) # all possible cases/combinations

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")
  # Create the 28 sets of results
  assign(N, convertFx(x = x, data = get(In), from = In, to = Out))
}

MortalityLaws documentation built on Nov. 6, 2018, 5:04 p.m.