Skip to content
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
72 changes: 72 additions & 0 deletions R/gs_update_ahr.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,78 @@
#'
#' # Alpha is updated to 0.05
#' gs_update_ahr(x = x, alpha = 0.05)
#'
#' # ------------------------------------------------- #
#' # Two-sided asymmetric stratified design,
#' # beta-spending with non-binding lower bound
#' # ------------------------------------------------- #
#' enroll_rate <- define_enroll_rate(stratum = c("A", "B"), duration = c(12, 12), rate = c(1, 1))
#'
#' # We assumme there are 2 strata, "A" and "B".
#' # For each stratum, there are delayed effect for the first 3 months.
#' # After the delayed effect, the HR is 0.8 for stratum A and 0.5 for stratum B.
#' fail_rate <- define_fail_rate(stratum = c("A", "A", "B", "B"),
#' duration = c(3, Inf, 3, Inf),
#' fail_rate = log(2) / c(9, 9, 9, 15),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it deserve a comment why the failure rate is different only for stratum B after the delayed effect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for your suggestions. These are really nice comments!

When is an example long enough that a vignette would be the better option?

The vignettes are typically more narrative-driven, which is the style Keaven prefers.
Although this example is lengthy, its primary focus is on demonstrating implementation rather than telling a complex story. Therefore, let's categorize it as an "example" for now, not a full vignette.

Does it deserve a comment why the failure rate is different only for stratum B after the delayed effect?

You identified the key consideration here! Typically, the median of the control arm is assumed to be constant. However, in some scenarios, it can be modeled as time-varying. This example demostrates that gsDesign2 is able to do time-varying median. Since the primary goal is for users to adapt the code and input their own study-specific parameters, the current example is sufficient.

#' hr = c(1, 0.8, 1, 0.5),
#' dropout_rate = rep(0.001, 4))
#'
#' # The original design assumes there are 2 IAs and 1 FA cutting by calendar time.
#' # The efficacy testing is conducted at IA2 and FA.
#' # The futility testing is conducted at IA1.
#' x <- gs_design_ahr(enroll_rate = enroll_rate,
#' fail_rate = fail_rate,
#' alpha = 0.0125,
#' beta = 0.1,
#' analysis = c(20, 28, 36),
#' upper = "gs_spending_bound",
#' upar = list(sf = "sfLDOF", total_spend = 0.0125),
#' lower = "gs_spending_bound",
#' lpar = list(sf = "sfHSD", total_spend = 0.1, param = -8),
#' test_upper = c(FALSE, TRUE, TRUE),
#' test_lower = c(TRUE, FALSE, FALSE)) |> to_integer()
#'
#' # At time of analysis
#' # For IA1,
#' # - There are 70 events observed during the delayed effect period for stratum A.
#' # - There are 150 events observed after the delayed effect period for stratum A.
#' # - There are 75 events observed during the delayed effect period for stratum B.
#' # - There are 90 events observed after the delayed effect period for stratum B.
#' # For IA2,
#' # - There are 75 events observed during the delayed effect period for stratum A.
#' # - There are 210 events observed after the delayed effect period for stratum A.
#' # - There are 76 events observed during the delayed effect period for stratum B.
#' # - There are 136 events observed after the delayed effect period for stratum B.
#' # For FA,
#' # - There are 77 events observed during the delayed effect period for stratum A.
#' # - There are 245 events observed after the delayed effect period for stratum A.
#' # - There are 77 events observed during the delayed effect period for stratum B.
#' # - There are 170 events observed after the delayed effect period for stratum B.
#' event_tbl <- data.frame(analysis = c(1, 1, 1, 1,
#' 2, 2, 2, 2,
#' 3, 3, 3, 3),
#' stratum = c("A", "A", "B", "B", # IA1
#' "A", "A", "B", "B", # IA2
#' "A", "A", "B", "B"),# FA
#' # event per interval per stratum at IA1
#' event = c(70, 150, 75, 90,
#' # event per interval per stratum at IA2
#' 75, 210, 76, 136,
#' # event per interval per stratum at FA
#' 77, 245, 77, 170))
#' observed_event <- (event_tbl |> dplyr::group_by(analysis) |> dplyr::summarize(x = sum(event)))$x
#'
#' ustime <- pmin(x$analysis$event,
#' observed_event) / x$analysis$event[3]
#' ustime[3] <- 1
#' lstime <- ustime
#'
#' xu <- gs_update_ahr(x = x,
#' alpha = 0.015,
#' ustime = ustime,
#' lstime = lstime,
#' event_tbl = event_tbl
#' )
gs_update_ahr <- function(
x = NULL,
alpha = NULL,
Expand Down
72 changes: 72 additions & 0 deletions man/gs_update_ahr.Rd

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

Loading