Gompertz#

class relife.Gompertz(shape=None, rate=None)[source]#

Gompertz lifetime distribution.

The Gompertz distribution is a 2-parameter distribution with \((c,\lambda)\). The probability density function is:

\[f(t) = c \lambda e^{\lambda t} e^{ -c \left( e^{\lambda t}-1 \right) }\]

where:

  • \(c > 0\), the shape parameter,

  • \(\lambda > 0\), the rate parameter,

  • \(t\geq 0\), the operating time, age, cycles, etc.

Parameters:
shapefloat, optional

shape parameter

ratefloat, optional

rate parameter

See also

regression.AFT

AFT regression

regression.ProportionalHazard

AFT regression

Methods

Survival functions

chf

Cumulative hazard function.

dhf

Derivative of the hazard function.

hf

Hazard function.

ichf

Inverse cumulative hazard function.

isf

Inverse survival function.

jac_chf

Jacobian of the cumulative hazard function.

jac_hf

Jacobian of the hazard function.

mrl

Mean residual life.

sf

Survival function.

cdf

Cumulative distribution function.

pdf

Probability density function.

ppf

Percent point function.

Statistics

mean

Mean of the distribution.

median

Median of the distribution.

moment

n-th order moment of the distribution.

var

Variance.

Other methods

copy

Copy current instance.

fit

Estimation of lifetime model parameters with respect to lifetime data.

jac_cdf

Jacobian of the parametric cumulative distribution function with respect to params.

jac_pdf

Jacobian of the parametric probability density function with respect to params.

jac_sf

Jacobian of the parametric survival function with respect to params.

ls_integrate

Lebesgue-Stieltjes integration.

rvs

Random variable sampling.

Attributes

nb_params

Number of parameters.

params

Parameters values.

params_names

Parameters names.

plot

Plot

fitting_results

cdf(time)#

Cumulative distribution function.

The survival function of the distribution

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Cumulative distribution function values at each given time.

chf(time)[source]#

Cumulative hazard function.

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Cumulative hazard values at each given time.

Notes

The cumulative hazard function is the integral of the hazard function.

copy()#

Copy current instance.

Returns:
An independant copied instance.
dhf(time)[source]#

Derivative of the hazard function.

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

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)[source]#

Hazard function.

The hazard function of the distribution

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Hazard values at each given time.

ichf(cumulative_hazard_rate)[source]#

Inverse cumulative hazard function.

Parameters:
Cumulative hazard ratefloat or ndarray, shape (n, ) or (m, n)

Cumulative hazard rate values. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Inverse cumulative hazard values, i.e. time.

isf(probability)#

Inverse survival function.

The survival function of the distribution

Parameters:
probabilityfloat or ndarray, shape (n, ) or (m, n)

Probability values. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Complement quantile corresponding to probability.

jac_cdf(time)#

Jacobian of the parametric cumulative distribution function with respect to params.

jac_chf(time)[source]#

Jacobian of the cumulative hazard function.

Parameters:
Elapsed timefloat or ndarray, shape (n, ) or (m, n)

Probability values. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Jacobian values, here gradient values at each given time.

jac_hf(time)[source]#

Jacobian of the hazard function.

Parameters:
Elapsed timefloat or ndarray, shape (n, ) or (m, n)

Probability values. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Jacobian values, here gradient values at each given time.

jac_pdf(time)#

Jacobian of the parametric probability density function with respect to params.

jac_sf(time)#

Jacobian of the parametric survival function with respect to params.

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()[source]#

Mean of the distribution.

Returns:
ndarray of shape (0,)

Mean value.

Notes

The mean of a distribution is the moment of the first order.

median()#

Median of the distribution.

Returns:
ndarray of shape (0,)

Median value.

moment(n)#

n-th order moment of the distribution.

Parameters:
nint

Order of the moment, at least 1.

Returns:
ndarray of shape (0, )

n-th order moment of the distribution.

mrl(time)[source]#

Mean residual life.

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Mean residual life values.

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)#

Probability density function.

The probability density function of the distribution

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

The probability density function evaluated at each given time.

property plot#

Plot

ppf(probability)#

Percent point function.

The percent point function of the distribution. It corresponds to the inverse of the cumulative distribution function

Parameters:
probabilityfloat or ndarray, shape (n, ) or (m, n)

Probability values. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Quantile corresponding to probability.

rvs(*, size=1, seed=None)#

Random variable sampling.

Parameters:
sizeint, default 1

Sized of the generated sample.

seedint, default None

Random seed.

Returns:
ndarray of shape (size, )

Sample of random lifetimes.

sf(time)#

Survival function.

The survival function of the distribution

Parameters:
timefloat or ndarray, shape (n, ) or (m, n)

Elapsed time. If the given shape is (n, ), one asset and n points of measure are considered To consider m assets with respectively n points of measure, pass an array of shape (m, n).

Returns:
ndarray of shape (), (n, ) or (m, n)

Survival function values at each given time.

var(*args)#

Variance.

Parameters:
*argsvariadic arguments required by the function
Returns:
ndarray of shape (0,)

Variance value.