years: Compute one of the life years measures

View source: R/years.R

yearsR Documentation

Compute one of the life years measures


Provides an estimate for one of the following measures: years lost (Andersen, 2013), years lost/saved (Andersen, 2017), or life years difference (Manevski, Ruzic Gorenjec, Andersen, Pohar Perme, 2022).


  formula = formula(data),
  measure = c("yd", "yl2017", "yl2013"),
  ratetable = relsurv::slopop,
  var.estimator = c("none", "bootstrap", "greenwood"),
  B = 100,
  precision = 30,
  na.action = stats::na.omit, = 0.95,
  timefix = FALSE,
  is.boot = FALSE,
  first.boot = FALSE



a formula object, with the response as a Surv object on the left of a ~ operator, and, ~1 specified on the right.

NOTE: The follow-up time must be in days.


a data.frame in which to interpret the variables named in the formula.


choose which measure is used: 'yd' (life years difference; Manevski, Ruzic Gorenjec, Andersen, Pohar Perme, 2022), 'yl2017' (years lost/saved; Andersen 2017), 'yl2013' (years lost/saved; Andersen 2013).


a table of event rates, organized as a ratetable object, such as slopop.


an optional list to be used if the variables are not organized and named in the same way as in the ratetable object. See details below.


Choose the estimator for the variance ('none', 'bootstrap', 'greenwood'). Default is 'none'. The 'greenwood' option is possible only for measure='yd'.


if var.estimator is 'bootstrap'. The number of bootstrap replications. Default is 100.


precision for numerical integration of the population curve. Default is 30 (days). The value may be decreased to get a higher precision or increased to achieve a faster calculation.


specific times at which the curves should be reported.


a missing-data filter function. Default is na.omit.

the confidence level for a two-sided confidence interval. Default is 0.95.


the timefix argument in survival::survfit.formula. Default is FALSE.


if TRUE, the function years has been called during a bootstrap replication.


if TRUE, this is the first bootstrap replication.


The life years difference (measure='yd') is taken by default. If other measures are of interest, use the measure argument.

The follow-up time must be specified in days. The ratetable being used may have different variable names and formats than the user's data set, this is dealt with the rmap argument. For example, if age is in years in the data but in days in the ratetable object, age=age*365.241 should be used. The calendar year can be in any date format (date, Date and POSIXt are allowed), the date formats in the ratetable and in the data may differ.

Numerical integration is performed, argument precision is set with argument precision, which defaults to 30-day intervals for intergration. For higher accuracy take a smaller value (e.g. precision=1 makes the integration on a daily basis).

The observed curves are reported at event and censoring times. The population curves are reported at all times used for the numerical integration. Note that for the years lost (Andersen, 2013) measure, only the excess absolute risk is reported.


A list containing the years measure, the observed and population curves (or the excess curve for Andersen 2013). The values are given as separate data.frames through time. Times are given in days, all areas are given in years. For measure='yl2017' values are reported only at the last time point. Functions plot_f and plot_years can be then used for plotting.

See Also

plot_f, plot_years


# Estimate the life years difference for the rdata dataset.
mod <- years(Surv(time, cens)~1, data=rdata, measure='yd', ratetable=slopop,
             rmap=list(age=age*365.241), var.estimator = 'none')
# Plot the absolute risk (observed and population curve):
# Plot the life years difference estimate:

relsurv documentation built on Dec. 28, 2022, 2:25 a.m.

Related to years in relsurv...