ehrapy.tools.weibull_aft#
- ehrapy.tools.weibull_aft(adata, duration_col, event_col, *, uns_key='weibull_aft', alpha=0.05, fit_intercept=True, penalizer=0.0, l1_ratio=0.0, model_ancillary=True, ancillary=None, show_progress=False, weights_col=None, robust=False, initial_point=None, entry_col=None, formula=None, fit_options=None)[source]#
Fit the Weibull accelerated failure time regression for the survival function.
The Weibull Accelerated Failure Time (AFT) survival regression model is a statistical method used to analyze time-to-event data, where the underlying assumption is that the logarithm of survival time follows a Weibull distribution. It models the survival time as an exponential function of the predictors, assuming a specific shape parameter for the distribution and allowing for accelerated or decelerated failure times based on the covariates. The results will be stored in the .uns slot of the
AnnDataobject under the key ‘weibull_aft’ unless specified otherwise in the uns_key parameter.See https://lifelines.readthedocs.io/en/latest/fitters/regression/WeibullAFTFitter.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) – 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:'weibull_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:True) – 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 WeibullAFTFitter.
Examples
>>> import ehrapy as ep >>> adata = ep.dt.mimic_2(encoded=False) >>> adata[:, ["censor_flg"]].X = np.where(adata[:, ["censor_flg"]].X == 0, 1, 0) >>> adata = adata[:, ["mort_day_censored", "censor_flg"]] >>> aft = ep.tl.weibull_aft(adata, duration_col="mort_day_censored", event_col="censor_flg") >>> aft.print_summary()