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

update the match.arg #212

Merged
merged 13 commits into from
Apr 16, 2023
9 changes: 5 additions & 4 deletions R/fixed_design.R
Original file line number Diff line number Diff line change
Expand Up @@ -547,15 +547,15 @@ 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 {
d <- fixed_design_power_rmst(
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)
)
}
Expand Down Expand Up @@ -583,15 +583,15 @@ 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 {
d <- fixed_design_power_rmst(
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)
)
}
Expand All @@ -615,6 +615,7 @@ fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", "
}
)


class(y) <- c("fixed_design", class(y))
return(y)
}
28 changes: 22 additions & 6 deletions R/rmst.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"`.
#'
Expand Down Expand Up @@ -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"]]
Expand Down Expand Up @@ -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"`.
#'
Expand All @@ -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"]]
Expand Down
9 changes: 7 additions & 2 deletions tests/testthat/test-independent-rmst.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down