Skip to content

Commit

Permalink
Merge pull request #312 from jdblischak/event_diff
Browse files Browse the repository at this point in the history
Define event_diff() as a separate internal function
  • Loading branch information
nanxstats authored Jan 16, 2024
2 parents 59e8a03 + da5f57f commit ff5dbb6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gsDesign2
Title: Group Sequential Design with Non-Constant Effect
Version: 1.1.0.3
Version: 1.1.0.4
Authors@R: c(
person("Keaven", "Anderson", email = "keaven_anderson@merck.com", role = c("aut")),
person("Yilong", "Zhang", email = "elong0527@gmail.com", role = c("aut")),
Expand Down
37 changes: 26 additions & 11 deletions R/expected_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,10 @@ expected_time <- function(
stop("expected_time(): the input target_event` should be a positive numer, rather than a vector!")
}

# Build a help function ----
# find the difference between `AHR()` and different values of total_duration
event_diff <- function(x) {
ans <- ahr(
enroll_rate = enroll_rate, fail_rate = fail_rate,
total_duration = x, ratio = ratio
)$event - target_event
return(ans)
}

# Perform uniroot AHR() over total_duration ----
res <- try(uniroot(event_diff, interval))
res <- try(
uniroot(event_diff, interval, enroll_rate, fail_rate, ratio, target_event)
)

if (inherits(res, "try-error")) {
stop("expected_time(): solution not found!")
Expand All @@ -120,3 +112,26 @@ expected_time <- function(
return(ans)
}
}

#' Considering the enrollment rate, failure rate, and randomization ratio,
#' calculate the difference between the targeted number of events and the
#' accumulated events at time `x`
#'
#' A helper function passed to `uniroot()`
#'
#' @param x Duration
#' @inheritParams expected_time
#'
#' @return A single numeric value that represents the difference between the
#' expected number of events for the provided duration (`x`) and the targeted
#' number of events (`target_event`)
#'
#' @keywords internal
event_diff <- function(x, enroll_rate, fail_rate, ratio, target_event) {
expected <- ahr(
enroll_rate = enroll_rate, fail_rate = fail_rate,
total_duration = x, ratio = ratio
)
ans <- expected$event - target_event
return(ans)
}
32 changes: 32 additions & 0 deletions man/event_diff.Rd

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

0 comments on commit ff5dbb6

Please sign in to comment.