Gompertz#

class relife.lifetime_model.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

Attributes:
fitting_resultsFittingResults, default is None

An object containing fitting results (AIC, BIC, etc.). If the model is not fitted, the value is None.

nb_params

Number of parameters.

params

Parameters values.

params_names

Parameters names.

plot

Provides access to plotting functionnalities

shape

Get the current shape value.

rate

Get the current rate value.

Methods

cdf

The cumulative density function.

chf

The cumulative hazard function.

dhf

The derivate of the hazard function.

fit

Estimation of the distribution parameters from lifetime data.

hf

The hazard function.

ichf

Inverse cumulative hazard function.

isf

The inverse survival function.

jac_cdf

The jacobian of the cumulative density function.

jac_chf

The jacobian of the cumulative hazard function.

jac_hf

The jacobian of the hazard function.

jac_pdf

The jacobian of the probability density function.

jac_sf

The jacobian of the survival function.

ls_integrate

Lebesgue-Stieltjes integration.

mean

The mean of the distribution.

median

The median.

moment

n-th order moment

mrl

The mean residual life function.

pdf

The probability density function.

ppf

The percent point function.

rvs

Random variable sampling.

sf

The survival function.

var

The variance of the distribution.

cdf(time)#

The cumulative density function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

chf(time)[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,) or (m, n).

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

dhf(time)[source]#

The derivate 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,) or (m, n).

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

fit(time, *, event=None, entry=None, departure=None, **options)#

Estimation of the distribution parameters from 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.

**options
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)[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,) or (m, n).

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

ichf(cumulative_hazard_rate)[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).

Returns:
Function values at each given cumulative hazard rate(s).
isf(probability)#

The 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).

Returns:
np.float64 or np.ndarray

Function values at each given probability value(s).

jac_cdf(time, *, asarray=False)#

The jacobian of the cumulative density function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

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. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_chf(time, *, 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,) or (m, n).

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. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_hf(time, *, 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,) or (m, n).

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. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_pdf(time, *, 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,) or (m, n).

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. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

jac_sf(time, *, 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,) or (m, n).

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. If asarray is True, the function returns an ndarray whose first dimension equals the number of parameters. This output is equivalent to applying np.stack on the output tuple when asarray is False.

ls_integrate(func, a, b, 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.)

degint, default 10

Degree of the polynomials interpolation

Returns:
np.ndarray

Lebesgue-Stieltjes integral of func from a to b.

mean()[source]#

The mean of the distribution.

Returns:
np.float64
median()#

The median.

Returns:
np.float64
moment(n)#

n-th order moment

Parameters:
nint

order of the moment, at least 1.

Returns:
np.float64
mrl(time)[source]#

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,) or (m, n).

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

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,) or (m, n).

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

property plot#

Provides access to plotting functionnalities

ppf(probability)#

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

Returns:
np.float64 or np.ndarray

Function values at each given probability value(s).

property rate#

Get the current rate value.

Returns:
float
rvs(size, *, nb_assets=None, return_event=False, return_entry=False, seed=None)#

Random variable sampling.

Parameters:
sizeint

Size of the generated sample.

nb_assetsint, optional

If nb_assets is not None, 2d arrays of samples are generated.

return_eventbool, default is False

If True, returns event indicators along with the sample time values.

return_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 or return_entry is True, returns a tuple containing the time values followed by event values, entry values or both.

sf(time)#

The survival function.

Parameters:
timefloat or np.ndarray

Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).

Returns:
np.float64 or np.ndarray

Function values at each given time(s).

property shape#

Get the current shape value.

Returns:
float
var()[source]#

The variance of the distribution.

Returns:
np.float64