diff --git a/R/fixed_design.R b/R/fixed_design.R index 41aed81c..e3f72e95 100644 --- a/R/fixed_design.R +++ b/R/fixed_design.R @@ -547,7 +547,7 @@ fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", " alpha = alpha, beta = 1 - power, ratio = ratio, enroll_rate = enroll_rate, fail_rate = fail_rate, analysis_time = study_duration, - test = "rmst difference", + test = "rmst_difference", tau = ifelse(has_tau, args$tau, study_duration) ) } else { @@ -555,7 +555,7 @@ fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", " alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, fail_rate = fail_rate, analysis_time = study_duration, - test = "rmst difference", + test = "rmst_difference", tau = ifelse(has_tau, args$tau, study_duration) ) } @@ -583,7 +583,7 @@ fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", " alpha = alpha, beta = 1 - power, ratio = ratio, enroll_rate = enroll_rate, fail_rate = fail_rate, analysis_time = study_duration, - test = "survival difference", + test = "survival_difference", tau = ifelse(has_tau, args$tau, study_duration) ) } else { @@ -591,7 +591,7 @@ fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", " alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, fail_rate = fail_rate, analysis_time = study_duration, - test = "survival difference", + test = "survival_difference", tau = ifelse(has_tau, args$tau, study_duration) ) } @@ -615,6 +615,7 @@ fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", " } ) + class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/rmst.R b/R/rmst.R index 81cd2b53..57f0a287 100644 --- a/R/rmst.R +++ b/R/rmst.R @@ -26,8 +26,8 @@ #' @param beta Power (`NULL` to compute power or strictly between #' 0 and `1 - alpha` otherwise). #' @param test A string specifies the type of statistical test. -#' Default is `"survival difference"` (a Kaplan-Meier based test). -#' One can also set it as `"rmst difference"` (another Kaplan-Meier based test). +#' - `"survival difference"` (default): a Kaplan-Meier based test. +#' -`"rmst difference"`: another Kaplan-Meier based test. #' @param tau Desired milestone for `test = "survival difference"` or #' `test = "rmst difference"`. #' @@ -57,8 +57,16 @@ fixed_design_size_rmst <- function(enroll_rate, ratio = 1, alpha = 0.025, beta = 0.1, - test = "rmst difference", + test = c("survival_difference", "rmst_difference"), tau = NULL) { + test <- match.arg(test) + + if (test == "survival_difference") { + test <- "survival difference" + } else if (test == "rmst_difference") { + test <- "rmst difference" + } + gs_arm <- gs_create_arm(enroll_rate, fail_rate, ratio = ratio, total_time = analysis_time) arm0 <- gs_arm[["arm0"]] arm1 <- gs_arm[["arm1"]] @@ -109,8 +117,8 @@ fixed_design_size_rmst <- function(enroll_rate, #' @param ratio Experimental:Control randomization ratio. #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param test A string specifies the type of statistical test. -#' Default is `"survival difference"` (a Kaplan-Meier based test). -#' One can also set it as `"rmst difference"` (another Kaplan-Meier based test). +#' - `"survival difference"` (default): a Kaplan-Meier based test. +#' - `"rmst difference"`: another Kaplan-Meier based test. #' @param tau Desired milestone for `test = "survival difference"` or #' `test = "rmst difference"`. #' @@ -136,8 +144,16 @@ fixed_design_power_rmst <- function(enroll_rate, analysis_time, ratio = 1, alpha = 0.025, - test = "rmst difference", + test = c("survival_difference", "rmst_difference"), tau = NULL) { + test <- match.arg(test) + + if (test == "survival_difference") { + test <- "survival difference" + } else if (test == "rmst_difference") { + test <- "rmst difference" + } + gs_arm <- gs_create_arm(enroll_rate, fail_rate, ratio = ratio, total_time = analysis_time) arm0 <- gs_arm[["arm0"]] arm1 <- gs_arm[["arm1"]] diff --git a/tests/testthat/test-independent-rmst.R b/tests/testthat/test-independent-rmst.R index bbf98cbf..a7b98243 100644 --- a/tests/testthat/test-independent-rmst.R +++ b/tests/testthat/test-independent-rmst.R @@ -12,7 +12,9 @@ test_that("given sample size, the output power arrives at the target", { ) # output from gsDesign2 - x1 <- fixed_design_size_rmst(enroll_rate, fail_rate, ratio = 1, analysis_time = 36, alpha = 0.025) + x1 <- gsDesign2:::fixed_design_size_rmst(enroll_rate, fail_rate, + ratio = 1, analysis_time = 36, + alpha = 0.025, test = "rmst_difference") # output from npsurvSS gs_arm <- gs_create_arm(enroll_rate, fail_rate, ratio = 1, total_time = 36) @@ -28,6 +30,7 @@ test_that("given sample size, the output power arrives at the target", { expect_equal(x1$bound$probability, x2) }) + test_that("given power, the output sample size arrives at the target power", { # set enrollment rates enroll_rate <- tibble::tibble(stratum = "All", duration = 12, rate = 500 / 12) @@ -42,7 +45,9 @@ test_that("given power, the output sample size arrives at the target power", { ) # output from gsDesign2 - x1 <- fixed_design_power_rmst(enroll_rate, fail_rate, analysis_time = 36) + x1 <- fixed_design_power_rmst(enroll_rate, fail_rate, + analysis_time = 36, + test = "rmst_difference") # output from npsurvSS gs_arm <- gs_create_arm(enroll_rate, fail_rate, ratio = 1, total_time = 36)