interp_lc_lim: Lee-Carter method with limited data.

View source: R/interp_lc_lim.R

interp_lc_limR Documentation

Lee-Carter method with limited data.

Description

Given a data frame with 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(
  input = NULL,
  dates_out = dates_in,
  Single = FALSE,
  dates_e0 = NULL,
  e0_Males = NULL,
  e0_Females = NULL,
  prev_divergence = FALSE,
  OAG = TRUE,
  verbose = TRUE,
  SVD = FALSE,
  ...
)

Arguments

input

data.frame with cols: Date, Sex, Age, nMx (opt), nqx (opt), lx (opt)

dates_out

numeric. Vector of decimal years to interpolate or extrapolate.

Single

logical. Whether or not the lifetable output is by single ages.

dates_e0

numeric. Vector of decimal years where "e_0" should be fitted when apply method.

e0_Males

numeric. Vector of life expectancy by year to be fitted. Same length than "dates_e0".

e0_Females

numeric. Vector of life expectancy by year to be fitted. Same length than "dates_e0".

prev_divergence

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

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.

Value

List with:

  • Interpolated/extrapolated lifetables 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 estimated Lee-Carter parameters for each sex:

    • 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

# 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(input = mA_swe, dates_out = dates_out, OAG = FALSE)$lt_hat

## Not run: 
lc_lim_data %>% 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)

# with simple ages as output
lc_lim_data_single <- interp_lc_lim(input = mA_swe, dates_out = dates_out, OAG = FALSE,
                                    Single = TRUE)$lt_hat

## Not run: 
lc_lim_data_single %>% 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)

# Avoiding cross-over between sex.
lc_lim_nondiv <- interp_lc_lim(input = mA_swe, dates_out = dates_out, OAG = FALSE,
                               prev_divergence = TRUE)$lt_hat
## Not run: 
lc_lim_nondiv %>% 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)

# Fitting information about e0 in Sweden for past years.
lc_lim_fite0 <- interp_lc_lim(input = mA_swe, dates_out = dates_out, OAG = FALSE,
                              dates_e0 = unique(e0_swe$Date),
                              e0_Males = e0_swe$e0[e0_swe$Sex=="m"], 
                              e0_Females = e0_swe$e0[e0_swe$Sex=="f"])$lt_hat
## Not run:                                
ggplot() + 
  geom_point(data = e0_swe, aes(Date,e0,col=factor(Sex)))+
  geom_line(data = lc_lim_fite0[lc_lim_fite0$Age==0,], aes(Date,ex,col=factor(Sex)))+
  labs(color = "Sex")+
  theme_classic()

## End(Not run)

# smooth and/or extend open age group, in this case input is for 80+, and chosen law is Makeham.
lc_lim_extOAg <- interp_lc_lim(input = mA_swe[mA_swe$Age<=80,], dates_out = dates_out,
                               OAG = FALSE,
                               OAnew=100,
                               extrapLaw = "makeham")$lt_hat
## Not run: 
ggplot() + 
  geom_step(data = lc_lim_extOAg, aes(Age,nMx,col=factor(round(Date,1)))) +
  scale_y_log10() + scale_color_viridis_d() + theme_classic() + facet_wrap(~Sex)
  
## End(Not run)
#End

timriffe/DemoTools documentation built on Oct. 14, 2024, 12:53 p.m.