-
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.
Enhancement: KM plot data depth and functionality (#853)
* using current commit of tutorials notebook * Enhance Kaplan-Meier plot with grid layout and survival probability table * added toggle for table * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix return values in kaplan_meier and update documentation for cox_ph_forestplot * Fix typo in display_table parameter and add tests for Kaplan-Meier plots * Rename display_table parameter to display_survival_statistics in kaplan_meier function and update related tests * Fix documentation typo in cox_ph_forestplot function * Update grid specification in kaplan_meier function and rerendered test images * Improve docstring --------- Co-authored-by: Eljas Roellin <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lukas Heumos <[email protected]>
- Loading branch information
1 parent
d710367
commit ae9eed7
Showing
5 changed files
with
212 additions
and
10 deletions.
There are no files selected for viewing
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
118 changes: 118 additions & 0 deletions
118
tests/_scripts/kaplain_meier_create_expected_plots.ipynb
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,118 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"import ehrapy as ep\n", | ||
"\n", | ||
"current_notebook_dir = %pwd\n", | ||
"_TEST_IMAGE_PATH = f\"{current_notebook_dir}/../plot/_images\"\n", | ||
"mimic_2 = ep.dt.mimic_2(encoded=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mimic_2[:, [\"censor_flg\"]].X = np.where(mimic_2[:, [\"censor_flg\"]].X == 0, 1, 0)\n", | ||
"groups = mimic_2[:, [\"service_unit\"]].X\n", | ||
"adata_ficu = mimic_2[groups == \"FICU\"]\n", | ||
"adata_micu = mimic_2[groups == \"MICU\"]\n", | ||
"kmf_1 = ep.tl.kaplan_meier(adata_ficu, duration_col=\"mort_day_censored\", event_col=\"censor_flg\", label=\"FICU\")\n", | ||
"kmf_2 = ep.tl.kaplan_meier(adata_micu, duration_col=\"mort_day_censored\", event_col=\"censor_flg\", label=\"MICU\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig, ax = ep.pl.kaplan_meier(\n", | ||
" [kmf_1, kmf_2],\n", | ||
" ci_show=[False, False, False],\n", | ||
" color=[\"k\", \"r\"],\n", | ||
" xlim=[0, 750],\n", | ||
" ylim=[0, 1],\n", | ||
" xlabel=\"Days\",\n", | ||
" ylabel=\"Proportion Survived\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig.savefig(f\"{_TEST_IMAGE_PATH}/kaplan_meier_expected.png\", dpi=80)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig, ax = ep.pl.kaplan_meier(\n", | ||
" [kmf_1, kmf_2],\n", | ||
" ci_show=[False, False, False],\n", | ||
" color=[\"k\", \"r\"],\n", | ||
" xlim=[0, 750],\n", | ||
" ylim=[0, 1],\n", | ||
" xlabel=\"Days\",\n", | ||
" ylabel=\"Proportion Survived\",\n", | ||
" display_survival_statistics=True,\n", | ||
" grid=True,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig.savefig(f\"{_TEST_IMAGE_PATH}/kaplan_meier_table_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 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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