relife.regression.ProportionalHazards
relife.regression.ProportionalHazards¶
- class relife.regression.ProportionalHazards(baseline: relife.parametric.ParametricLifetimeModel, beta: Optional[numpy.ndarray] = None)[source]¶
Bases:
relife.regression.Regression
Parametric Proportional Hazards Regression Model.
The cumulative hazard function \(H\) is linked to the multiplier function \(g\) by the relation:
\[H(t, x) = g(\beta, x) H_0(t) = e^{\beta \cdot x} H_0(t)\]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.
References
- 1
Sun, J. (2006). The statistical analysis of interval-censored failure time data (Vol. 3, No. 1). New York: springer.
Methods
Cumulative distribution function.
Cumulative hazard function.
Fit the parametric survival regression model to lifetime data.
Hazard function (or hazard rate).
Inverse cumulative hazard function.
Inverse survival function.
Lebesgue-Stieltjes integration.
Mean of the distribution.
Median of the distribution.
N-th order moment of the distribution.
Mean residual life.
Probability density function.
Percent point function.
Random variable sampling.
Survival (or reliability) function of the lifetime model.
Support upper bound of the lifetime model.
Variance of the distribution.
Attributes
beta
Coefficients for the covariates.
Number of parameters.
Parameters of the hazard functions.
- cdf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Cumulative distribution function.
- Parameters
t (float or 1D array) – Elapsed time.
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
Cumulative distribution function at t with extra args .
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
- chf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Cumulative hazard function.
The cumulative hazard function is the integral of the hazard function.
- Parameters
t (float or 1D array) – Elapsed time.
*args (float or 2D array, optional) – Extra arguments required by the hazard function.
- Returns
Cumulative hazard function at t.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
- fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None, covar: Optional[numpy.ndarray] = None, args: numpy.ndarray = (), params0: Optional[numpy.ndarray] = None, method: Optional[str] = None, **kwargs) relife.regression.Regression ¶
Fit the parametric survival regression model to lifetime data.
- Parameters
time (1D array) – Array of time-to-event or durations.
event (1D array, optional) –
Array of event types coded as follows:
0 if observation ends before the event has occurred (right censoring)
1 if the event has occured
2 if observation starts after the event has occurred (left censoring)
by default the event has occured for each asset.
entry (1D array, optional) – Array of delayed entry times (left truncation), by default None.
covar (2D array) – Array of covariates.
args (float or 2D array, optional) – Extra arguments required by the baseline parametric lifetime model.
params0 (1D array, optional) – Initial guess, by default None.
method (str, optional) – Type of solver (see scipy.optimize.minimize documentation), by default None.
- Returns
Return the fitted regression as the current object.
- Return type
self
- hf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Hazard function (or hazard rate).
The hazard function is the derivative of the cumulative hazard function.
- Parameters
t (float or 1D array) – Elapsed time.
*args (float or 2D array, optional) – Extra arguments required by the hazard function.
- Returns
Hazard rate at t.
- Return type
float or 1D array
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
- ichf(v: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Inverse cumulative hazard function.
- Parameters
v (float or 1D array) – Cumulative hazard rate
*args (float or 2D array, optional) – Extra arguments required by the hazard function.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
- isf(p: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Inverse survival function.
- Parameters
p (float or 1D array) – Probability.
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
Complement quantile corresponding to p.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(p),)
- ls_integrate(func: Callable, a: numpy.ndarray, b: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100, q0: float = 0.0001) numpy.ndarray ¶
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.
- Parameters
func (Callable) – Function or method to integrate on interval [a,b] integrated with respect to the lifetime model.
a (float or 1D array) – Lower bound of integration.
b (float or 1D array) – Upper bound of integration (use numpy.inf for +infinity).
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
**kwargs (int or float) – Extra keyword arguments required for the Lebesgue-Stieljes integration.
- Returns
Lebesgue-Stieltjes integral of func with respect to cdf from a to b.
- Return type
float or ndarray
Notes
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.
- 1
Resnick, S. I. (1992). Adventures in stochastic processes. Springer Science & Business Media. p176.
- mean(*args: numpy.ndarray) numpy.ndarray ¶
Mean of the distribution.
The mean of a distribution is the moment of the first order.
- Parameters
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
Mean of the distribution.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
- median(*args: numpy.ndarray) numpy.ndarray ¶
Median of the distribution.
The median is the ppf evaluated at 0.5.
- Parameters
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
The median of the distribution.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
- moment(n: int, *args: numpy.ndarray) numpy.ndarray ¶
N-th order moment of the distribution.
The n-th order moment is the Lebegue-Stieljes integral of x**n with respect to the cdf.
- Parameters
n (int, n >=1) – Order of moment.
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
N-th order moment of the distribution.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
- mrl(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Mean residual life.
The mean residual life for an asset aged t is the mean of the lifetime distribution truncated at t on the interval [t,ub).
- Parameters
t (float or 1D array) – Age of the asset
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
The mean residual life of assets at age t.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),).
The mean residual life is:
\[\mu(t) = \dfrac{\int_t^{\infty} (x - t) \mathrm{d}F(x)}{S(t)}\]where \(F\) is the cumulative distribution function and \(S\) is the survival function.
- property n_params: int¶
Number of parameters.
- property params: numpy.ndarray¶
Parameters of the hazard functions.
- pdf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Probability density function.
- Parameters
t (float or 1D array) – Elapsed time.
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
The probability density function evaluated at t with extra arguments args.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
- ppf(p: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Percent point function.
The ppf is the inverse of cdf.
- Parameters
p (float or 1D array) – Probability.
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
Quantile corresponding to p.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(p),)
- rvs(*args: numpy.ndarray, size: int = 1, random_state: Optional[int] = None) numpy.ndarray ¶
Random variable sampling.
- Parameters
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
size (int, optional) – Size of sample, by default 1.
random_state (int, optional) – Random seed, by default None.
- Returns
Sample of random variates with shape[-1]=size.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (size,)
- sf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray ¶
Survival (or reliability) function of the lifetime model.
- Parameters
t (float or 1D array) – Elapsed time.
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
The survival function evaluated at t with extra arguments args.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
- support_upper_bound(*args: numpy.ndarray) float ¶
Support upper bound of the lifetime model.
- Parameters
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
The support upper bound of the lifetime model with respect to the extra arguments.
- Return type
float or ndarray
- var(*args: numpy.ndarray) numpy.ndarray ¶
Variance of the distribution.
- Parameters
*args (float or 2D array, optional) – Extra arguments required by the lifetime model.
- Returns
Variance of the distribution.
- Return type
float or ndarray
Notes
If args are of type ndarray, the arrays should be broadcastable with
shape[-1]=1
.The shape of the result will be:
np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)