AcceleratedFailureTime#

class relife.lifetime_model.AcceleratedFailureTime(baseline, coefficients=(None,))[source]#

Accelerated failure time regression.

The cumulative hazard function \(H\) is linked to the multiplier function \(g\) by the relation:

\[H(t, x) = H_0\left(\dfrac{t}{g(\beta, x)}\right) = H_0(t e^{- \beta \cdot x})\]

where \(x\) is a vector of covariates, \(\beta\) is the coefficient vector of the effect of covariates, \(H_0\) is the baseline cumulative hazard function [1].


Parameters:
baselineFittableParametricLifetimeModel

Any lifetime model that can be fitted.

coefficientstuple of floats (values can be None), default is (None,)

Coefficients values of the covariate effects.

Attributes:
baselineFittableParametricLifetimeModel

The regression baseline model (lifetime model).

covar_effect_CovarEffect

The regression covariate effect.

fitting_resultsFittingResults, default is None

An object containing fitting results (AIC, BIC, etc.). If the model is not fitted, the value is None.

coefficients

Coefficients of the regression.

nb_params

Number of parameters.

params

Parameters values.

params_names

Parameters names.

plot

Provides access to plotting functionnalities

See also

regression.ProportionalHazard

proportional hazard regression

References

[1]

Kalbfleisch, J. D., & Prentice, R. L. (2011). The statistical analysis of failure time data. John Wiley & Sons.

Methods

cdf

The cumulative density function.

chf

The cumulative hazard function.

dhf

The derivative of the hazard function.

fit

Estimation of the regression parameters from lifetime data.

fit_from_interval_censored_lifetimes

Estimation of the regression parameters from interval censored lifetime data.

freeze

Freeze regression covar.

hf

The hazard function.

ichf

Inverse cumulative hazard function.

isf

The inverse survival function.

jac_cdf

The jacobian of the cumulative density function.

jac_chf

The jacobian of the cumulative hazard function.

jac_hf

The jacobian of the hazard function.

jac_pdf

The jacobian of the probability density function.

jac_sf

The jacobian of the survival function.

ls_integrate

Lebesgue-Stieltjes integration.

mean

The mean.

median

The median.

moment

n-th order moment

mrl

The mean residual life.

pdf

The probility density function.

ppf

The percent point function.

rvs

Random variable sampling.

sf

The survival function.

var

The variance.

cdf(time, covar)#

The cumulative density function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

chf(time, covar)[source]#

The cumulative hazard function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

property coefficients#

Coefficients of the regression.

Returns:
ndarray
dhf(time, covar)[source]#

The derivative of the hazard function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

fit(time, covar, event=None, entry=None, optimizer_options=None)#

Estimation of the regression parameters from lifetime data.

Parameters:
time1d array

Observed lifetime values.

covar1d or 2d array

Covariates values. 1d array is valid if the regression has one coefficient. Otherwise it must be an 2d array of shape (m, nb_coef).

event1d array of bool, default is None

Boolean indicators tagging lifetime values as right censored or complete.

entry1d array, default is None

Left truncations applied to lifetime values.

optimizer_optionsdict, default is None
Extra arguments used by scipy.minimize. Default values are:
  • method : “L-BFGS-B”

  • contraints : ()

  • tol : None

  • callback : None

  • options : None

  • bounds : self.params_bounds

  • x0 : self.init_params

Returns:
Self

The current object with the estimated parameters setted inplace.

fit_from_interval_censored_lifetimes(time_inf, time_sup, covar, entry=None, optimizer_options=None)#

Estimation of the regression parameters from interval censored lifetime data.

Parameters:
time_inf1d array

Observed lifetime lower bounds.

time_sup1d array

Observed lifetime upper bounds.

covar1d or 2d array

Covariates values. 1d array is valid if the regression has one coefficient. Otherwise it must be an 2d array of shape (m, nb_coef).

entry1d array, default is None

Left truncations applied to lifetime values.

optimizer_optionsdict, default is None
Extra arguments used by scipy.minimize. Default values are:
  • method : “L-BFGS-B”

  • contraints : ()

  • tol : None

  • callback : None

  • options : None

  • bounds : self.params_bounds

  • x0 : self.init_params

Returns:
Self

The current object with the estimated parameters setted inplace.

Notes

Where time_inf == time_sup, lifetimes are complete.

freeze(covar)#

Freeze regression covar.

Parameters:
covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
FrozenParametricModel
hf(time, covar)[source]#

The hazard function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

ichf(cumulative_hazard_rate, covar)[source]#

