ProportionalHazard#
- class relife.lifetime_model.ProportionalHazard(baseline, coefficients=(None,))[source]#
Proportional Hazard regression.
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 [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_effectCovarEffect
The regression covariate effect.
See also
regression.AFT
Accelerated Failure Time regression.
References
[1]Sun, J. (2006). The statistical analysis of interval-censored failure time data (Vol. 3, No. 1). New York: springer.
Methods
The cumulative distribution function.
The cumulative hazard function.
The derivative of the hazard function.
Estimation of parameters.
The hazard function.
Inverse cumulative hazard function.
Inverse survival function.
The jacobian of the cumulative distribution function.
The jacobian of the cumulative hazard function.
The jacobian of the hazard function.
The jacobian of the probability density function.
The jacobian of the survival function.
Lebesgue-Stieltjes integration.
The mean.
The median.
n-th order moment
The mean residual life function.
The probability density function.
The percent point function.
Random variable sampling.
The survival function.
The variance.
- cdf(time, covar, *args)#
The cumulative distribution 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- chf(time, covar, *args)[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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- dhf(time, covar, *args)[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_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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- fit(time, covar, *args, event=None, entry=None, departure=None, **kwargs)#
Estimation of parameters.
- Parameters:
- timendarray (1d or 2d)
Observed lifetime 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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- 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.
- **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:
- Self
The current object with the estimated parameters setted inplace.
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]#
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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- ichf(cumulative_hazard_rate, covar, *args)[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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given cumulative hazard rate(s).
- isf(probability, covar, *args)#
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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given probability value(s).
- jac_cdf(time, covar, *args, asarray=False)#
The jacobian of the cumulative distribution 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- 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. Ifasarray
is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applyingnp.stack
on the output tuple whenasarray
is False.
- jac_chf(time, covar, *args, 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- 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. Ifasarray
is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applyingnp.stack
on the output tuple whenasarray
is False.
- jac_hf(time, covar, *args, 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- 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. Ifasarray
is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applyingnp.stack
on the output tuple whenasarray
is False.
- jac_pdf(time, covar, *args, 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- 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. Ifasarray
is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applyingnp.stack
on the output tuple whenasarray
is False.
- jac_sf(time, covar, *args, 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- 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. Ifasarray
is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applyingnp.stack
on the output tuple whenasarray
is False.
- ls_integrate(func, a, b, covar, *args, 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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- degint, default 10
Degree of the polynomials interpolation
- Returns:
- np.ndarray
Lebesgue-Stieltjes integral of func from a to b.
- mean(covar, *args)#
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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64
The mean value.
- median(covar, *args)#
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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64
The median value.
- moment(n, covar, *args)[source]#
n-th order moment
- Parameters:
- norder of the moment, at least 1.
- Returns:
- np.float64
n-th order moment.
- mrl(time, covar, *args)#
The mean residual life 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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- property nb_params#
Number of parameters.
- Returns:
- int
Number of parameters.
- property params#
Parameters values.
- Returns:
- ndarray
Parameters values of the core
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 core if fit exists or by specifying all parameters values when the core 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)#
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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- property plot#
Provides access to plotting functionality for this distribution.
- ppf(probability, covar, *args)#
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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given probability value(s).
Notes
The
ppf
is the inverse ofcdf()
.
- rvs(size, covar, *args, return_event=False, return_entry=False, seed=None)#
Random variable sampling.
- Parameters:
- sizeint, (int,) or (int, int)
Size of the generated sample. If size is
n
or(n,)
, n samples are generated. If size is(m,n)
, a 2d array of samples is generated.- return_eventbool, default is False
If True, returns event indicators along with the sample time values.
- random_entrybool, default is False
If True, returns corresponding entry values of the sample time values.
- seedoptional int, default is None
Random seed used to fix random sampling.
- Returns:
- float, ndarray or tuple of float or ndarray
The sample values. If either
return_event
orrandom_entry
is True, returns a tuple containing the time values followed by event values, entry values or both.
- sf(time, covar, *args)#
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)
- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64 or np.ndarray
Function values at each given time(s).
- var(covar, *args)#
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)
.- *argsfloat or np.ndarray
Additional arguments needed by the model.
- Returns:
- np.float64
The variance value.