From a0e3d901bb30e2547ba12ca9fa43a6211c4dd834 Mon Sep 17 00:00:00 2001 From: LittleBeannie Date: Mon, 9 Jun 2025 10:45:59 -0400 Subject: [PATCH 1/2] fix the non-working example in `sim_gs_n` --- R/sim_gs_n.R | 37 ++++++++++++++++++++++++++++--------- man/sim_gs_n.Rd | 21 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/R/sim_gs_n.R b/R/sim_gs_n.R index 14ffc448..0992454f 100644 --- a/R/sim_gs_n.R +++ b/R/sim_gs_n.R @@ -254,7 +254,7 @@ #' ) #' plan("sequential") #' -#' # Example 10: group sequential design with updated bounds +#' # Example 10: group sequential design with updated bounds -- efficacy only #' x <- gs_design_ahr(analysis_time = 1:3*12) |> to_integer() #' sim_gs_n( #' n_sim = 1, @@ -268,6 +268,25 @@ #' weight = fh(rho = 0, gamma = 0), #' original_design = x #' ) +#' +#' # Example 11: group sequential design with updated bounds -- efficacy & futility +#' x <- gs_design_ahr( +#' alpha = 0.025, beta = 0.1, analysis_time = 1:3*12, +#' upper = gs_spending_bound, upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025), +#' lower = gs_spending_bound, lpar = list(sf = gsDesign::sfHSD, param = -4, total_spend = 0.01), +#' test_upper = c(FALSE, TRUE, TRUE), test_lower = c(TRUE, FALSE, FALSE)) |> to_integer() +#' sim_gs_n( +#' n_sim = 1, +#' sample_size = max(x$analysis$n), +#' enroll_rate = x$enroll_rate, +#' fail_rate = x$fail_rate, +#' test = wlr, +#' cut = list(ia1 = create_cut(planned_calendar_time = x$analysis$time[1]), +#' ia2 = create_cut(planned_calendar_time = x$analysis$time[2]), +#' fa = create_cut(planned_calendar_time = x$analysis$time[3])), +#' weight = fh(rho = 0, gamma = 0), +#' original_design = x +#' ) #' } sim_gs_n <- function( n_sim = 1000, @@ -389,10 +408,10 @@ sim_gs_n <- function( # Add planned and updated bounds if (!is.null(original_design) && is_logrank){ # Add planned bounds - planed_upper_bound <- original_design$bound$z[original_design$bound$bound == "upper"] - planed_lower_bound <- original_design$bound$z[original_design$bound$bound == "lower"] - ans_1sim$planed_upper_bound <- planed_upper_bound - ans_1sim$planed_lower_bound <- planed_lower_bound + ans_1sim <- ans_1sim |> + left_join(original_design$bound |> filter(bound == "upper") |> select(analysis, z) |> rename(planed_upper_bound = z)) |> + left_join(original_design$bound |> filter(bound == "lower") |> select(analysis, z) |> rename(planed_lower_bound = z)) + # Calculate ustime and lstime obs_event <- with(event_tbl, tapply(event, analysis, sum, simplify = TRUE)) @@ -417,10 +436,10 @@ sim_gs_n <- function( ustime = ustime, lstime = if(all(original_design$bound$bound == "upper")){NULL}else{lstime}, event_tbl = event_tbl) - updated_upper_bound <- updated_design$bound$z[updated_design$bound$bound == "upper"] - updated_lower_bound <- updated_design$bound$z[updated_design$bound$bound == "lower"] - ans_1sim$updated_upper_bound <- updated_upper_bound - ans_1sim$updated_lower_bound <- updated_lower_bound + + ans_1sim <- ans_1sim |> + left_join(updated_design$bound |> filter(bound == "upper") |> select(analysis, z) |> rename(updated_upper_bound = z)) |> + left_join(updated_design$bound |> filter(bound == "lower") |> select(analysis, z) |> rename(updated_lower_bound = z)) } ans_1sim diff --git a/man/sim_gs_n.Rd b/man/sim_gs_n.Rd index 6bd2d66b..4d8eaf73 100644 --- a/man/sim_gs_n.Rd +++ b/man/sim_gs_n.Rd @@ -282,7 +282,7 @@ sim_gs_n( ) plan("sequential") -# Example 10: group sequential design with updated bounds +# Example 10: group sequential design with updated bounds -- efficacy only x <- gs_design_ahr(analysis_time = 1:3*12) |> to_integer() sim_gs_n( n_sim = 1, @@ -296,6 +296,25 @@ sim_gs_n( weight = fh(rho = 0, gamma = 0), original_design = x ) + +# Example 11: group sequential design with updated bounds -- efficacy & futility +x <- gs_design_ahr( + alpha = 0.025, beta = 0.1, analysis_time = 1:3*12, + upper = gs_spending_bound, upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025), + lower = gs_spending_bound, lpar = list(sf = gsDesign::sfHSD, param = -4, total_spend = 0.01), + test_upper = c(FALSE, TRUE, TRUE), test_lower = c(TRUE, FALSE, FALSE)) |> to_integer() +sim_gs_n( + n_sim = 1, + sample_size = max(x$analysis$n), + enroll_rate = x$enroll_rate, + fail_rate = x$fail_rate, + test = wlr, + cut = list(ia1 = create_cut(planned_calendar_time = x$analysis$time[1]), + ia2 = create_cut(planned_calendar_time = x$analysis$time[2]), + fa = create_cut(planned_calendar_time = x$analysis$time[3])), + weight = fh(rho = 0, gamma = 0), + original_design = x +) } \dontshow{\}) # examplesIf} } From 7e1d281b0847d9b272200dba4a40675a5b50cc23 Mon Sep 17 00:00:00 2001 From: LittleBeannie Date: Mon, 9 Jun 2025 11:00:39 -0400 Subject: [PATCH 2/2] add namespace of `left_join`, `select`, `filter` and `rename` --- R/sim_gs_n.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/sim_gs_n.R b/R/sim_gs_n.R index 0992454f..2b0f813f 100644 --- a/R/sim_gs_n.R +++ b/R/sim_gs_n.R @@ -409,8 +409,8 @@ sim_gs_n <- function( if (!is.null(original_design) && is_logrank){ # Add planned bounds ans_1sim <- ans_1sim |> - left_join(original_design$bound |> filter(bound == "upper") |> select(analysis, z) |> rename(planed_upper_bound = z)) |> - left_join(original_design$bound |> filter(bound == "lower") |> select(analysis, z) |> rename(planed_lower_bound = z)) + dplyr::left_join(original_design$bound |> dplyr::filter(bound == "upper") |> dplyr::select(analysis, z) |> dplyr::rename(planed_upper_bound = z)) |> + dplyr::left_join(original_design$bound |> dplyr::filter(bound == "lower") |> dplyr::select(analysis, z) |> dplyr::rename(planed_lower_bound = z)) # Calculate ustime and lstime @@ -438,8 +438,8 @@ sim_gs_n <- function( event_tbl = event_tbl) ans_1sim <- ans_1sim |> - left_join(updated_design$bound |> filter(bound == "upper") |> select(analysis, z) |> rename(updated_upper_bound = z)) |> - left_join(updated_design$bound |> filter(bound == "lower") |> select(analysis, z) |> rename(updated_lower_bound = z)) + dplyr::left_join(updated_design$bound |> dplyr::filter(bound == "upper") |> dplyr::select(analysis, z) |> dplyr::rename(updated_upper_bound = z)) |> + dplyr::left_join(updated_design$bound |> dplyr::filter(bound == "lower") |> dplyr::select(analysis, z) |> dplyr::rename(updated_lower_bound = z)) } ans_1sim