Inverse cumulative hazard function.

Parameters:
cumulative_hazard_ratefloat or np.ndarray

Cumulative hazard rate value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray

Function values at each given cumulative hazard rate(s).

isf(probability, covar)#

The inverse survival function.

Parameters:
probabilityfloat or np.ndarray

Probability value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray

Function values at each given probability value(s).

jac_cdf(time, covar, asarray=False)#

The jacobian of the cumulative density function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

asarraybool, default is False
Returns:
np.float64, np.ndarray or tuple of np.float64 or np.ndarray

The derivatives with respect to each parameter. If asarray is False, the function returns a tuple containing the same number of elements as parameters. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_chf(time, covar, asarray=False)[source]#

The jacobian of the cumulative hazard function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

asarraybool, default is False
Returns:
np.float64, np.ndarray or tuple of np.float64 or np.ndarray

The derivatives with respect to each parameter. If asarray is False, the function returns a tuple containing the same number of elements as parameters. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_hf(time, covar, asarray=False)[source]#

The jacobian of the hazard function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

asarraybool, default is False
Returns:
np.float64, np.ndarray or tuple of np.float64 or np.ndarray

The derivatives with respect to each parameter. If asarray is False, the function returns a tuple containing the same number of elements as parameters. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_pdf(time, covar, asarray=False)#

The jacobian of the probability density function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

asarraybool, default is False
Returns:
np.float64, np.ndarray or tuple of np.float64 or np.ndarray

The derivatives with respect to each parameter. If asarray is False, the function returns a tuple containing the same number of elements as parameters. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_sf(time, covar, asarray=False)#

The jacobian of the survival function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n_values,) or (n_assets, n_values).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

asarraybool, default is False
Returns:
np.float64, np.ndarray or tuple of np.float64 or np.ndarray

The derivatives with respect to each parameter. If asarray is False, the function returns a tuple containing the same number of elements as parameters. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

ls_integrate(func, a, b, covar, deg=10)#

Lebesgue-Stieltjes integration.

Parameters:
funccallable (in1 ndarray , out1 ndarray)

The callable must have only one ndarray object as argument and one ndarray object as output

andarray (maximum number of dimension is 2)

Lower bound(s) of integration.

bndarray (maximum number of dimension is 2)

Upper bound(s) of integration. If lower bound(s) is infinite, use np.inf as value.)

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

degint, default 10

Degree of the polynomials interpolation

Returns:
np.ndarray

Lebesgue-Stieltjes integral of func from a to b.

mean(covar)#

The mean.

Parameters:
covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray
median(covar)#

The median.

Parameters:
covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray
moment(n, covar)#

n-th order moment

Parameters:
nint

order of the moment, at least 1.

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray
mrl(time, covar)#

The mean residual life.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

property nb_coef#

Number of coefficients.

Returns:
int
property nb_params#

Number of parameters.

Returns:
int

Number of parameters.

property params#

Parameters values.

Returns:
ndarray

Parameters values

Notes

If parameter values are not set, they are encoded as np.nan value.

property params_names#

Parameters names.

Returns:
list of str

Parameters names

Notes

Parameters values can be requested (a.k.a. get) by their name at instance level.

pdf(time, covar)#

The probility density function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

property plot#

Provides access to plotting functionnalities

ppf(probability, covar)#

The percent point function.

Parameters:
probabilityfloat or np.ndarray

Probability value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray

Function values at each given probability value(s).

rvs(size, covar, nb_assets=None, return_event=False, return_entry=False, seed=None)#

Random variable sampling.

Parameters:
sizeint

Size of the generated sample.

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

nb_assetsint, optional

If nb_assets is not None, 2d arrays of samples are generated.

return_eventbool, default is False

If True, returns event indicators along with the sample time values.

return_entrybool, default is False

If True, returns corresponding entry values of the sample time values.

seedoptional int, np.random.BitGenerator, np.random.Generator, np.random.RandomState, default is None

If int or BitGenerator, seed for random number generator. If np.random.RandomState or np.random.Generator, use as given.

Returns:
float, ndarray or tuple of float or ndarray

The sample values. If either return_event or random_entry is True, returns a tuple containing the time values followed by event values, entry values or both.

sf(time, covar)#

The survival function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef)

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

var(covar)#

The variance.

Parameters:
covarfloat or np.ndarray

Covariates values. float can only be valid if the regression has one coefficients. Otherwise it must be a ndarray of shape (nb_coef,) or (m, nb_coef).

Returns:
np.float64 or np.ndarray