AFT#
- class relife.AFT(baseline, coef=(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.
- Parameters:
- baselineParametricLifetimeModel
Any parametric lifetime model to serve as the baseline.
- coeftuple of floats (values can be None), optional
Coefficients values of the covariate effects.
References
[1]Kalbfleisch, J. D., & Prentice, R. L. (2011). The statistical analysis of failure time data. John Wiley & Sons.
Methods
Survival functions
Cumulative hazard function.
Derivative of the hazard function.
Hazard function.
Inverse cumulative hazard function.
Inverse survival function.
Jacobian of the cumulative hazard function.
Jacobian of the hazard function.
Mean residual life.
Survival function.
Cumulative distribution function.
Probability density function.
Percent point function (inverse of cdf).
Statistics
Mean of the distribution.
Median of the distribution.
n-th order moment
Variance of the distribution.
Other methods
Copy current instance.
Estimation of lifetime model parameters with respect to lifetime data.
Jacobian of the cumulative distribution function.
Jacobian of the probability density function.
Jacobian of the survival function
Lebesgue-Stieltjes integration.
Random variates.
Attributes
Number of parameters.
Parameters values.
Parameters names.
Plot
fitting_results
- cdf(time, covar, *args)#
Cumulative distribution function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Cumulative probabilities at each given time.
- chf(time, covar, *args)[source]#
Cumulative hazard function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Cumulative hazard values at each given time.
- copy()#
Copy current instance.
- Returns:
- An independant copied instance.
- dhf(time, covar, *args)[source]#
Derivative of the hazard function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Derivative values with respect to time.
- fit(time, event=None, entry=None, departure=None, model_args=(), inplace=False, **kwargs)#
Estimation of lifetime model parameters with respect to lifetime data.
- Parameters:
- timendarray (1d or 2d)
Observed lifetime values.
- eventndarray of boolean values (1d), default is None
Boolean indicators tagging lifetime values as right censored or complete.
- entryndarray of float (1d), default is None
Left truncations applied to lifetime values.
- departurendarray of float (1d), default is None
Right truncations applied to lifetime values.
- model_argstuple of ndarray, default is None
Other arguments needed by the lifetime model.
- inplaceboolean, default is True
If true, parameters of the lifetime model will be replaced by estimated parameters.
- **kwargs
- 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:
- ndarray of float
Estimated parameters.
Notes
Supported lifetime observations format is either 1d-array or 2d-array. 2d-array is more advanced format that allows to pass other information as left-censored or interval-censored values. In this case, event is not needed as 2d-array encodes right-censored values by itself.
- hf(time, covar, *args)[source]#
Hazard function.
The hazard function of the regression.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Hazard values at each given time.
Notes
time, covar, and any *args arrays must be broadcastable.
- ichf(cumulative_hazard_rate, covar, *args)[source]#
Inverse cumulative hazard function.
- Parameters:
- cumulative_hazard_ratefloat or ndarray, shape (n, ) or (m, n)
Cumulative hazard rate values.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Inverse cumulative hazard values, i.e., time.
- isf(probability, covar, *args)#
Inverse survival function.
- Parameters:
- probabilityfloat or ndarray, shape (n, ) or (m, n)
Survival probabilities.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Time values corresponding to the given survival probabilities.
- jac_cdf(time, covar, *args)#
Jacobian of the cumulative distribution function.
Jacobian with respect to model parameters.
- Parameters:
- timenp.darray of shape (n, ) or (m, n)
Elapsed time.
- covarnp.darray of shape (k, ) or (m, k)
Covariates values.
- *argsvariable number of np.darray
Any other variables needed by the model
- Returns:
- np.ndarray of shape (n, nb_params) or (m, n, nb_params)
The values of the jacobian at each n points (eventually for m assets).
- jac_chf(time, covar, *args)[source]#
Jacobian of the cumulative hazard function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- np.ndarray of shape (n, nb_params) or (m, n, nb_params)
The values of the Jacobian at each n points (eventually for m assets).
- jac_hf(time, covar, *args)[source]#
Jacobian of the hazard function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- np.ndarray of shape (n, nb_params) or (m, n, nb_params)
The values of the Jacobian at each n points (eventually for m assets).
- jac_pdf(time, covar, *args)#
Jacobian of the probability density function.
Jacobian with respect to model parameters.
- Parameters:
- timenp.darray of shape (n, ) or (m, n)
Elapsed time.
- covarnp.darray of shape (k, ) or (m, k)
Covariates values.
- *argsvariable number of np.darray
Any other variables needed by the model
- Returns:
- np.ndarray of shape (n, nb_params) or (m, n, nb_params)
The values of the jacobian at each n points (eventually for m assets).
- jac_sf(time, covar, *args)#
Jacobian of the survival function
Jacobian with respect to model parameters.
- Parameters:
- timenp.darray of shape (n, ) or (m, n)
Elapsed time.
- covarnp.darray of shape (k, ) or (m, k)
Covariates values.
- *argsvariable number of np.darray
Any other variables needed by the model
- Returns:
- np.ndarray of shape (n, nb_params) or (m, n, nb_params)
The values of the jacobian at each n points (eventually for m assets).
- ls_integrate(func, a, b, *args, deg=100)#
Lebesgue-Stieltjes integration.
The Lebesgue-Stieljes intregration of a function with respect to the lifetime model taking into account the probability density function and jumps
The Lebesgue-Stieltjes integral is:
\[\int_a^b g(x) \mathrm{d}F(x) = \int_a^b g(x) f(x)\mathrm{d}x + \sum_i g(a_i) w_i\]where:
\(F\) is the cumulative distribution function,
\(f\) the probability density function of the lifetime model,
\(a_i\) and \(w_i\) are the points and weights of the jumps.
- Parameters:
- funccallable (in1 ndarray, out1 ndarray)
The callable must have only one ndarray object as argument and returns one ndarray object
- andarray (max dim of 2)
Lower bound(s) of integration.
- bndarray (max dim of 2)
Upper bound(s) of integration. If lower bound(s) is infinite, use np.inf as value.
- argsndarray (max dim of 2)
Other arguments needed by the lifetime model (eg. covariates)
- degint, default 100
Degree of the polynomials interpolation
- Returns:
- 2d ndarray
Lebesgue-Stieltjes integral of func with respect to cdf from a to b.
Notes
ls_integrate operations rely on arguments number of dimensions passed in a, b, *args or any other variable referenced in func. Because func callable is not easy to inspect, either one must specify the maximum number of dimensions used (0, 1 or 2), or ls_integrate converts all these objects to 2d-array. Currently, the second option is prefered. That’s why, returns are always 2d-array.
- mean(covar, *args)#
Mean of the distribution.
- Parameters:
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- np.ndarray
Mean values.
- median(covar, *args)#
Median of the distribution.
- Parameters:
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- np.ndarray
Median values.
- moment(n, *args)#
n-th order moment
- Parameters:
- norder of the moment, at least 1.
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (0, )
n-th order moment.
- mrl(time, covar, *args)#
Mean residual life.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Mean residual life values at each given time.
- property nb_params#
Number of parameters.
- Returns:
- int
Number of parameters.
- property params#
Parameters values.
- Returns:
- ndarray
Parameters values of the model
Notes
If parameter values are not set, they are encoded as np.nan value.
Parameters can be by manually setting`params` through its setter, fitting the model if fit exists or by specifying all parameters values when the model object is initialized.
- 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, *args)#
Probability density function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Probability densities at each given time.
- property plot#
Plot
- ppf(probability, covar, *args)#
Percent point function (inverse of cdf).
- Parameters:
- probabilityfloat or ndarray, shape (n, ) or (m, n)
Cumulative probabilities.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Time values corresponding to the given cumulative probabilities.
- rvs(covar, *args, size=1, seed=None)#
Random variates.
- Parameters:
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- sizeint, optional
Number of random variates to generate.
- seedint, optional
Seed for random number generator.
- Returns:
- np.ndarray
Random variates.
- sf(time, covar, *args)#
Survival function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Survival probabilities at each given time.
- var(covar, *args)#
Variance of the distribution.
- Parameters:
- covarnp.ndarray of shape (k, ) or (m, k)
Covariate values.
- *argsvariable number of np.ndarray
Any other variables needed by the model.
- Returns:
- np.ndarray
Variance values.