Package 'reslife'

Title: 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>.
Authors: Andrew Crawford [cre, aut], Zekai Wang [aut], Ka Lok Lee [aut]
Maintainer: Andrew Crawford <[email protected]>
License: GPL (>= 3)
Version: 0.2.1
Built: 2025-01-31 03:54:41 UTC
Source: https://github.com/an-crawford/reslife

Help Index


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 flexsurvreg() object. Contains an option to supply new data and returns the output as a vector.

Usage

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

Arguments

obj

Name of a flexsurvreg() object from which data is extracted.

life

Value at which the user wants to calculate residual life. Must be a scalar.

p

percentile for percentile residual life, default is .5

type

can be 'mean', 'median', 'percentile', or 'all'. Default is 'mean'.

newdata

a data frame containing new data values to calculate residual life for. Default is a blank data frame.

Value

A vector of residual life 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

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

fitg2 <- flexsurv::flexsurvreg(formula = Surv(futime, fustat) ~ age,
data = ovarian, dist="gengamma")
df_new = data.frame(age = 12)
reslifefsr(obj = fitg2, life = 3, type = 'median', newdata = df_new)