GeneralizedGammaRegressionFitter¶
- class lifelines.fitters.generalized_gamma_regression_fitter.GeneralizedGammaRegressionFitter(alpha: float = 0.05, penalizer: float | ndarray = 0.0, l1_ratio: float = 0.0, **kwargs)¶
This class implements a Generalized Gamma model for regression data. The model has parameterized form:
The survival function is:
\[\begin{split}S(t; x)=\left\{ \begin{array}{} 1-\Gamma_{RL}\left( \frac{1}{{{\lambda }^{2}}};\frac{{e}^{\lambda \left( \frac{\log(t)-\mu }{\sigma} \right)}}{\lambda ^{2}} \right) \textit{ if } \lambda> 0 \\ \Gamma_{RL}\left( \frac{1}{{{\lambda }^{2}}};\frac{{e}^{\lambda \left( \frac{\log(t)-\mu }{\sigma} \right)}}{\lambda ^{2}} \right) \textit{ if } \lambda \le 0 \\ \end{array} \right.\,\!\end{split}\]where \(\Gamma_{RL}\) is the regularized lower incomplete Gamma function, and \(\sigma = \sigma(x) = \exp(\alpha x^T), \lambda = \lambda(x) = \beta x^T, \mu = \mu(x) = \gamma x^T\).
This model has the Exponential, Weibull, Gamma and Log-Normal as sub-models, and thus can be used as a way to test which model to use:
When \(\lambda = 1\) and \(\sigma = 1\), then the data is Exponential.
When \(\lambda = 1\) then the data is Weibull.
When \(\sigma = \lambda\) then the data is Gamma.
When \(\lambda = 0\) then the data is Log-Normal.
When \(\lambda = -1\) then the data is Inverse-Weibull.
When \(-\sigma = \lambda\) then the data is Inverse-Gamma.
After calling the
.fit
method, you have access to properties like:cumulative_hazard_
,survival_function_
, A summary of the fit is available with the methodprint_summary()
.Important
The parameterization implemented has \(\log\sigma\), thus there is a ln_sigma_ in the output. Exponentiate this parameter to recover \(\sigma\).
Important
This model is experimental. It’s API may change in the future. Also, it’s convergence is not very stable.
- Parameters:
alpha (float, optional (default=0.05)) – the level in the confidence intervals.
penalizer (float or array, optional (default=0.0)) – the penalizer coefficient to the size of the coefficients. See l1_ratio. Must be equal to or greater than 0. Alternatively, penalizer is an array equal in size to the number of parameters, with penalty coefficients for specific variables. For example, penalizer=0.01 * np.ones(p) is the same as penalizer=0.01
Examples
from lifelines import GeneralizedGammaFitter from lifelines.datasets import load_waltons waltons = load_waltons() ggf = GeneralizedGammaFitter() ggf.fit(waltons['T'], waltons['E']) ggf.plot() ggf.summary
- cumulative_hazard_¶
The estimated cumulative hazard (with custom timeline if provided)
- Type:
DataFrame
- hazard_¶
The estimated hazard (with custom timeline if provided)
- Type:
DataFrame
- survival_function_¶
The estimated survival function (with custom timeline if provided)
- Type:
DataFrame
- cumulative_density_¶
The estimated cumulative density function (with custom timeline if provided)
- Type:
DataFrame
- density_¶
The estimated density function (PDF) (with custom timeline if provided)
- Type:
DataFrame
- variance_matrix_¶
The variance matrix of the coefficients
- Type:
DataFrame
- median_¶
The median time to event
- Type:
float
- lambda_¶
The fitted parameter in the model
- Type:
float
- rho_¶
The fitted parameter in the model
- Type:
float
- alpha_¶
The fitted parameter in the model
- Type:
float
- durations¶
The durations provided
- Type:
array
- event_observed¶
The event_observed variable provided
- Type:
array
- timeline¶
The time line to use for plotting and indexing
- Type:
array
- entry¶
The entry array provided, or None
- Type:
array or None