Package {reslife}


Type: Package
Title: Calculate Mean Residual Life (MRL) and Related Values for Different Distributions
Version: 0.3.0
Date: 2026-11-06
Description: A pair of functions for calculating mean residual life (MRL) , median residual life, and percentile residual life using the outputs of either the 'flexsurv' package or parameters provided by the user. Input information about the distribution, the given 'life' value, the percentile, and the type of residual life, and the function will return your desired values. For the 'flexsurv' option, the function allows the user to input their own data for making predictions. This function is based on Jackson (2016) <doi:10.18637/jss.v070.i08>.
License: GPL (≥ 3)
Encoding: UTF-8
Depends: pracma, flexsurv, gsl
URL: https://github.com/an-crawford/reslife, https://kaloklee.github.io/reslife/
Suggests: knitr, rmarkdown, survival, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/roxygen2/version: 8.1.1
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-11-06 15:13:59 UTC; kartmanlmde
Author: Ka Lok Lee [cre, aut], Andrew Crawford [aut], Zekai Wang [aut]
Maintainer: Ka Lok Lee <kaloklee@gmail.com>
Repository: CRAN
Date/Publication: 2026-11-06 16:40:09 UTC

reslife: Calculate Mean Residual Life (MRL) and Related Values for Different Distributions

Description

A pair of functions for calculating mean residual life (MRL) , median residual life, and percentile residual life using the outputs of either the 'flexsurv' package or parameters provided by the user. Input information about the distribution, the given 'life' value, the percentile, and the type of residual life, and the function will return your desired values. For the 'flexsurv' option, the function allows the user to input their own data for making predictions. This function is based on Jackson (2016) doi:10.18637/jss.v070.i08.

Author(s)

Maintainer: Andrew Crawford atcrawford18@gmail.com

Authors:

See Also

Useful links:


Calculating Residual Life Values

Description

Calculates residual life values over a range of values. Allows the user to specify the distribution and the parameters.

Usage

residlife(values, distribution, parameters, p = 0.5, type = "mean")

Arguments

values

Range of values over which residual life is calculated.Usually given as a vector.

distribution

Name of the distribution. Needs to be one of 'weibull', 'gompertz', 'gamma', 'gengamma.orig', 'exponential', 'lnorm', or 'llogis', 'genf', or 'genf.orig'.

parameters

Parameters of the survival function. Needs to be inputted in order as a vector, with the name of the parameter included.

p

Percentile at which to calculate residual life. Default is .5.

type

Type of residual life outputted. Must be "mean", "median", "percentile", or "all". Default is "mean".

Value

The residual life for a specified sequence of values.

References

Jackson CH (2016). “flexsurv: a platform for parametric survival modeling in R.” Journal of statistical software, 70.

Poynor V (2010). “Bayesian inference for mean residual life functions in survival analysis.” Masters diss., University of California, Santa Cruz.

Prentice RL (1975). “Discrimination among some parametric models.” Biometrika, 62(3), 607–614.

Stacy EW (1962). “A generalization of the gamma distribution.” The Annals of mathematical statistics, pp. 1187–1192

Examples

residlife(values = 0:60, distribution= 'weibull', parameters = c(shape = 1.2, scale = 3))
residlife(values = 15:35, distribution= 'gamma', parameters =  c(shape = 1.2, rate =  1.7),
p = .25, type ='all')


Calculate Residual Life Values Using a flexsurvreg() Object

Description

Calculate residual life values using a fitted flexsurvreg object. Allows specifying covariate profiles via newdata.

Usage

reslifefsr(obj, life, p = 0.5, type = "mean", newdata = data.frame())

Arguments

obj

A fitted flexsurvreg object from package flexsurv.

life

Scalar numeric value of elapsed time at which to calculate residual life.

p

Percentile for quantile residual life. Default is 0.5.

type

Type of residual life to return: "mean", "median", "quantile", "percentile", or "all". Default is "mean".

newdata

A data frame containing covariate values to evaluate. Default is empty (evaluates baseline).

Value

A numeric vector (if type is "mean", "median", or "quantile") or a data frame (if type == "all"), with one row per covariate profile in newdata.

References

Jackson CH (2016). “flexsurv: a platform for parametric survival modeling in R.” Journal of statistical software, 70.

Poynor V (2010). “Bayesian inference for mean residual life functions in survival analysis.” Masters diss., University of California, Santa Cruz.

Prentice RL (1975). “Discrimination among some parametric models.” Biometrika, 62(3), 607–614.

Stacy EW (1962). “A generalization of the gamma distribution.” The Annals of mathematical statistics, pp. 1187–1192.

Examples

library(flexsurv)
fitg <- flexsurvreg(Surv(futime, fustat) ~ 1, data = ovarian, dist = "gengamma")
reslifefsr(obj = fitg, life = 6, p = 0.75, type = "all")

fitg2 <- flexsurvreg(Surv(futime, fustat) ~ age, data = ovarian, dist = "gengamma")
df_new <- data.frame(age = c(50, 65))
reslifefsr(obj = fitg2, life = 3, type = "median", newdata = df_new)