-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Feature: Forestplot for CoxPH model (#838)
* coxph_forestplot * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changed-notebook * Update ehrapy/plot/_survival_analysis.py Co-authored-by: Eljas Roellin <[email protected]> * Update ehrapy/plot/_survival_analysis.py Co-authored-by: Eljas Roellin <[email protected]> * Remove useless empty line * Remove useless comment * undo again; check rtd build * renamed function and updated documentation to mention, that it is a lifelines object * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * removed fitted check and updated name in notebook * Update ehrapy/plot/_survival_analysis.py Co-authored-by: Lukas Heumos <[email protected]> * updated variable names and moved test to better file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * made anything after coxphfitter keyword only * changed type to iterable * added title and show args * less ambiguous loop index * fixed test. had to return figure and axis, so the test can save the image * get summary form adata * updated docs * updated exampel * removed fitter object from docu * Update ehrapy/plot/_survival_analysis.py Co-authored-by: Eljas Roellin <[email protected]> * docu updates, for understandability * link between functions * Enhance documentation for cox_ph_forestplot function to clarify usage of adata and summary table * Update documentation for cox_ph_forestplot function to clarify uns_key argument usage * Refactor subplot variable names for clarity in cox_ph_forestplot function --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eljas Roellin <[email protected]> Co-authored-by: Lukas Heumos <[email protected]> Co-authored-by: eroell <[email protected]>
- Loading branch information
1 parent
728f1bd
commit ac2c531
Showing
10 changed files
with
288 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"import ehrapy as ep" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"current_notebook_dir = %pwd\n", | ||
"_TEST_IMAGE_PATH = f\"{current_notebook_dir}/../plot/_images\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"adata = ep.dt.mimic_2(encoded=False)\n", | ||
"adata_subset = adata[:, [\"mort_day_censored\", \"censor_flg\", \"gender_num\", \"afib_flg\", \"day_icu_intime_num\"]]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"genderafib_coxph = ep.tl.cox_ph(adata_subset, duration_col=\"mort_day_censored\", event_col=\"censor_flg\")\n", | ||
"\n", | ||
"fig, ax = ep.pl.cox_ph_forestplot(genderafib_coxph, fig_size=(12, 3), t_adjuster=0.15, marker=\"o\", size=2, text_size=14)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig.savefig(f\"{_TEST_IMAGE_PATH}/coxph_forestplot_expected.png\", dpi=80)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
|
||
import ehrapy as ep | ||
|
||
CURRENT_DIR = Path(__file__).parent | ||
_TEST_IMAGE_PATH = f"{CURRENT_DIR}/_images" | ||
|
||
|
||
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"]] | ||
ep.tl.cox_ph(adata_subset, duration_col="mort_day_censored", event_col="censor_flg") | ||
fig, ax = ep.pl.cox_ph_forestplot(adata_subset, fig_size=(12, 3), t_adjuster=0.15, marker="o", size=2, text_size=14) | ||
|
||
check_same_image( | ||
fig=fig, | ||
base_path=f"{_TEST_IMAGE_PATH}/coxph_forestplot", | ||
tol=2e-1, | ||
) |