| maybe_dither_lx | R Documentation |
Force lx to be monotonically decreasing. Ties in consecutive values of lx produce problems to estimate quantiles from lx in various of our functions. These either result in warnings or errors. This function checks for ties, and if found, it adds a small amount of monotonically decreasing noise to lx.
maybe_dither_lx(lx, pert = 1e-04)
lx |
numeric. vector of the lifetable survivorship. |
pert |
numeric scalar. The maximum size of the perturbation, default value of 0.0001 |
This function is here for robustness, as this situation often occurs in lifetables with a radix of 100000 and integer expressed output, especially around closeout ages. This perturbation is only applied if needed. The perturbation has a trivial effect of estimated quantile ages along most of the age range. The argument pert should be a small positive amount.
a vector of lx, either perturbed or not.
lx <- 10:0 / 10
age <- 0:10
all(maybe_dither_lx(lx) == lx)
lx2 <- c(10,9,8,7,7,5,4,3,2,1,0) / 10
lx2 - maybe_dither_lx(lx2)
lx3 <- c(10:2,0,0)
lx3 - maybe_dither_lx(lx3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.