interp_lc_lim_group: Lee-Carter method with limited data for groups.

View source: R/interp_lc_lim_group.R

interp_lc_lim_groupR Documentation

Lee-Carter method with limited data for groups.

Description

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).

Usage

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,
  ...
)

Arguments

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 "e_0". This should be fitted when apply method.

prev_divergence

logical. Whether or not prevent divergence and sex crossover between groups. Default FALSE.

weights

list. For prev_divergence option. A double for each element of a list with names as id columns. Should sum up to 1. Default: same weight for each group.

OAG

logical. Whether or not the last element of nMx (or nqx or lx) is an open age group. Default TRUE.

verbose

logical. Default FALSE.

SVD

logical. Use Singular Value Decomposition for estimate b and k or Maximum Likelihood Estimation. Default FALSE for Maximum Likelihood Estimation.

...

Other arguments to be passed on to the lt_abridged function.

Details

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.

Value

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.

Note

Draft Version

References

\insertRef

Li2005DemoTools \insertRefLi2004DemoTools

See Also

lt_abridged

Examples

# 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)

timriffe/DemoTools documentation built on Jan. 28, 2024, 5:13 a.m.