View source: R/interp_lc_lim_group.R
interp_lc_lim_group | R Documentation |
Given a data frame with groups (country, region, sex), dates, sex and mortality data by age (rates, conditioned probabilities of death or survival function), this function interpolate/extrapolate life tables using the method for limited data suggested by Li et. al (2004) (at least three observed years).
interp_lc_lim_group(
input = NULL,
dates_out = NULL,
Single = FALSE,
input_e0 = NULL,
prev_divergence = FALSE,
weights = NULL,
OAG = TRUE,
verbose = TRUE,
SVD = FALSE,
...
)
input |
data.frame. Columns: id, Date, Sex, Age, nMx (opt), nqx (opt), lx (opt). The first column (id) can be a numeric index or character vector identifying each group. |
dates_out |
numeric. Vector of decimal years to interpolate or extrapolate. |
Single |
logical. Whether or not the lifetable output is by single ages. |
input_e0 |
data.frame with cols: id, Date, Sex and |
prev_divergence |
logical. Whether or not prevent divergence and sex crossover between groups. Default |
weights |
list. For |
OAG |
logical. Whether or not the last element of |
verbose |
logical. Default |
SVD |
logical. Use Singular Value Decomposition for estimate b and k or Maximum Likelihood Estimation. Default |
... |
Other arguments to be passed on to the |
Based on spreadsheet "Li_2018_Limited_Lee-Carter-v4.xlsm" from UN.
Useful for abridged or single ages, and allows output in both formats also.
One option is the use of non-divergent method for sex coherency (Li & Lee, 2005).
The other is the possibility of fitting "k"
to replicate "e_0"
at some given dates.
id
column in input
argument works for separate between groups. In case only one population/sex is given,
is recommended to give some group name to id
, if not the function will try to infer the case.
List with:
Lifetable in a data.frame with columns:
Date
numeric. Dates included in dates_out,
Sex
character. Male "m"
or female "f"
,
Age
integer. Lower bound of abridged age class,
'AgeInt“ integer. Age class widths.
nMx
numeric. Age-specific central death rates.
nAx
numeric. Average time spent in interval by those deceased in interval.
nqx
numeric. Age-specific conditional death probabilities.
lx
numeric. Lifetable survivorship
ndx
numeric. Lifetable deaths distribution.
nLx
numeric. Lifetable exposure.
Sx
numeric. Survivor ratios in uniform 5-year age groups.
Tx
numeric. Lifetable total years left to live above age x.
ex
numeric. Age-specific remaining life expectancy.
List with parameters estimated for each group:
kt
numeric time vector. Time trend in mortality level.
ax
numeric age vector. Average time of log(m_{x,t})
.
bx
numeric age vector. Pattern of change in response to kt
.
Draft Version
Li2005DemoTools \insertRefLi2004DemoTools
lt_abridged
# mortality rates from Sweden, for specific dates. Each sex a group.
mA_swe$id = c(rep("A",nrow(mA_swe)/2),
rep("B",nrow(mA_swe)/2))
# needs mortality rates in this dates:
dates_out <- as.Date(paste0(seq(1948,2018,5),"-07-01"))
# apply LC with limited data to extrap/interpolate
lc_lim_data <- interp_lc_lim_group(input = mA_swe, dates_out = dates_out)
## Not run:
lc_lim_data[["lt_hat"]] %>% ggplot(aes(Age,nMx,col=factor(round(Date,1)))) +
geom_step() + scale_color_viridis_d() +
scale_y_log10() + theme_classic() + facet_wrap(~Sex)
## End(Not run)
# avoid cross-over between groups
lc_lim_data <- interp_lc_lim_group(input = mA_swe, dates_out = dates_out,
prev_divergence = TRUE, weights=list(A=.4,B=.6))
## Not run:
lc_lim_data[["lt_hat"]] %>% ggplot(aes(Age,nMx,col=factor(round(Date,1)))) +
geom_step() + scale_color_viridis_d() +
scale_y_log10() + theme_classic() + facet_wrap(~id)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.