Skip to content

Commit

Permalink
renamed function and updated documentation to mention, that it is a l…
Browse files Browse the repository at this point in the history
…ifelines object
  • Loading branch information
aGuyLearning committed Dec 13, 2024
1 parent 75ee4ba commit 541e505
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ehrapy/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from ehrapy.plot._colormaps import * # noqa: F403
from ehrapy.plot._missingno_pl_api import * # noqa: F403
from ehrapy.plot._scanpy_pl_api import * # noqa: F403
from ehrapy.plot._survival_analysis import coxph_forestplot, kaplan_meier, ols
from ehrapy.plot._survival_analysis import cox_ph_forestplot, kaplan_meier, ols
from ehrapy.plot.causal_inference._dowhy import causal_effect
from ehrapy.plot.feature_ranking._feature_importances import rank_features_supervised
19 changes: 12 additions & 7 deletions ehrapy/plot/_survival_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ def kaplan_meier(
return None


def coxph_forestplot(
coxph: CoxPHFitter,
def cox_ph_forestplot(
cox_ph: CoxPHFitter,
labels: list[str] | None = None,
fig_size: tuple = (10, 10),
t_adjuster: float = 0.1,
Expand All @@ -313,11 +313,12 @@ def coxph_forestplot(
text_size: int = 12,
color: str = "k",
):
"""Plots a forest plot of the Cox Proportional Hazard model.
"""Generates a forest plot to visualize the coefficients and confidence intervals of a Cox Proportional Hazards model.
The method requires a fitted CoxPHFitter object from the lifelines library.
Inspired by `zepid.graphics.EffectMeasurePlot <https://readthedocs.org>`_ (zEpid Package, https://pypi.org/project/zepid/).
Args:
coxph: Fitted CoxPHFitter object.
coxph: Fitted CoxPHFitter object from the lifelines library.
labels: List of labels for each coefficient, default uses the index of the coxph.summary.
fig_size: Width, height in inches.
t_adjuster: Adjust the table to the right.
Expand All @@ -332,13 +333,17 @@ def coxph_forestplot(
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> adata_subset = adata[:, ["mort_day_censored", "censor_flg", "gender_num", "afib_flg", "day_icu_intime_num"]]
>>> coxph = ep.tl.coxph(adata_subset, event_col="censor_flg", duration_col="mort_day_censored")
>>> ep.pl.coxph_forestplot(coxph)
>>> coxph = ep.tl.cox_ph(adata_subset, event_col="censor_flg", duration_col="mort_day_censored")
>>> ep.pl.cox_ph_forestplot(coxph)
.. image:: /_static/docstring_previews/coxph_forestplot.png
"""
data = coxph.summary
# check that the coxph object is fitted
if not cox_ph._fitted:
raise ValueError("The CoxPHFitter object must be fitted")

data = cox_ph.summary
auc_col = "coef"

if labels is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/plot/test_catplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_catplot_vanilla(adata_mini, check_same_image):
def test_coxph_forestplot(mimic_2, check_same_image):
adata_subset = mimic_2[:, ["mort_day_censored", "censor_flg", "gender_num", "afib_flg", "day_icu_intime_num"]]
coxph = ep.tl.cox_ph(adata_subset, duration_col="mort_day_censored", event_col="censor_flg")
fig, ax = ep.pl.coxph_forestplot(coxph, fig_size=(12, 3), t_adjuster=0.15, marker="o", size=2, text_size=14)
fig, ax = ep.pl.cox_ph_forestplot(coxph, fig_size=(12, 3), t_adjuster=0.15, marker="o", size=2, text_size=14)

check_same_image(
fig=fig,
Expand Down

0 comments on commit 541e505

Please sign in to comment.