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

Add a type = "cloglog" for log minus log survival plots #195

Merged
merged 17 commits into from
May 8, 2024

Conversation

avishaitsur
Copy link
Contributor

@avishaitsur avishaitsur commented Mar 31, 2024

What changes are proposed in this pull request?
Add a type = "cloglog" for log minus log survival plots to tidysurvfit() and ggsurvfit(). These plots are widely used to assess the assumption of proportional hazards before running a Cox regression model and are implemented in the survival and survminer packages.

If there is an GitHub issue associated with this pull request, please provide link.
closes #194


Reviewer Checklist (if item does not apply, mark as complete)

  • Ensure all package dependencies are installed by running renv::install()
  • PR branch has pulled the most recent updates from master branch. Ensure the pull request branch and your local version match and both have the latest updates from the master branch.
  • If a new function was added, function included in _pkgdown.yml
  • If a bug was fixed, a unit test was added for the bug check
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Overall code coverage remains >99.5%. Review coverage with withr::with_envvar(list(CI = TRUE), code = devtools::test_coverage()). Begin in a fresh R session without any packages loaded.
  • R CMD Check runs without errors, warnings, and notes
  • usethis::use_spell_check() runs with no spelling errors in documentation

When the branch is ready to be merged into master:

  • Update NEWS.md with the changes from this pull request under the heading "# ggsurvfit (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • Increment the version number using usethis::use_version(which = "dev")
  • Run usethis::use_spell_check() again
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge".

@ddsjoberg
Copy link
Collaborator

Thank you for the PR!! I will likely to get to this next week.

@ddsjoberg
Copy link
Collaborator

it looks like there are some test failures. can you take a look at the details?

@ddsjoberg
Copy link
Collaborator

FYI, I have just heard from the maintainer of the survival package that they are planning a release that has breaking changes in ggsurvfit. This means that I will prepping a new release soon. If you want to address the failures in the checks in the next week, we may be able to add this to the next release. Let me know if you have questions. Thanks, Daniel

@avishaitsur
Copy link
Contributor Author

Hi Daniel,

I'm a physician, and my coding/GitHub/package development skills are pretty basic. Despite my best efforts, I am struggling with the remaining test failures. I have managed to address some, but others are beyond my ability to resolve efficiently.

I'm reaching out to see if someone within the community could assist in refining these fixes. I believe the updates would be beneficial, especially for users conducting medical research. Any support or direction on how to move forward with these specific issues would be greatly appreciated.

Thank you again for your patience and for considering these modifications.

R/ggsurvfit.R Outdated
@@ -73,13 +73,17 @@ ggsurvfit <- function(x, type = "survival",
# prep data to be passed to ggplot() -----------------------------------------
df <-
tidy_survfit(x = x, type = type) %>%
dplyr::filter(type != "cloglog" | .data$time > 0) %>%
Copy link
Collaborator

Choose a reason for hiding this comment

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

@avishaitsur can you explain what the purpose of this addition is? Thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the line that is causing the GitHub Actions Checks to fail, and I don't understand why/if it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The transformation in log minus log survival is cloglog = function(y) log(-log(y)).
In time 0, by definition, the survival y is 1, and therefore, the result is undefined (log of 1 is 0, and log of -0 is undefined).
For this reason, the transformation and the visual do not apply to time 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course, thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder the best way to handle this as survfit() allows negative times. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The transformation and the visual are implemented in the survival and survminer packages. Maybe we could explore their solutions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

worst case, we get a NaN or Inf value and it won't appear on the plot.

I am going to go ahead and merge this now (assuming the current tests complete without error). I am also going to make a release

@ddsjoberg
Copy link
Collaborator

FYI I removed the call to ggplot2::scale_x_log10 because we were mixing log base e with log base 10. I added an example to the gallery using the correct base log.

@ddsjoberg ddsjoberg merged commit ef4fc45 into pharmaverse:main May 8, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add type = "cloglog" (log minus log survival)
2 participants