ehrapy.tools.log_logistic_aft¶
- ehrapy.tools.log_logistic_aft(adata, duration_col, event_col=None, *, uns_key='log_logistic_aft', alpha=0.05, fit_intercept=True, penalizer=0.0, l1_ratio=0.0, model_ancillary=False, ancillary=None, show_progress=False, weights_col=None, robust=False, initial_point=None, entry_col=None, formula=None, fit_options=None)[source]¶
Fit the log logistic accelerated failure time regression for the survival function. The Log-Logistic Accelerated Failure Time (AFT) survival regression model is a powerful statistical tool employed in the analysis of time-to-event data. This model operates under the assumption that the logarithm of survival time adheres to a log-logistic distribution, offering a flexible framework for understanding the impact of covariates on survival times. By modeling survival time as a function of predictors, the Log-Logistic AFT model enables researchers to explore how specific factors influence the acceleration or deceleration of failure times, providing valuable insights into the underlying mechanisms driving event occurrence. The results will be stored in the .uns slot of the
AnnData
object under the key ‘log_logistic_aft’ unless specified otherwise in the uns_key parameter.See https://lifelines.readthedocs.io/en/latest/fitters/regression/LogLogisticAFTFitter.html
- Parameters:
adata (
AnnData
) – AnnData object.duration_col (
str
) – Name of the column in the AnnData objects that contains the subjects’ lifetimes.event_col (
str
|None
, default:None
) – The name of the column in the AnnData object that specifies whether the event has been observed, or censored. Column values are True if the event was observed, False if the event was lost (right-censored). If left None, all individuals are assumed to be uncensored.uns_key (
str
, default:'log_logistic_aft'
) – The key to use for the .uns slot in the AnnData object.alpha (
float
, default:0.05
) – The alpha value in the confidence intervals.fit_intercept (
bool
, default:True
) – Whether to fit an intercept term in the model.penalizer (
float
|ndarray
, default:0.0
) – Attach a penalty to the size of the coefficients during regression. This improves stability of the estimates and controls for high correlation between covariates.l1_ratio (
float
, default:0.0
) – Specify what ratio to assign to a L1 vs L2 penalty. Same as scikit-learn. See penalizer above.model_ancillary (
bool
, default:False
) – Set the model instance to always model the ancillary parameter with the supplied Dataframe. This is useful for grid-search optimization.ancillary (
bool
|DataFrame
|str
|None
, default:None
) – Choose to model the ancillary parameters. If None or False, explicitly do not fit the ancillary parameters using any covariates. If True, model the ancillary parameters with the same covariates asdf
. If DataFrame, provide covariates to model the ancillary parameters. Must be the same row count asdf
. If str, should be a formulashow_progress (
bool
, default:False
) – Since the fitter is iterative, show convergence diagnostics. Useful if convergence is failing.weights_col (
str
|None
, default:None
) – The name of the column in DataFrame that contains the weights for each subject.robust (
bool
, default:False
) – Compute the robust errors using the Huber sandwich estimator, aka Wei-Lin estimate. This does not handle ties, so if there are high number of ties, results may significantly differ.initial_point (default:
None
) – set the starting point for the iterative solver.entry_col (
str
|None
, default:None
) – Column denoting when a subject entered the study, i.e. left-truncation.formula (
str
|None
, default:None
) – Use an R-style formula for modeling the dataset. See formula syntax: https://matthewwardrop.github.io/formulaic/basic/grammar/ If a formula is not provided, all variables in the dataframe are used (minus those used for other purposes like event_col, etc.)fit_options (
dict
|None
, default:None
) – Additional keyword arguments to pass into the estimator.
- Return type:
- Returns:
Fitted LogLogisticAFTFitter.
Examples
>>> import ehrapy as ep >>> adata = ep.dt.mimic_2(encoded=False) >>> # Flip 'censor_fl' because 0 = death and 1 = censored >>> adata[:, ["censor_flg"]].X = np.where(adata[:, ["censor_flg"]].X == 0, 1, 0) >>> adata = adata[:, ["mort_day_censored", "censor_flg"]] >>> llf = ep.tl.log_logistic_aft(adata, duration_col="mort_day_censored", event_col="censor_flg")