LifetimeModel#
- class relife.model.LifetimeModel[source]#
Base class to create a lifetime model.
A lifetime model is an object that can answer to traditional lifetime probability functions (
sf
,hf
etc.) and other common probabilitu functions (pdf
,cdf
, etc.).Methods
Cumulative distribution function.
Cumulative hazard function.
Hazard function.
Inverse cumulative hazard function.
Inverse survival function.
Lebesgue-Stieltjes integration.
Mean.
Median
n-th order moment
Mean residual life.
Probability density function.
Percent point function.
Random variable sampling.
Survival function.
Variance.
Attributes
Plot
- cdf(time, *args)[source]#
Cumulative distribution function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Cumulative distribution function values at each given time.
- abstract chf(time, *args)[source]#
Cumulative hazard function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Cumulative hazard values at each given time.
- abstract hf(time, *args)[source]#
Hazard function.
The hazard function of the distribution
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Hazard values at each given time.
- ichf(cumulative_hazard_rate, *args)[source]#
Inverse cumulative hazard function.
- Parameters:
- Cumulative hazard ratefloat or ndarray, shape (n, ) or (m, n)
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Inverse cumulative hazard values, i.e. time.
- isf(probability, *args)[source]#
Inverse survival function.
- Parameters:
- probabilityfloat or ndarray, shape (n, ) or (m, n)
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Complement quantile corresponding to probability.
- ls_integrate(func, a, b, *args, deg=100)[source]#
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(*args)[source]#
Mean.
- Parameters:
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (0,)
Mean value.
- median(*args)[source]#
Median
- Parameters:
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (0,)
Median value.
- moment(n, *args)[source]#
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, *args)[source]#
Mean residual life.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Mean residual life values.
- abstract pdf(time, *args)[source]#
Probability density function.
- Parameters:
- timefloat or ndarray, shape (n, ) or (m, n)
Elapsed time.
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
The probability density function evaluated at each given time.
- property plot#
Plot
- ppf(probability, *args)[source]#
Percent point function.
- Parameters:
- probabilityfloat or ndarray, shape (n, ) or (m, n)
- *argsvariadic arguments required by the function
- Returns:
- ndarray of shape (), (n, ) or (m, n)
Quantile corresponding to probability.
- rvs(*args, size=1, seed=None)[source]#
Random variable sampling.
- Parameters:
- *argsvariadic arguments required by the function
- sizeint, default 1
Sized of the generated sample.
- seedint, default None
Random seed.
- Returns:
- ndarray of shape (size, )
Sample of random lifetimes.