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

Rewrite ExpSurvOS to prevent NaNs #73

Merged
merged 6 commits into from
Oct 2, 2023
Merged

Rewrite ExpSurvOS to prevent NaNs #73

merged 6 commits into from
Oct 2, 2023

Conversation

holgstr
Copy link
Contributor

@holgstr holgstr commented Oct 2, 2023

Fixes #72

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

Unit Tests Summary

    1 files    14 suites   2m 8s ⏱️
  57 tests   57 ✔️ 0 💤 0
139 runs  139 ✔️ 0 💤 0

Results for commit 55705be.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  ---------
R/assertions.R                  15       0  100.00%
R/empSignificant.R              59       0  100.00%
R/eventTracking.R               88       2  97.73%   48, 244
R/getClinicalTrials.R           64       0  100.00%
R/getSimulatedData.R           107       0  100.00%
R/getWaitTimeSum.R              29       2  93.10%   45, 48
R/hazardFunctions.R             26       0  100.00%
R/piecewiseDistribution.R       32       0  100.00%
R/piecewiseHazards.R            18       0  100.00%
R/survivalFunctions.R           96       0  100.00%
R/transitionParameters.R        42       0  100.00%
TOTAL                          576       4  99.31%

Diff against main

Filename                     Stmts    Miss  Cover
-------------------------  -------  ------  --------
R/empSignificant.R             +59       0  +100.00%
R/eventTracking.R               +8       0  +0.23%
R/getClinicalTrials.R           +6       0  +100.00%
R/getSimulatedData.R            +5       0  +100.00%
R/hazardFunctions.R            +26       0  +100.00%
R/piecewiseDistribution.R       -1       0  +100.00%
R/piecewiseHazards.R            +1       0  +100.00%
R/survivalFunctions.R          +96       0  +100.00%
TOTAL                         +200       0  +0.37%

Results for commit: 0c56de3

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@gowerc
Copy link

gowerc commented Oct 2, 2023

Hey @holgstr - Please can you add a unit test for this change. E.g. have some code that would have caused the bug / error on the old code which now works fine on this new code ? Tests code goes in the tests/testthat folder.

@holgstr
Copy link
Contributor Author

holgstr commented Oct 2, 2023

Hey @gowerc, thanks for the quick look, I have added the test now.

@gowerc
Copy link

gowerc commented Oct 2, 2023

@holgstr - Apologies I'm not overly familiar with this project, which equation / paper are you referencing with this change ?

@holgstr
Copy link
Contributor Author

holgstr commented Oct 2, 2023

@gowerc It's S_OS(t) on page 4 of Erdmann et al (2023).

@gowerc
Copy link

gowerc commented Oct 2, 2023

I didn't have time to do the algebra to be confident that, outside of the mentioned edge case, the before and after are identical e.g. that

ExpSurvPFS(t, h01, h02) / h012 * (h12 - h02 - h01 * exp(-h012 * t))

Is equivalent to

ExpSurvPFS(t, h01, h02) + h01 * h012^-1 * (ExpSurvPFS(t, h01, h02) - exp(-h12 * t))

EDIT - Got around to doing the algebra to confirm they are indeed identical :) Left code in for reference though

But running a load of different numbers I can't find any examples where its not true and all the prior unit tests still pass so I'm happy for this to be approved.

Code for reference:

library(testthat)

ExpSurvPFS <- function(t, h01, h02)  exp(-(h01 + h02) * t)

ExpSurvOS <- function(t, h01, h02, h12) {
    h012 <- h12 - h01 - h02
    ExpSurvPFS(t, h01, h02) / h012 * (h12 - h02 - h01 * exp(-h012 * t))
}

new_ExpSurvOS <- function(t, h01, h02, h12) {
    h012 <- h12 - h01 - h02
    ExpSurvPFS(t, h01, h02) + h01 * h012^-1 * (ExpSurvPFS(t, h01, h02) - exp(-h12 * t))
}

