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

adds ExpHazOS function #65

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(ExpHazOS)
export(ExpQuantOS)
export(ExpSurvOS)
export(ExpSurvPFS)
Expand Down
21 changes: 21 additions & 0 deletions R/hazardFunctions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' OS Hazard Function from Constant Transition Hazards
#'
#' @param t (`numeric`)\cr study time-points.
#' @param h01 (positive `number`)\cr transition hazard for 0 to 1 transition.
#' @param h02 (positive `number`)\cr transition hazard for 0 to 2 transition.
#' @param h12 (positive `number`)\cr transition hazard for 1 to 2 transition.
#'
#' @return This returns the value of the OS hazard function at time t.
#' @export
#'
#' @examples
#' ExpHazOS(c(1:5), 0.2, 1.1, 0.8)
ExpHazOS <- function(t, h01, h02, h12) {
assert_numeric(t, lower = 0, any.missing = FALSE)
assert_positive_number(h01)
assert_positive_number(h02)
assert_positive_number(h12)

h012 <- h12 - h01 - h02
((h12 - h02) * (h01 + h02) - h01 * h12 * exp(-h012 * t)) / ((h12 - h02) - h01 * exp(-h012 * t))
}
3 changes: 3 additions & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ reference:
- PWCsurvPFS
- PwcOSInt
- PWCsurvOS
- title: Hazard functions
contents:
- ExpHazOS
26 changes: 26 additions & 0 deletions man/ExpHazOS.Rd

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

15 changes: 15 additions & 0 deletions tests/testthat/test-hazardFunctions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ExpHazOS ----

test_that("ExpHazOS works as expected", {
actual <- ExpHazOS(1, 0.2, 1.1, 0.8)
expect_equal(actual, 1.038192, tolerance = 1e-3)

actual2 <- ExpHazOS(2, 0.4, 1.4, 0.1)
expect_equal(actual2, 0.266345, tolerance = 1e-3)
})

test_that("ExpHazOS works also with vector of times t", {
result <- ExpHazOS(t = c(1:3), 0.2, 1.1, 0.8)
expected <- c(1.0381919, 0.9777975, 0.9253826)
expect_equal(result, expected, tolerance = 1e-3)
})