ehrapy.tools.weibull#
- ehrapy.tools.weibull(edata, duration_col, event_col, *, uns_key='weibull', timeline=None, entry=None, label=None, alpha=None, ci_labels=None, weights=None, fit_options=None, layer=None)[source]#
Employ the Weibull model in univariate survival analysis to understand event occurrence dynamics.
In contrast to the non-parametric Nelson-Aalen estimator, the Weibull model employs a parametric approach with shape and scale parameters, enabling a more structured analysis of survival data. This technique is particularly useful when dealing with censored data, as it accounts for the presence of individuals whose event times are unknown due to censoring. By fitting the Weibull model to censored survival data, researchers can estimate these parameters and gain insights into the hazard rate over time, facilitating comparisons between different groups or treatments. This method provides a comprehensive framework for examining survival data and offers valuable insights into the factors influencing event occurrence dynamics. The results will be stored in the .uns slot of the data object under the key ‘weibull’ unless specified otherwise in the uns_key parameter. See https://lifelines.readthedocs.io/en/latest/fitters/univariate/WeibullFitter.html
- Parameters:
edata (
EHRData) – Central data object.duration_col (
str) – Name of the column in the data objects that contains the subjects’ lifetimes.event_col (
str) – The name of the column in the data 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') – The key to use for the .uns slot in the data object.timeline (
list[float] |None, default:None) – Return the best estimate at the values in timelines (positively increasing)entry (
str|None, default:None) – Relative time when a subject entered the study. This is useful for left-truncated (not left-censored) observations. If None, all members of the population entered study when they were “born”.label (
str|None, default:None) – A string to name the column of the estimate.alpha (
float|None, default:None) – The alpha value in the confidence intervals. Overrides the initializing alpha for this call to fit only.ci_labels (
list[str] |None, default:None) – Add custom column names to the generated confidence intervals as a length-2 list: [<lower-bound name>, <upper-bound name>] (default: <label>_lower_<1-alpha/2>).weights (
list[float] |None, default:None) – If providing a weighted dataset. For example, instead of providing every subject as a single element of durations and event_observed, one could weigh subject differently.fit_options (
dict|None, default:None) – Additional keyword arguments to pass into the estimator.
- Return type:
- Returns:
Fitted WeibullFitter.
Examples
>>> import ehrdata as ed >>> import ehrapy as ep >>> edata = ed.dt.mimic_2() >>> # Flip 'censor_fl' because 0 = death and 1 = censored >>> edata[:, ["censor_flg"]].X = np.where(edata[:, ["censor_flg"]].X == 0, 1, 0) >>> wf = ep.tl.weibull(edata, "mort_day_censored", "censor_flg")