Skip to content

Commit

Permalink
Fix WeibSurvOS (#80)
Browse files Browse the repository at this point in the history
<!--- Replace `#nnn` with your issue link for reference. -->

Fixes #78

---------

Signed-off-by: Daniel Sabanes Bove <danielinteractive@users.noreply.github.com>
Co-authored-by: Daniel Sabanes Bove <danielinteractive@users.noreply.github.com>
  • Loading branch information
holgstr and danielinteractive authored Nov 1, 2023
1 parent 5e4ab86 commit 004067c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

- `ExpSurvOS` now returns 0 instead of NaN for large values of t.
- `WeibSurvOS` now does not return an error for large values of t.
- `getSimulatedData` now also works when there are no transitions from progression to death, similarly for `getOneClinicalTrial` (which now warns if there are no such transitions at all).


Expand Down
25 changes: 16 additions & 9 deletions R/survivalFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ integrateVector <- function(integrand, upper, ...) {
#' @export
#'
#' @examples
#' WeibOSInteg(1:5, 0.2, 0.5, 2.1, 1.2, 0.9, 1)
WeibOSInteg <- function(x, h01, h02, h12, p01, p02, p12) {
x^(p01 - 1) * exp(-h01 * x^p01 - h02 * x^p02 + h12 * x^p12)
#' WeibOSInteg(1:5, 2:6, 0.2, 0.5, 2.1, 1.2, 0.9, 1)
WeibOSInteg <- function(x, t, h01, h02, h12, p01, p02, p12) {
x^(p01 - 1) * exp(-h01 * x^p01 - h02 * x^p02 - h12 * (t^p12 - x^p12))
}

#' OS Survival Function from Weibull Transition Hazards
Expand All @@ -118,14 +118,21 @@ WeibSurvOS <- function(t, h01, h02, h12, p01, p02, p12) {
assert_positive_number(p12)

WeibSurvPFS(t, h01, h02, p01, p02) +
h01 * p01 * exp(-h12 * t^p12) *
integrateVector(WeibOSInteg,
upper = t,
h01 = h01, h02 = h02, h12 = h12, p01 = p01, p02 = p02, p12 = p12
)
h01 * p01 *
sapply(t, function(t) {
integrateVector(WeibOSInteg,
upper = t,
t = t,
h01 = h01,
h02 = h02,
h12 = h12,
p01 = p01,
p02 = p02,
p12 = p12
)
})
}


#' Cumulative Hazard for Piecewise Constant Hazards
#'
#' @param t (`numeric`)\cr study time-points.
Expand Down
6 changes: 4 additions & 2 deletions man/WeibOSInteg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testthat/test-survivalFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ test_that("WeibSurvOS works as expected", {

actual2 <- WeibSurvOS(0, 0.7, 0.5, 0.8, 1.2, 1, 0.9)
expect_equal(actual2, 1)

actual3 <- WeibSurvOS(1000, 1, 1.1, 1.2, 1.3, 0.8, 1.4)
expect_equal(actual3, 0)
})

# pwA ----
Expand Down

0 comments on commit 004067c

Please sign in to comment.