are_equal <- function(t, h01, h02, h12) {
    old <- ExpSurvOS(t = t, h01 = h01, h02 = h02, h12 = h12)
    new <- new_ExpSurvOS(t = t, h01 = h01, h02 = h02, h12 = h12)
    expect_equal(old, new)
}

t <- seq(0, 10, by = 0.005)
h01 <- rnorm(length(t), 0, 2) ^2
h02 <- rnorm(length(t), 0, 2) ^2
h12 <- rnorm(length(t), 0, 2) ^2
are_equal(t, h01, h02, h12)

@holgstr - Not essential but may be worth just adding a note to the NEWS.md file listing the bug fix as a not-yet-released change. See here for an example of an "in-development" update where the # number is the number of the PR (73 in this case)

That being said I just realised I don't have permissions to approve the PR 😢

@numbersman77 / @niessl - Would 1 of you be able to approve please; or alternatively could you give me permissions to approve please.

NEWS.md Outdated
Comment on lines 13 to 16

## Minor improvements and bug fixes

- ExpSurvOS now returns 0 instead of NaN for large values of t (#73, @holgstr)
Copy link

Choose a reason for hiding this comment

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

Apologies I wasn't clear, this should go at the top of the file as this will eventually be included into a next version see:

image

https://r-pkgs.org/other-markdown.html#sec-news

@holgstr
Copy link
Contributor Author

holgstr commented Oct 2, 2023

@gowerc was this what you meant? Bc now there is a version conflict between Description and News? :) Maybe I should substitute "(development version)" with "0.0.5.9011" ?

@gowerc
Copy link

gowerc commented Oct 2, 2023

@cicdguy - It looks like the Version check pipeline is designed to fail if the DESCRIPTION version number doesn't exactly match the version number in the NEWS.md file.

Can I double check what the expected/standard workflow is here then. I usually just add everything as (development version) in the NEWS.md file until I'm ready to release at which point I decide if its a patch / minor / major release. It feels like this pipeline is designed for you to have made that decision before you've even determined how many updates will be included in the release ?

@cicdguy
Copy link
Contributor

cicdguy commented Oct 2, 2023

@cicdguy - It looks like the Version check pipeline is designed to fail if the DESCRIPTION version number doesn't exactly match the version number in the NEWS.md file.

Can I double check what the expected/standard workflow is here then. I usually just add everything as (development version) in the NEWS.md file until I'm ready to release at which point I decide if its a patch / minor / major release. It feels like this pipeline is designed for you to have made that decision before you've even determined how many updates will be included in the release ?

Yeah that workflow only checks 2 things:

  1. Whether the version in the NEWS.md matches with the one in the DESCRIPTION file. I believe it was originally added to maintain consistent versions across the changelog (the NEWS.md file) and the package version (in the DESCRIPTION file) for the sake of having automated releases and version bumps (which are used in the NEST workflows).
  2. To check if there are emojis in the NEWS.md file. Turns out that remotes::install_github() is allergic to emojis in the NEWS files.

The former is used in conjunction with the version bump workflow. I'd recommend not using it if you prefer to use (development version) in the NEWS.md instead of the X.Y.Z.9000 format of the version of dev versions of the package.

@gowerc
Copy link

gowerc commented Oct 2, 2023

As this isn't my package I won't advocate for disabling / changing any of the pipelines.
@holgstr - Perhaps just replace "Development version" with the current pre-release number e.g. 0.0.5.9011

@gowerc gowerc self-requested a review October 2, 2023 16:57
@gowerc
Copy link

gowerc commented Oct 2, 2023

@holgstr - Approved feel free to merge

@holgstr
Copy link
Contributor Author

holgstr commented Oct 2, 2023

@gowerc Great, thanks a lot!

@holgstr holgstr merged commit c7783a2 into main Oct 2, 2023
24 checks passed
@holgstr holgstr deleted the exp-surv-os branch October 2, 2023 16:59
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.

ExpSurvOS returns NaN when it should return 0
3 participants