ehrapy.tools.cox_ph¶
- ehrapy.tools.cox_ph(adata, duration_col, event_col, entry_col=None)[source]¶
Fit the Cox’s proportional hazard for the survival function.
The Cox proportional hazards model (CoxPH) examines the relationship between the survival time of subjects and one or more predictor variables. It models the hazard rate as a product of a baseline hazard function and an exponential function of the predictors, assuming proportional hazards over time.
See https://lifelines.readthedocs.io/en/latest/fitters/regression/CoxPHFitter.html
- Parameters:
adata (
AnnData
) – AnnData object with necessary columns duration_col and event_col.duration_col (
str
) – The name of the column in the AnnData objects that contains the subjects’ lifetimes.event_col (
str
) – The name of the column in anndata that contains the subjects’ death observation. If left as None, assume all individuals are uncensored.entry_col (
str
, default:None
) – Column denoting when a subject entered the study, i.e. left-truncation.
- Return type:
CoxPHFitter
- Returns:
Fitted CoxPHFitter.
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) >>> cph = ep.tl.cox_ph(adata, "mort_day_censored", "censor_flg")