Learn R Programming

LEdecomp (version 1.0.4)

sen_num: A numerical approximation of the sensitivity of life expectancy at birth to changes in mortality.

Description

Here we produce a numerical derivative based on the methods implemented in the numDeriv::grad() function. Tweaking the optional arguments of numDeriv::grad(), passed in via ... might lead to greater precision, but this method actually performs usably well with its defaults.

Usage

sen_num(
  mx,
  age = (1:length(mx)) - 1,
  nx = rep(1, length(mx)),
  sex = "t",
  closeout = TRUE,
  ...
)

Value

numeric vector of sensitivity of life expectancy to perturbations in mx.

Arguments

mx

numeric vector of the mortality rates (central death rates)

age

integer vector of the lower bound of each age group (currently only single ages supported)

nx

age interval width, assumes 1 by default

sex

character: Male ("m"), Female ("f"), or Total ("t")

closeout

logical. Default TRUE.

...

optional arguments to pass to mx_to_e0()

Examples

Run this code
x <- 0:100
mx <- 0.001 * exp(x * 0.07)
sn <- sen_num(mx,age=x,sex='t',closeout=TRUE)
sa <- sen_arriaga_instantaneous2(mx, age=x,sex='t',perturb = 1e-4)
# \donttest{
plot(x,sa)
lines(x,sn)
# }
# examine residuals:
sn - sa
# Note discrepancies in ages >0 are due to numerical precision only
# \donttest{
plot(x, sn - sa, main = "still uncertain what accounts for the age 0 discrepancy")
# }

Run the code above in your browser using DataLab