Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Forestplot for CoxPH model #838

Merged
merged 34 commits into from
Jan 15, 2025
Merged

New Feature: Forestplot for CoxPH model #838

merged 34 commits into from
Jan 15, 2025

Conversation

aGuyLearning
Copy link
Collaborator

@aGuyLearning aGuyLearning commented Dec 6, 2024

PR Checklist
Resolves #743

  • This comment contains a description of changes (with reason)
  • Referenced issue is linked
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

This pull request introduces a new plotting function for Cox Proportional Hazards models and updates related documentation and tests. The most important changes include adding a new plotting function, updating imports, and adding new tests.

New Feature:

  • Added cox_ph_forestplot function to generate forest plots for Cox Proportional Hazards models in ehrapy/plot/_survival_analysis.py.

Documentation Updates:

  • Updated docs/usage/usage.md to include plot.cox_ph_forestplot in the list of available plotting functions.

Import Adjustments:

  • Modified ehrapy/plot/__init__.py to import the new cox_ph_forestplot function.
  • Updated import statements in ehrapy/plot/_survival_analysis.py to include necessary modules for the new plotting function.

Testing Enhancements:

  • Added a new test in tests/plot/test_survival_analysis.py to validate the cox_ph_forestplot function.
  • Created a Jupyter notebook tests/_scripts/coxph_forestplot_create_expected.ipynb to generate expected output for the new plotting function.

Additional Fixtures:

  • Introduced a new pytest fixture mimic_2 in tests/conftest.py to provide test data for the new function.
image

image

@aGuyLearning aGuyLearning linked an issue Dec 6, 2024 that may be closed by this pull request
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@eroell eroell self-requested a review December 6, 2024 17:20
@github-actions github-actions bot added the chore label Dec 11, 2024
@eroell
Copy link
Collaborator

eroell commented Dec 11, 2024

Hm checking into the failed docs build

@eroell
Copy link
Collaborator

eroell commented Dec 11, 2024

How did you make the option to have this dashed vertical bar before? That seemed quite nice!

ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Show resolved Hide resolved
@eroell eroell added enhancement New feature or request and removed chore labels Dec 11, 2024
@github-actions github-actions bot added the chore label Dec 11, 2024
@eroell
Copy link
Collaborator

eroell commented Dec 11, 2024

And at the end flexing this feature in the survival notebook would be great.. :)

@eroell eroell closed this Dec 11, 2024
@eroell eroell reopened this Dec 11, 2024
@eroell
Copy link
Collaborator

eroell commented Dec 11, 2024

sorry, misclicked!

ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
ehrapy/plot/_survival_analysis.py Outdated Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
@eroell
Copy link
Collaborator

eroell commented Dec 11, 2024

Medcat no more a doc build dependency; asked about state of Python 3.12 CogStack/MedCAT#510

@aGuyLearning aGuyLearning requested a review from eroell January 15, 2025 08:35
@eroell
Copy link
Collaborator

eroell commented Jan 15, 2025

One a sidenote, there should be a pull request template with checkmarks and some suggested subtitles for the first comment, which we should use for all pull requests ideally.

@aGuyLearning aGuyLearning requested a review from eroell January 15, 2025 08:56

Args:
adata: :class:`~anndata.AnnData` object containing all observations in `.uns`.
uns_key: Key in `.uns` where the CoxPHFitter object is stored.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to a brief description of the result that is stored there; mention and reference the ehrapy function who writes the results into this field

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated or at least synced with the uns_key argument description, where there is also still the wrong description about the CoxPHFitter object

Args:
adata: :class:`~anndata.AnnData` object containing all observations in `.uns`.
uns_key: Key in `.uns` where the CoxPHFitter object is stored.
labels: List of labels for each coefficient, default uses the index of the coxph.summary.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is coxph.summary? (I know, but users should be able to understand what this is doing by just following our documentation)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the updates of the current review request, this is still as it looked when I made this comment? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, very sorry, i should first fix it in my editor and then sign of here.

@eroell
Copy link
Collaborator

eroell commented Jan 15, 2025

Quick question on the additional functionality with the secondary helper plots "below" the forestplot; are you planning to add them, or are they too unstable/time consuming to set up at this stage? (fine if this is the case of course, could also be a later enhancement!)

@eroell eroell changed the title coxph_forestplot New Feature: Forestplot for CoxPH model Jan 15, 2025
@aGuyLearning aGuyLearning requested a review from eroell January 15, 2025 11:44
@aGuyLearning
Copy link
Collaborator Author

There is no table intended under the forest plot. i believe you mean #742

@eroell
Copy link
Collaborator

eroell commented Jan 15, 2025

There is no table intended under the forest plot. i believe you mean #742

Ah yes, had mixed this up, thanks!

Copy link
Collaborator

@eroell eroell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 2 re-unresolved comments

@eroell eroell merged commit ac2c531 into main Jan 15, 2025
11 checks passed
@eroell eroell deleted the enhancement/issue-743 branch January 15, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visualization of CoxPH models
3 participants