From ea6b14456a29306d5e9e727625acd365fee543b7 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:56:54 -0400 Subject: [PATCH 01/30] `fixed_design` -> `fixed_design_ahr` --- R/fixed_design_ahr.R | 128 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 R/fixed_design_ahr.R diff --git a/R/fixed_design_ahr.R b/R/fixed_design_ahr.R new file mode 100644 index 00000000..06711c46 --- /dev/null +++ b/R/fixed_design_ahr.R @@ -0,0 +1,128 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for AHR methods. +#' Returns a tibble with a basic summary. +#' +#' @inheritParams gs_design_ahr +#' @inheritParams gs_power_ahr +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param study_duration Study duration. +#' +#' @return A table. +#' +#' @export +#' +#' @examples +#' library(dplyr) +#' +#' # example 1: given power and compute sample size +#' x <- fixed_design_ahr( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36 +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_ahr( +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36 +#' ) +#' x %>% summary() +fixed_design_ahr <- function(alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + event = NULL + ) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + enroll_rate = enroll_rate, + fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + if (is.null(power)) { + d <- gs_power_ahr( + upar = qnorm(1 - alpha), lpar = -Inf, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + ratio = ratio, + analysis_time = study_duration, + event = event + ) + } else { + d <- gs_design_ahr( + alpha = alpha, beta = 1 - power, + upar = qnorm(1 - alpha), lpar = -Inf, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + ratio = ratio, + analysis_time = study_duration + ) + } + + ans <- tibble::tibble( + design = "ahr", + n = d$analysis$n, + event = d$analysis$event, + time = d$analysis$time, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, enroll_rate = d$enroll_rate, + fail_rate = d$fail_rate, analysis = ans, design = "ahr" + ) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From c0bbcdf314ccba608a09f1f2a74d45d5bdcd25be Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:57:20 -0400 Subject: [PATCH 02/30] `fixed_design` -> `fixed_design_fh` --- R/fixed_design_fh.R | 146 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 R/fixed_design_fh.R diff --git a/R/fixed_design_fh.R b/R/fixed_design_fh.R new file mode 100644 index 00000000..8cbd1eb9 --- /dev/null +++ b/R/fixed_design_fh.R @@ -0,0 +1,146 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for Fleming-Harrington method. +#' Returns a tibble with a basic summary. +#' @inheritParams gs_design_wlr +#' @inheritParams gs_power_wlr +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param study_duration Study duration. +#' @param rho test parameter in Fleming-Harrington method. +#' @param gamma test parameter in Fleming-Harrington method. +#' +#' @return A table. +#' +#' @export +#' +#' @examples +#' library(dplyr) +#' +#' # example 1: given power and compute sample size +#' x <- fixed_design_fh( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' rho = 1, gamma = 1 +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_fh( +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' rho = 1, gamma = 1 +#' ) +#' x %>% summary() +fixed_design_fh <- function(alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + rho = 0, + gamma = 0) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + + # check test parameters, like rho, gamma + if (length(rho) > 1) { + stop("fixed_design_fh: multiple rho can not be used in Fleming-Harrington method!") + } + if (length(gamma) > 1) { + stop("fixed_design_fh: multiple gamma can not be used in Fleming-Harrington method!") + } + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + rho = rho, gamma = gamma, + enroll_rate = enroll_rate, + fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + weight <- function(x, arm0, arm1) { + wlr_weight_fh(x, arm0, arm1, rho = rho, gamma = gamma) + } + + if (is.null(power)) { + d <- gs_power_wlr( + upar = qnorm(1 - alpha), lpar = -Inf, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + ratio = ratio, + weight = weight, + analysis_time = study_duration, + event = NULL) + } else { + d <- gs_design_wlr( + alpha = alpha, beta = 1 - power, + upar = qnorm(1 - alpha), lpar = -Inf, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + ratio = ratio, + weight = weight, + analysis_time = study_duration + ) + } + + ans <- tibble::tibble( + design = "fh", + n = d$analysis$n, + event = d$analysis$event, + time = d$analysis$time, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, + analysis = ans, + design = "fh", design_par = list(rho = rho,gamma = gamma) + ) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From dc9041136bf9385339834a5920b0eac2af9785e3 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:57:34 -0400 Subject: [PATCH 03/30] `fixed_design` -> `fixed_design_lf` --- R/fixed_design_lf.R | 219 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 R/fixed_design_lf.R diff --git a/R/fixed_design_lf.R b/R/fixed_design_lf.R new file mode 100644 index 00000000..c8735dce --- /dev/null +++ b/R/fixed_design_lf.R @@ -0,0 +1,219 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for Lachin-Foulkes method. +#' Returns a tibble with a basic summary. +#' +#' @param alpha One-sided Type I error (strictly between 0 and 1). +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param ratio Experimental:Control randomization ratio. +#' @param study_duration Study duration. +#' @inheritParams gs_design_ahr +#' +#' @return A table. +#' +#' @export +#' +#' @examples +#' library(dplyr) +#' +#' # example 1: given power and compute sample size +#' x <- fixed_design_lf( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = 100, +#' fail_rate = log(2) / 12, +#' hr = .7, +#' dropout_rate = .001 +#' ), +#' study_duration = 36 +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_fh( +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = 100, +#' fail_rate = log(2) / 12, +#' hr = .7, +#' dropout_rate = .001 +#' ), +#' study_duration = 36 +#' ) +#' x %>% summary() +fixed_design_lf <- function(alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate + ) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + enroll_rate = enroll_rate, + fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + # check if it is stratum + n_stratum1 <- length(unique(enroll_rate$stratum)) + n_stratum2 <- length(unique(fail_rate$stratum)) + if (n_stratum1 != n_stratum2) { + stop("The number of strata does not match in the enrollment/failrate.") + } else { + n_stratum <- n_stratum1 + } + + if (n_stratum == 1) { + m <- length(fail_rate$fail_rate) + lambda_cc <- fail_rate$fail_rate + etaa <- fail_rate$dropout_rate + gammaa <- enroll_rate$rate + rr <- enroll_rate$duration + if (m == 1) { + ss <- NULL + } else { + ss <- fail_rate$duration[1:(m - 1)] + } + } else { + warning("Lachin-Foulkes is not recommended for stratified designs!") + + temp <- fail_rate %>% + group_by(stratum) %>% + summarize(n_duration = n()) + # calculate the S: duration of piecewise constant event rates + if (all(temp$n_duration == 1)) { + ss <- cbind(NULL, NULL) + } else { + stratified_duration <- fail_rate %>% + select(stratum, duration) %>% + tidyr::pivot_wider(names_from = stratum, values_from = duration, values_fn = list) + + ss <- do.call(cbind, lapply(stratified_duration, function(x) { + x %>% unlist() + })) %>% + as.matrix() + } + + # calculate the lambdaC: event hazard rates for the control group + stratified_lambdac <- fail_rate %>% + select(stratum, fail_rate) %>% + tidyr::pivot_wider(names_from = stratum, values_from = fail_rate, values_fn = list) + + lambda_cc <- do.call(cbind, lapply(stratified_lambdac, function(x) { + x %>% unlist() + })) %>% + as.matrix() + + # calculate the eta: dropout hazard rates for the control group + stratified_eta <- fail_rate %>% + select(stratum, dropout_rate) %>% + tidyr::pivot_wider(names_from = stratum, values_from = dropout_rate, values_fn = list) + + etaa <- do.call(cbind, lapply(stratified_eta, function(x) { + x %>% unlist() + })) %>% + as.matrix() + + # calculate the gamma: rates of entry by time period (rows) and strata (columns) + stratified_enroll_rate <- enroll_rate %>% + select(stratum, rate) %>% + tidyr::pivot_wider(names_from = stratum, values_from = rate, values_fn = list) + + gammaa <- do.call(cbind, lapply(stratified_enroll_rate, function(x) { + x %>% unlist() + })) %>% + as.matrix() + + # calculate the R: duration of time periods for recruitment rates specified in rows of gamma + stratified_enroll_duration <- enroll_rate %>% + select(stratum, duration) %>% + tidyr::pivot_wider(names_from = stratum, values_from = duration, values_fn = list) + + rr <- do.call(cbind, lapply(stratified_enroll_duration, function(x) { + x %>% unlist() + })) %>% + as.matrix() + } + + # calculate the ahr as the hr in nSurv + dd <- ahr(enroll_rate = enroll_rate, fail_rate = fail_rate, total_duration = study_duration, ratio = ratio) + + # use nSuve to develop the design + d <- gsDesign::nSurv( + alpha = alpha, beta = if (is.null(power)) { + NULL + } else { + 1 - power + }, + ratio = ratio, hr = dd$ahr, + # fail_rate + lambdaC = lambda_cc, + S = ss, eta = etaa, + # enroll_rate + gamma = gammaa, R = if (n_stratum == 1) { + rr + } else { + rr[, 1] + }, + T = study_duration, minfup = study_duration - sum(if (n_stratum == 1) { + rr + } else { + rr[, 1] + }) + ) + + ans <- tibble::tibble( + design = "lf", + n = d$n, + event = d$d, + time = d$T, + bound = qnorm(1 - alpha), + alpha = d$alpha, + power = d$power + ) + + y <- list( + input = input, + enroll_rate = enroll_rate %>% mutate(rate = rate * d$n / sum(enroll_rate$duration * enroll_rate$rate)), + fail_rate = fail_rate, + analysis = ans, + design = "lf" + ) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From 5766e7902d073cfc7348a5ba6b375b43e660d785 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:57:47 -0400 Subject: [PATCH 04/30] `fixed_design` -> `fixed_design_maxcombo` --- R/fixed_design_maxcombo.R | 147 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 R/fixed_design_maxcombo.R diff --git a/R/fixed_design_maxcombo.R b/R/fixed_design_maxcombo.R new file mode 100644 index 00000000..780f34f7 --- /dev/null +++ b/R/fixed_design_maxcombo.R @@ -0,0 +1,147 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for many sample size methods. +#' Returns a tibble with a basic summary. +#' +#' +#' @param alpha One-sided Type I error (strictly between 0 and 1). +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param ratio Experimental:Control randomization ratio. +#' @param study_duration Study duration. +#' @param rho A vector of numbers paring with gamma and tau for maxcombo test. +#' @param gamma A vector of numbers paring with rho and tau for maxcombo test. +#' @param tau A vector of numbers paring with gamma and rho for maxcombo test. +#' @inheritParams gs_design_combo +#' +#' @return A table. +#' @export +#' +#' @examples +#' library(dplyr) +#' +#' # example 1: given power and compute sample size +#' x <- fixed_design_maxcombo( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' rho = c(0, 0.5), gamma = c(0, 0), tau = c(-1, -1) +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_maxcombo( +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' rho = c(0, 0.5), gamma = c(0, 0), tau = c(-1, -1) +#' ) +#' x %>% summary() +fixed_design_maxcombo <- function(alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + rho = c(0, 0, 1), + gamma = c(0, 1, 0), + tau = rep(-1, 3)) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + rho = rho, gamma = gamma, tau = tau, + enroll_rate = enroll_rate, + fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + # organize the tests in MaxCombo + max_combo_test <- data.frame( + rho = rho, + gamma = gamma, + tau = tau + ) %>% + mutate(test = seq(1, length(rho)), analysis = 1, analysis_time = study_duration) + + # check if power is NULL or not + if (is.null(power)) { + d <- gs_power_combo( + ratio = ratio, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + fh_test = max_combo_test, + upper = gs_b, upar = qnorm(1 - alpha), + lower = gs_b, lpar = -Inf + ) + } else { + d <- gs_design_combo( + alpha = alpha, beta = 1 - power, ratio = ratio, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + fh_test = max_combo_test, + upper = gs_b, upar = qnorm(1 - alpha), + lower = gs_b, lpar = -Inf + ) + } + + # get the output of MaxCombo + ans <- tibble::tibble( + design = "maxcombo", + n = d$analysis$n, + event = d$analysis$event, + time = d$analysis$time, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, + enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, + design = "maxcombo", design_par = list(rho = rho, gamma = gamma, tau = tau) + ) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From 13e343bbb9e1d0a120225768aecbd981871bc123 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:57:59 -0400 Subject: [PATCH 05/30] `fixed_design` -> `fixed_design_mb` --- R/fixed_design_mb.R | 142 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 R/fixed_design_mb.R diff --git a/R/fixed_design_mb.R b/R/fixed_design_mb.R new file mode 100644 index 00000000..8a703bbe --- /dev/null +++ b/R/fixed_design_mb.R @@ -0,0 +1,142 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for Magirr-Burman method. +#' Returns a tibble with a basic summary. +#' @inheritParams gs_design_wlr +#' @inheritParams gs_power_wlr +#' +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param ratio Experimental:Control randomization ratio. +#' @param study_duration Study duration. +#' @param tau Test parameter of Magirr-Burman method. +#' +#' @return A table. +#' @export +#' +#' @examples +#' library(dplyr) +#' +#' # example 1: given power and compute sample size +#' x <- fixed_design_mb( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' tau = 4 +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_mb( +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = c(4, 100), +#' fail_rate = log(2) / 12, +#' hr = c(1, .6), +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' tau = 4 +#' ) +#' x %>% summary() +fixed_design_mb <- function(alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + tau = 6) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + + if (length(tau) > 1) { + stop("fixed_design: multiple tau can not be used in Magirr-Burman method!") + } + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + tau = tau, + enroll_rate = enroll_rate, + fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + weight <- function(x, arm0, arm1) { + wlr_weight_fh(x, arm0, arm1, rho = -1, gamma = 0, tau = tau) + } + + if (is.null(power)) { + d <- gs_power_wlr( + enroll_rate = enroll_rate, + fail_rate = fail_rate, + ratio = 1, + weight = weight, + upper = gs_b, upar = qnorm(1 - alpha), + lower = gs_b, lpar = -Inf, + analysis_time = study_duration, + event = NULL) + } else { + d <- gs_design_wlr( + alpha = alpha, + beta = 1 - power, + enroll_rate = enroll_rate, + fail_rate = fail_rate, + ratio = 1, + weight = weight, + upper = gs_b, upar = qnorm(1 - alpha), + lower = gs_b, lpar = -Inf, + analysis_time = study_duration) + } + + # get the output of MB + ans <- tibble::tibble( + design = "mb", + n = d$analysis$n, + event = d$analysis$event, + time = d$analysis$time, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, + design = "mb", design_par = list(tau = tau)) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From 3f903b69d7bbc3de2e5f538c7452f25160e7cef0 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:58:16 -0400 Subject: [PATCH 06/30] `fixed_design` -> `fixed_design_milestone` --- R/fixed_design_milestone.R | 132 +++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 R/fixed_design_milestone.R diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R new file mode 100644 index 00000000..bab8d8b8 --- /dev/null +++ b/R/fixed_design_milestone.R @@ -0,0 +1,132 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for milestone method. +#' Returns a tibble with a basic summary. +#' +#' @param alpha One-sided Type I error (strictly between 0 and 1). +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param ratio Experimental:Control randomization ratio. +#' @param study_duration Study duration. +#' @param tau Test parameter of milestone method. +#' +#' @return A table. +#' +#' @export +#' +#' @examples +#' library(dplyr) +#'# example 1: given power and compute sample size +#' x <- fixed_design( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = 100, +#' fail_rate = log(2) / 12, +#' hr = .7, +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' tau = 18 +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design( +#' "milestone", +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = 100, +#' fail_rate = log(2) / 12, +#' hr = .7, +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' tau = 18 +#' ) +#' x %>% summary() +fixed_design_milestone <- function(alpha = 0.025, + power = NULL, + ratio = 1, + enroll_rate, + fail_rate, + study_duration = 36, + tau = NULL) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + if(is.null(tau)){ + tau <- study_duration + } + if(!is.numeric(tau) | length(tau) > 1){ + stop("fixed_design_milestone: tau should a scaler.") + } + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + tau = tau, enroll_rate = enroll_rate, fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + if (is.null(power)) { + d <- fixed_design_power_rmst( + alpha = alpha, ratio = ratio, + enroll_rate = enroll_rate, fail_rate = fail_rate, + analysis_time = study_duration, + test = "survival_difference", + tau = tau) + } else { + d <- fixed_design_size_rmst( + alpha = alpha, beta = 1 - power, ratio = ratio, + enroll_rate = enroll_rate, fail_rate = fail_rate, + analysis_time = study_duration, + test = "survival_difference", + tau = tau) + } + + # get the output of MaxCombo + ans <- tibble::tibble( + design = "milestone", + n = d$analysis$n, + event = d$analysis$event, + time = d$analysis$time, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, + enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, + design = "milestone", design_par = list(tau = tau) + ) + class(y) <- c("fixed_design", class(y)) + return(y) +} From 53b6df193c126c9690a3f9e435e58f618c286339 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:58:27 -0400 Subject: [PATCH 07/30] `fixed_design` -> `fixed_design_rd` --- R/fixed_design_rd.R | 119 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 R/fixed_design_rd.R diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R new file mode 100644 index 00000000..0b243506 --- /dev/null +++ b/R/fixed_design_rd.R @@ -0,0 +1,119 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for risk difference under unstratified design. +#' Returns a tibble with a basic summary. +#' +#' @param alpha One-sided Type I error (strictly between 0 and 1). +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param p_c A numerical value of the control arm rate. +#' @param p_e A numerical value of the experimental arm rate. +#' @param rd0 Risk difference under null hypothesis, default is 0. +#' @param n Sample size. If NULL with power input, the sample size will be +#' computed to achieve the targeted power +#' @param ratio Experimental:Control randomization ratio. +#' +#' @return A table. +#' @export +#' +#' @examples +#' library(dplyr) +#' +#' # example 1: given power and compute sample size +#' x <- fixed_design_rd( +#' alpha = alpha, power = 1 - beta, p_c = .15, p_e = .1, +#' rd0 = 0, ratio = 1) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_rd( +#' alpha = alpha, power = NULL, p_c = .15, p_e = .1, +#' rd0 = 0, n = 2000, ratio = 1) +#' x %>% summary() +fixed_design_rd <- function(alpha = 0.025, + power = NULL, + ratio = 1, + p_c, + p_e, + rd0 = 0, + n = NULL) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + if(!is.numeric(p_c) | !is.numeric(p_e)){ + stop("fixed_design_rd: p_c and p_e should be numerical values.") + } + if(length(p_c) > 1 | length(p_e) > 1){ + stop("fixed_design_rd: p_c and p_e should be a scaler.") + } + if(!is.null(n) & !is.numeric(n) ){ + stop("fixed_design_rd: n should be numerical values.") + } + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, + p_c = p_c, p_e = p_e, n = n + ) + + # ------------------------- # + # generate design # + # ------------------------- # + if (is.null(power)) { + d <- gs_power_rd( + p_c = tibble::tibble(stratum = "All", rate = p_c), + p_e = tibble::tibble(stratum = "All", rate = p_e), + ratio = ratio, + upper = gs_b, upar = qnorm(1 - alpha), + lower = gs_b, lpar = -Inf, + n = tibble::tibble(stratum = "All", n = n, analysis = 1), + rd0 = rd0, weight = "unstratified" + ) + } else { + d <- gs_design_rd( + p_c = tibble::tibble(stratum = "All", rate = p_c), + p_e = tibble::tibble(stratum = "All", rate = p_e), + alpha = alpha, beta = 1 - power, ratio = ratio, + upper = gs_b, upar = qnorm(1 - alpha), + lower = gs_b, lpar = -Inf, + rd0 = rd0, weight = "unstratified" + ) + } + + # get the output of MaxCombo + ans <- tibble::tibble( + design = "rd", + n = d$analysis$n, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, + enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "rd" + ) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From 694395d2aaa7f1fe1d1da5c7225b44db044923e4 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:58:41 -0400 Subject: [PATCH 08/30] `fixed_design` -> `fixed_design_rmst` --- R/fixed_design_rmst.R | 131 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 R/fixed_design_rmst.R diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R new file mode 100644 index 00000000..a04558a6 --- /dev/null +++ b/R/fixed_design_rmst.R @@ -0,0 +1,131 @@ +# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. +# All rights reserved. +# +# This file is part of the gsDesign2 program. +# +# gsDesign2 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#' Fixed design sample size +#' +#' Computes fixed design sample size for RMST methods. +#' Returns a tibble with a basic summary. +#' +#' @param alpha One-sided Type I error (strictly between 0 and 1). +#' @param power Power (`NULL` to compute power or strictly between 0 +#' and `1 - alpha` otherwise). +#' @param ratio Experimental:Control randomization ratio. +#' @param study_duration Study duration. +#' @param tau Test parameter in RMST. +#' @return A table. +#' @export +#' +#' @examples +#' library(dplyr) +#' # example 1: given power and compute sample size +#' x <- fixed_design_rmst( +#' alpha = .025, power = .9, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), +#' fail_rate = define_fail_rate( +#' duration = 100, +#' fail_rate = log(2) / 12, +#' hr = .7, +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' tau = 18 +#' ) +#' x %>% summary() +#' +#' # example 2: given sample size and compute power +#' x <- fixed_design_rmst( +#' alpha = .025, +#' enroll_rate = define_enroll_rate(duration = 18, rate = 20), +#' fail_rate = define_fail_rate( +#' duration = 100, +#' fail_rate = log(2) / 12, +#' hr = .7, +#' dropout_rate = .001 +#' ), +#' study_duration = 36, +#' tau = 18 +#' ) +#' x %>% summary() +fixed_design_rmst <- function(alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + tau = NULL) { + # --------------------------------------------- # + # check inputs # + # --------------------------------------------- # + check_enroll_rate(enroll_rate) + check_fail_rate(fail_rate) + check_enroll_rate_fail_rate(enroll_rate, fail_rate) + if(is.null(tau)){ + tau <- study_duration + } + if(!is.numeric(tau) | length(tau) > 1){ + stop("fixed_design_rmst: tau should a scaler.") + } + + # ------------------------- # + # save inputs # + # ------------------------- # + input <- list( + alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, + tau = tau, enroll_rate = enroll_rate, fail_rate = fail_rate + ) + + # ------------------------- # + # generate design # + # ------------------------- # + if (is.null(power)) { + d <- fixed_design_power_rmst( + alpha = alpha, ratio = ratio, + enroll_rate = enroll_rate, fail_rate = fail_rate, + analysis_time = study_duration, + test = "rmst_difference", + tau = tau + ) + } else { + d <- fixed_design_size_rmst( + alpha = alpha, beta = 1 - power, ratio = ratio, + enroll_rate = enroll_rate, fail_rate = fail_rate, + analysis_time = study_duration, + test = "rmst_difference", + tau = tau + ) + } + # get the output + ans <- tibble::tibble( + design = "rmst", + n = d$analysis$n, + event = d$analysis$event, + time = d$analysis$time, + bound = (d$bound %>% filter(bound == "upper"))$z, + alpha = alpha, + power = (d$bound %>% filter(bound == "upper"))$probability + ) + + y <- list( + input = input, + enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, + design = "rmst", design_par = list(tau = tau), study_duration + ) + + class(y) <- c("fixed_design", class(y)) + return(y) +} From 2b94a6ffd7b89565e614004fd01f5a57ebbeccd8 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:58:57 -0400 Subject: [PATCH 09/30] delete `fixed_design` --- R/fixed_design.R | 693 ----------------------------------------------- 1 file changed, 693 deletions(-) delete mode 100644 R/fixed_design.R diff --git a/R/fixed_design.R b/R/fixed_design.R deleted file mode 100644 index 3fe19317..00000000 --- a/R/fixed_design.R +++ /dev/null @@ -1,693 +0,0 @@ -# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. -# All rights reserved. -# -# This file is part of the gsDesign2 program. -# -# gsDesign2 is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -#' Fixed design sample size -#' -#' Computes fixed design sample size for many sample size methods. -#' Returns a tibble with a basic summary. -#' -#' @param method Sample size method. Default is `"ahr"`. -#' Other options include `"fh"`, `"mb"`, `"lf"`, `"rd"`, -#' `"maxcombo"`, `"milestone"`. -#' @param alpha One-sided Type I error (strictly between 0 and 1). -#' @param power Power (`NULL` to compute power or strictly between 0 -#' and `1 - alpha` otherwise). -#' @param ratio Experimental:Control randomization ratio. -#' @param study_duration Study duration. -#' @param ... Additional arguments like `enroll_rate`, `fail_rate`, -#' `rho`, `gamma`, `tau`. -#' -#' @return A table. -#' -#' @export -#' -#' @examples -#' library(dplyr) -#' -#' # Average hazard ratio -#' x <- fixed_design( -#' "ahr", -#' alpha = .025, power = .9, -#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), -#' fail_rate = define_fail_rate( -#' duration = c(4, 100), -#' fail_rate = log(2) / 12, -#' hr = c(1, .6), -#' dropout_rate = .001 -#' ), -#' study_duration = 36 -#' ) -#' x %>% summary() -#' -#' # Lachin and Foulkes (uses gsDesign::nSurv()) -#' x <- fixed_design( -#' "lf", -#' alpha = .025, power = .9, -#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), -#' fail_rate = define_fail_rate( -#' duration = 100, -#' fail_rate = log(2) / 12, -#' hr = .7, -#' dropout_rate = .001 -#' ), -#' study_duration = 36 -#' ) -#' x %>% summary() -#' -#' # RMST -#' x <- fixed_design( -#' "rmst", -#' alpha = .025, power = .9, -#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), -#' fail_rate = define_fail_rate( -#' duration = 100, -#' fail_rate = log(2) / 12, -#' hr = .7, -#' dropout_rate = .001 -#' ), -#' study_duration = 36, -#' tau = 18 -#' ) -#' x %>% summary() -#' -#' # Milestone -#' x <- fixed_design( -#' "milestone", -#' alpha = .025, power = .9, -#' enroll_rate = define_enroll_rate(duration = 18, rate = 1), -#' fail_rate = define_fail_rate( -#' duration = 100, -#' fail_rate = log(2) / 12, -#' hr = .7, -#' dropout_rate = .001 -#' ), -#' study_duration = 36, -#' tau = 18 -#' ) -#' x %>% summary() -fixed_design <- function(method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", "rmst", "milestone"), - alpha = 0.025, - power = NULL, - ratio = 1, - study_duration = 36, - ...) { - # --------------------------------------------- # - # check inputs # - # --------------------------------------------- # - x <- match.arg(method) - args <- list(...) - - has_weight <- "weight" %in% names(args) - has_rho <- "rho" %in% names(args) - has_gamma <- "gamma" %in% names(args) - has_tau <- "tau" %in% names(args) - has_enroll_rate <- "enroll_rate" %in% names(args) - has_fail_rate <- "fail_rate" %in% names(args) - has_event <- "event" %in% names(args) - has_n <- "n" %in% names(args) - - # ------------------------- # - # check inputs # - # ------------------------- # - # check enrollment rate (not expected for RD) - if (!has_enroll_rate && x != "rd") { - stop("fixed_design: please input enroll_rate!") - } else { - enroll_rate <- args$enroll_rate - } - - # check failure rate (not expected for RD) - if (!has_fail_rate && x != "rd") { - stop("fixed_design: please input fail_rate!") - } else { - fail_rate <- args$fail_rate - } - - # check test parameters, like rho, gamma, tau - if (has_rho && length(args$rho) > 1 && x %in% c("fh", "mb")) { - stop("fixed_design: multiple rho can not be used in Fleming-Harrington or Magirr-Burman method!") - } - if (has_gamma && length(args$gamma) > 1 && x %in% c("fh", "mb")) { - stop("fixed_design: multiple gamma can not be used in Fleming-Harrington or Magirr-Burman method!") - } - if (has_tau && length(args$tau) > 1 && x %in% c("fh", "mb")) { - stop("fixed_design: multiple tau can not be used in Fleming-Harrington or Magirr-Burman method!") - } - if (has_tau && x == "fh") { - stop("fixed_design: tau is not needed for Fleming-Harrington (FH) method!") - } - if (has_rho && has_gamma && x == "mb") { - stop("fixed_design: rho and gamma are not needed for Magirr-Burman (MB) method!") - } - - # check inputs necessary for RD - if (x == "rd") { - if (!"p_c" %in% names(args)) { - stop("fixed_design: p_c is needed for RD!") - } - if (!"p_e" %in% names(args)) { - stop("fixed_design: p_e is needed for RD!") - } - if (!"rd0" %in% names(args)) { - stop("fixed_design: rd0 is needed for RD!") - } - if (is.null(power) && !has_n) { - stop("fixed_design: sample size n = ... is needed for RD!") - } - } - - # ------------------------- # - # save inputs # - # ------------------------- # - input <- list( - alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, - weight = if (has_weight) { - args$weight - } else { - NULL - }, - rho = if (has_rho) { - args$rho - } else { - NULL - }, - gamma = if (has_gamma) { - args$gamma - } else { - NULL - }, - tau = if (has_tau) { - args$tau - } else { - NULL - }, - enroll_rate = if (has_enroll_rate) { - args$enroll_rate - } else { - NULL - }, - fail_rate = if (has_fail_rate) { - args$fail_rate - } else { - NULL - }, - n = if (has_n) { - args$n - } else { - NULL - } - ) - - # ------------------------- # - # generate design # - # ------------------------- # - y <- switch(x, - "ahr" = { - if (!is.null(power)) { - d <- gs_design_ahr( - alpha = alpha, beta = 1 - power, - upar = qnorm(1 - alpha), lpar = -Inf, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - ratio = ratio, - analysis_time = study_duration - ) - } else { - d <- gs_power_ahr( - upar = qnorm(1 - alpha), lpar = -Inf, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - ratio = ratio, - analysis_time = study_duration, - event = if (has_event) { - args$event - } else { - NULL - } - ) - } - ans <- tibble::tibble( - design = "ahr", - n = d$analysis$n, - event = d$analysis$event, - time = d$analysis$time, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, enroll_rate = d$enroll_rate, - fail_rate = d$fail_rate, analysis = ans, design = "ahr" - ) - }, - "fh" = { - if (has_weight + has_rho + has_gamma == 0) { - weight <- function(x, arm0, arm1) { - wlr_weight_fh(x, arm0, arm1, rho = 0, gamma = 0.5) - } - } - if (has_weight == 0 & has_rho + has_gamma >= 1) { - weight <- function(x, arm0, arm1) { - wlr_weight_fh(x, arm0, arm1, - rho = ifelse(has_rho, args$rho, 0), - gamma = ifelse(has_gamma, args$gamma, 0.5) - ) - } - } - if (!is.null(power)) { - d <- gs_design_wlr( - alpha = alpha, beta = 1 - power, - upar = qnorm(1 - alpha), lpar = -Inf, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - ratio = ratio, - weight = weight, - analysis_time = study_duration - ) - } else { - d <- gs_power_wlr( - upar = qnorm(1 - alpha), lpar = -Inf, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - ratio = ratio, - weight = weight, - analysis_time = study_duration, - event = NULL - ) - } - ans <- tibble::tibble( - design = "fh", - n = d$analysis$n, - event = d$analysis$event, - time = d$analysis$time, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, - analysis = ans, - design = "fh", design_par = list( - rho = if (has_rho) { - args$rho - } else { - 0 - }, - gamma = if (has_gamma) { - args$gamma - } else { - 0.5 - } - ) - ) - }, - "mb" = { - # check if power is NULL or not - if (!is.null(power)) { - d <- gs_design_wlr( - alpha = alpha, - beta = 1 - power, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - ratio = 1, - weight = function(x, arm0, arm1) { - wlr_weight_fh(x, arm0, arm1, - rho = -1, gamma = 0, - tau = ifelse(has_tau, args$tau, 6) - ) - }, - upper = gs_b, - upar = qnorm(1 - alpha), - lower = gs_b, - lpar = -Inf, - analysis_time = study_duration - ) - } else { - d <- gs_power_wlr( - enroll_rate = enroll_rate, - fail_rate = fail_rate, - ratio = 1, - weight = function(x, arm0, arm1) { - wlr_weight_fh(x, arm0, arm1, - rho = -1, gamma = 0, - tau = ifelse(has_tau, args$tau, 6) - ) - }, - upper = gs_b, - upar = qnorm(1 - alpha), - lower = gs_b, - lpar = -Inf, - analysis_time = study_duration, - event = NULL - ) - } - - # get the output of MB - ans <- tibble::tibble( - design = "mb", - n = d$analysis$n, - event = d$analysis$event, - time = d$analysis$time, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, - design = "mb", design_par = list(tau = ifelse(has_tau, args$tau, 6)) - ) - }, - "lf" = { - # check if it is stratum - n_stratum1 <- length(unique(enroll_rate$stratum)) - n_stratum2 <- length(unique(fail_rate$stratum)) - if (n_stratum1 != n_stratum2) { - stop("The number of strata does not match in the enrollment/failrate.") - } else { - n_stratum <- n_stratum1 - } - - if (n_stratum == 1) { - m <- length(fail_rate$fail_rate) - lambda_cc <- fail_rate$fail_rate - etaa <- fail_rate$dropout_rate - gammaa <- enroll_rate$rate - rr <- enroll_rate$duration - if (m == 1) { - ss <- NULL - } else { - ss <- fail_rate$duration[1:(m - 1)] - } - } else { - warning("Lachin-Foulkes is not recommended for stratified designs!") - - temp <- fail_rate %>% - group_by(stratum) %>% - summarize(n_duration = n()) - # calculate the S: duration of piecewise constant event rates - if (all(temp$n_duration == 1)) { - ss <- cbind(NULL, NULL) - } else { - stratified_duration <- fail_rate %>% - select(stratum, duration) %>% - tidyr::pivot_wider(names_from = stratum, values_from = duration, values_fn = list) - - ss <- do.call(cbind, lapply(stratified_duration, function(x) { - x %>% unlist() - })) %>% - as.matrix() - } - - # calculate the lambdaC: event hazard rates for the control group - stratified_lambdac <- fail_rate %>% - select(stratum, fail_rate) %>% - tidyr::pivot_wider(names_from = stratum, values_from = fail_rate, values_fn = list) - - lambda_cc <- do.call(cbind, lapply(stratified_lambdac, function(x) { - x %>% unlist() - })) %>% - as.matrix() - - # calculate the eta: dropout hazard rates for the control group - stratified_eta <- fail_rate %>% - select(stratum, dropout_rate) %>% - tidyr::pivot_wider(names_from = stratum, values_from = dropout_rate, values_fn = list) - - etaa <- do.call(cbind, lapply(stratified_eta, function(x) { - x %>% unlist() - })) %>% - as.matrix() - - # calculate the gamma: rates of entry by time period (rows) and strata (columns) - stratified_enroll_rate <- enroll_rate %>% - select(stratum, rate) %>% - tidyr::pivot_wider(names_from = stratum, values_from = rate, values_fn = list) - - gammaa <- do.call(cbind, lapply(stratified_enroll_rate, function(x) { - x %>% unlist() - })) %>% - as.matrix() - - # calculate the R: duration of time periods for recruitment rates specified in rows of gamma - stratified_enroll_duration <- enroll_rate %>% - select(stratum, duration) %>% - tidyr::pivot_wider(names_from = stratum, values_from = duration, values_fn = list) - - rr <- do.call(cbind, lapply(stratified_enroll_duration, function(x) { - x %>% unlist() - })) %>% - as.matrix() - } - - # calculate the ahr as the hr in nSurv - dd <- ahr(enroll_rate = enroll_rate, fail_rate = fail_rate, total_duration = study_duration, ratio = ratio) - - # use nSuve to develop the design - d <- gsDesign::nSurv( - alpha = alpha, beta = if (is.null(power)) { - NULL - } else { - 1 - power - }, - ratio = ratio, hr = dd$ahr, - # fail_rate - lambdaC = lambda_cc, - S = ss, eta = etaa, - # enroll_rate - gamma = gammaa, R = if (n_stratum == 1) { - rr - } else { - rr[, 1] - }, - T = study_duration, minfup = study_duration - sum(if (n_stratum == 1) { - rr - } else { - rr[, 1] - }) - ) - - ans <- tibble::tibble( - design = "lf", - n = d$n, - event = d$d, - time = d$T, - bound = qnorm(1 - alpha), - alpha = d$alpha, - power = d$power - ) - - list( - input = input, - enroll_rate = enroll_rate %>% mutate(rate = rate * d$n / sum(enroll_rate$duration * enroll_rate$rate)), - fail_rate = fail_rate, - analysis = ans, - design = "lf" - ) - }, - "maxcombo" = { - # organize the tests in MaxCombo - max_combo_test <- data.frame( - rho = if (has_rho) { - args$rho - } else { - c(0, 0) - }, - gamma = if (has_gamma) { - args$gamma - } else { - c(0, 0.5) - }, - tau = if (has_tau) { - args$tau - } else { - -1 - } - ) %>% - mutate(test = seq(1, length(rho)), analysis = 1, analysis_time = study_duration) - - # check if power is NULL or not - if (!is.null(power)) { - d <- gs_design_combo( - alpha = alpha, beta = 1 - power, ratio = ratio, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - fh_test = max_combo_test, - upper = gs_b, upar = qnorm(1 - alpha), - lower = gs_b, lpar = -Inf - ) - } else { - d <- gs_power_combo( - ratio = ratio, - enroll_rate = enroll_rate, - fail_rate = fail_rate, - fh_test = max_combo_test, - upper = gs_b, upar = qnorm(1 - alpha), - lower = gs_b, lpar = -Inf - ) - } - - # get the output of MaxCombo - ans <- tibble::tibble( - design = "maxcombo", - n = d$analysis$n, - event = d$analysis$event, - time = d$analysis$time, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, - enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, - design = "maxcombo", design_par = list( - rho = if (has_rho) { - args$rho - } else { - c(0, 0) - }, - gamma = if (has_gamma) { - args$gamma - } else { - c(0, 0.5) - }, - tau = if (has_tau) { - args$tau - } else { - c(-1, -1) - } - ) - ) - }, - "rd" = { - if (!is.null(power)) { - d <- gs_design_rd( - p_c = tibble::tibble(stratum = "All", rate = args$p_c), - p_e = tibble::tibble(stratum = "All", rate = args$p_e), - alpha = alpha, beta = 1 - power, ratio = ratio, - upper = gs_b, upar = qnorm(1 - alpha), - lower = gs_b, lpar = -Inf, - rd0 = args$rd0, weight = "unstratified" - ) - } else { - d <- gs_power_rd( - p_c = tibble::tibble(stratum = "All", rate = args$p_c), - p_e = tibble::tibble(stratum = "All", rate = args$p_e), - ratio = ratio, - upper = gs_b, upar = qnorm(1 - alpha), - lower = gs_b, lpar = -Inf, - n = tibble::tibble(stratum = "All", n = args$n, analysis = 1), - rd0 = args$rd0, weight = "unstratified" - ) - } - - # get the output of MaxCombo - ans <- tibble::tibble( - design = "rd", - n = d$analysis$n, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, - enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "rd" - ) - }, - "rmst" = { - if (!is.null(power)) { - d <- fixed_design_size_rmst( - alpha = alpha, beta = 1 - power, ratio = ratio, - enroll_rate = enroll_rate, fail_rate = fail_rate, - analysis_time = study_duration, - 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", - tau = ifelse(has_tau, args$tau, study_duration) - ) - } - - # get the output - ans <- tibble::tibble( - design = "rmst", - n = d$analysis$n, - event = d$analysis$event, - time = d$analysis$time, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, - enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, - design = "rmst", design_par = list(tau = ifelse(has_tau, args$tau, study_duration)) - ) - }, - "milestone" = { - if (!is.null(power)) { - d <- fixed_design_size_rmst( - alpha = alpha, beta = 1 - power, ratio = ratio, - enroll_rate = enroll_rate, fail_rate = fail_rate, - analysis_time = study_duration, - 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", - tau = ifelse(has_tau, args$tau, study_duration) - ) - } - - # get the output of MaxCombo - ans <- tibble::tibble( - design = "milestone", - n = d$analysis$n, - event = d$analysis$event, - time = d$analysis$time, - bound = (d$bound %>% filter(bound == "upper"))$z, - alpha = alpha, - power = (d$bound %>% filter(bound == "upper"))$probability - ) - - list( - input = input, - enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, - design = "milestone", design_par = list(tau = ifelse(has_tau, args$tau, study_duration)) - ) - } - ) - - - class(y) <- c("fixed_design", class(y)) - return(y) -} From d6c61fa2939b8365136f77c701eb6630a47a4f3d Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:59:14 -0400 Subject: [PATCH 10/30] update a warning in `as_gt` --- R/as_gt.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/as_gt.R b/R/as_gt.R index db6cec2e..1d897fd9 100644 --- a/R/as_gt.R +++ b/R/as_gt.R @@ -153,14 +153,14 @@ as_gt.fixed_design <- function(x, title = NULL, footnote = NULL, ...) { "fh" = { paste0( "Power for Fleming-Harrington test ", - substr(x$design, 19, nchar(x$design)), + substr(x$Design, 19, nchar(x$Design)), " using method of Yung and Liu." ) }, "mb" = { paste0( "Power for ", - x$design, + x$Design, " computed with method of Yung and Liu." ) }, @@ -174,20 +174,19 @@ as_gt.fixed_design <- function(x, title = NULL, footnote = NULL, ...) { "maxcombo" = { paste0( "Power for MaxCombo test with Fleming-Harrington tests", - substr(x$design, 9, nchar(x$design)), "." + substr(x$Design, 9, nchar(x$Design)), "." ) }, "milestone" = { - paste0("Power for ", x$design, " computed with method of Yung and Liu.") + paste0("Power for ", x$Design, " computed with method of Yung and Liu.") }, "rmst" = { - paste0("Power for ", x$design, " computed with method of Yung and Liu.") + paste0("Power for ", x$Design, " computed with method of Yung and Liu.") } ) } ans <- x %>% - dplyr::mutate(design = design_mtd) %>% gt::gt() %>% gt::tab_header(title = title) %>% gt::tab_footnote(footnote = footnote, locations = gt::cells_title(group = "title")) From 232a2ec4375839c9f8813bcbc74785934c6bf354 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:59:38 -0400 Subject: [PATCH 11/30] update test file --- .../testthat/test-independent-fixed_design.R | 98 +++---------------- 1 file changed, 16 insertions(+), 82 deletions(-) diff --git a/tests/testthat/test-independent-fixed_design.R b/tests/testthat/test-independent-fixed_design.R index d527e9fb..d5ca7b2d 100644 --- a/tests/testthat/test-independent-fixed_design.R +++ b/tests/testthat/test-independent-fixed_design.R @@ -18,78 +18,14 @@ study_duration <- 36 # Experimental / Control randomization ratio ratio <- 1 -test_that("input checking", { - # miss enroll_rate - expect_error( - fixed_design( - "ahr", - alpha = 0.025, - power = 0.9, - fail_rate = fail_rate, - study_duration = study_duration, - ratio = ratio - ) - ) - - # miss fail_rate - expect_error( - fixed_design( - "ahr", - alpha = 0.025, - power = 0.9, - enroll_rate = enroll_rate, - study_duration = study_duration, - ratio = ratio - ) - ) - - # multiple rho for FH/MB - expect_error(fixed_design("fh", - alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duration = study_duration, ratio = ratio, rho = c(0.5, 0) - )) - expect_error(fixed_design("mb", - alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duration = study_duration, ratio = ratio, rho = c(0.5, 0) - )) - - # multiple tau for FH/MB - expect_error(fixed_design("fh", - alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duration = study_duration, ratio = ratio, tau = c(0.5, 0) - )) - expect_error(fixed_design("mb", - alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duration = study_duration, ratio = ratio, tau = c(0.5, 0) - )) - - # redundant tau in FH - expect_error(fixed_design("fh", - alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duration = study_duration, ratio = ratio, tau = 0.5 - )) - - # redundant rho/gamma in MB - expect_error(fixed_design("mb", - alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duration = study_duration, ratio = ratio, rho = 0.5, gamma = 0.5 - )) - - # p_c/p_e/rd0 not input in RD - expect_error(fixed_design("rd", alpha = 0.025, power = 0.9, p_e = 0.1, rd0 = 0, ratio = ratio)) - expect_error(fixed_design("rd", alpha = 0.025, power = 0.9, p_c = 0.1, rd0 = 0, ratio = ratio)) - expect_error(fixed_design("rd", alpha = 0.025, power = 0.9, p_c = 0.2, p_e = 0.1, ratio = ratio)) - expect_error(fixed_design("rd", alpha = 0.025, p_c = 0.2, p_e = 0.1, rd0 = 0, ratio = ratio)) -}) - test_that("AHR", { - x <- fixed_design("ahr", + x <- fixed_design_ahr( alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio ) - y <- fixed_design("ahr", + y <- fixed_design_ahr( alpha = 0.025, enroll_rate = enroll_rate %>% mutate(rate = x$analysis$n / duration), fail_rate = fail_rate, study_duration = study_duration, ratio = ratio @@ -99,14 +35,14 @@ test_that("AHR", { }) test_that("FH", { - x <- fixed_design("fh", + x <- fixed_design_fh( alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, rho = 0.5, gamma = 0.5 ) - y <- fixed_design("fh", + y <- fixed_design_fh( alpha = 0.025, enroll_rate = enroll_rate %>% mutate(rate = x$analysis$n / duration), fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, @@ -117,14 +53,14 @@ test_that("FH", { }) test_that("MB", { - x <- fixed_design("mb", + x <- fixed_design_mb( alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, tau = 8 ) - y <- fixed_design("mb", + y <- fixed_design_mb( alpha = 0.025, enroll_rate = enroll_rate %>% mutate(rate = x$analysis$n / duration), fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, @@ -135,13 +71,13 @@ test_that("MB", { }) test_that("LF", { - x <- fixed_design("lf", + x <- fixed_design_lf( alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio ) - y <- fixed_design("lf", + y <- fixed_design_lf( alpha = 0.025, enroll_rate = enroll_rate %>% mutate(rate = x$analysis$n / duration), fail_rate = fail_rate, study_duration = study_duration, ratio = ratio @@ -151,7 +87,7 @@ test_that("LF", { }) test_that("MaxCombo", { - x <- fixed_design("maxcombo", + x <- fixed_design_maxcombo( alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, @@ -160,7 +96,7 @@ test_that("MaxCombo", { tau = c(-1, 4, 6) ) - y <- fixed_design("maxcombo", + y <- fixed_design_maxcombo( alpha = 0.025, enroll_rate = enroll_rate %>% mutate(rate = x$analysis$n / duration), fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, @@ -173,14 +109,14 @@ test_that("MaxCombo", { }) test_that("RMST", { - x <- fixed_design("rmst", + x <- fixed_design_rmst( alpha = 0.025, power = 0.9, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, tau = 18 ) - y <- fixed_design("rmst", + y <- fixed_design_rmst( alpha = 0.025, enroll_rate = enroll_rate %>% mutate(rate = x$analysis$n / duration), fail_rate = fail_rate, study_duration = study_duration, ratio = ratio, @@ -191,16 +127,14 @@ test_that("RMST", { }) test_that("RD", { - x <- fixed_design("rd", + x <- fixed_design_rd( alpha = 0.025, power = 0.9, - p_c = .15, p_e = .1, rd0 = 0, ratio = ratio, - tau = 18 + p_c = .15, p_e = .1, rd0 = 0, ratio = ratio ) - y <- fixed_design("rd", + y <- fixed_design_rd( alpha = 0.025, n = x$analysis$n, - p_c = .15, p_e = .1, rd0 = 0, ratio = ratio, - tau = 18 + p_c = .15, p_e = .1, rd0 = 0, ratio = ratio ) expect(y$analysis$power, 0.9) From 43082e0385e8ab21c0e0af1e97928d0d0e8d1f8b Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 10:59:54 -0400 Subject: [PATCH 12/30] update vignette --- vignettes/articles/usage-fixed-design.Rmd | 88 ++++++++--------------- 1 file changed, 30 insertions(+), 58 deletions(-) diff --git a/vignettes/articles/usage-fixed-design.Rmd b/vignettes/articles/usage-fixed-design.Rmd index 42aea366..6b59cd7e 100644 --- a/vignettes/articles/usage-fixed-design.Rmd +++ b/vignettes/articles/usage-fixed-design.Rmd @@ -21,6 +21,7 @@ vignette: | library(gt) library(gsDesign) library(gsDesign2) +library(dplyr) ``` # Introduction @@ -70,8 +71,7 @@ beta <- 0.1 If one wants to get a power of 90%, one can calculate the sample size by ```{r} -fixed_design( - "ahr", +fixed_design_ahr( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, @@ -86,8 +86,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power of AHR by ```{r} -fixed_design( - "ahr", +fixed_design_ahr( alpha = alpha, enroll_rate = enroll_rate, fail_rate = fail_rate, @@ -104,8 +103,7 @@ If one wants to get a power of 90\%, one can calculate the sample size by ```{r} # Fixed design with a given power with default rho/gamma -fixed_design( - "fh", +fixed_design_fh( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, @@ -121,8 +119,7 @@ In the above example, the FH parameters (`rho`, `gamma`) take the default value ```{r} # Fixed design with a given power with input rho/gamma -fixed_design( - "fh", +fixed_design_fh( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, @@ -140,8 +137,7 @@ Given the above enrollment rate and enrollment duration, one can calculate the p ```{r} # Fixed design with power calculated -fixed_design( - "fh", +fixed_design_fh( alpha = alpha, enroll_rate = enroll_rate, fail_rate = fail_rate, @@ -156,8 +152,7 @@ But users can always custom their `rho` and `gamma` by ```{r} # Fixed design with power calculated -fixed_design( - "fh", +fixed_design_fh( alpha = alpha, enroll_rate = enroll_rate, fail_rate = fail_rate, @@ -174,8 +169,7 @@ fixed_design( If one wants to get a power of 90\%, one can calculate the sample size by ```{r} -fixed_design( - "mb", +fixed_design_mb( ratio = ratio, alpha = alpha, power = 1 - beta, @@ -190,8 +184,7 @@ fixed_design( In the above example, the mb parameter (`tau`) takes the default value as `tau = 6`. But users can always custom their `tau` by ```{r} -fixed_design( - "mb", +fixed_design_mb( ratio = ratio, alpha = alpha, power = 1 - beta, @@ -207,8 +200,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power of MB under the default `tau = 6` by ```{r} -fixed_design( - "mb", +fixed_design_mb( ratio = ratio, alpha = alpha, enroll_rate = enroll_rate, @@ -222,8 +214,7 @@ fixed_design( But users can always custom their `tau` by ```{r} -fixed_design( - "mb", +fixed_design_mb( ratio = ratio, alpha = alpha, enroll_rate = enroll_rate, @@ -240,8 +231,7 @@ fixed_design( If one wants to get a power of 90\%, one can calculate the sample size by ```{r} -fixed_design( - "lf", +fixed_design_lf( alpha = alpha, power = 1 - beta, ratio = ratio, @@ -256,8 +246,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power of LF by ```{r} -fixed_design( - "lf", +fixed_design_lf( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -273,8 +262,7 @@ fixed_design( If one wants to get a power of 90\%, one can calculate the sample size by ```{r} -fixed_design( - "maxcombo", +fixed_design_maxcombo( alpha = alpha, power = 1 - beta, ratio = ratio, @@ -295,8 +283,7 @@ data.frame(rho = c(0, 0), gamma = c(0, 0.5), tau = -1) %>% gt() But users can always custom their `rho`, `gamma`, `tau` by ```{r} -fixed_design( - "maxcombo", +fixed_design_maxcombo( alpha = alpha, power = 1 - beta, ratio = ratio, @@ -314,8 +301,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power of MaxCombo under the default parameters by ```{r} -fixed_design( - "maxcombo", +fixed_design_maxcombo( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -329,8 +315,7 @@ fixed_design( But users can always custom their `rho`, `gamma`, `tau` by ```{r} -fixed_design( - "maxcombo", +fixed_design_maxcombo( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -349,8 +334,7 @@ fixed_design( If one wants to get a power of 90\%, one can calculate the sample size by ```{r} -fixed_design( - "rmst", +fixed_design_rmst( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, @@ -366,8 +350,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power of RMST by ```{r} -fixed_design( - "rmst", +fixed_design_rmst( alpha = alpha, enroll_rate = enroll_rate, fail_rate = fail_rate, @@ -384,8 +367,7 @@ fixed_design( If one wants to get a power of 90\%, one can calculate the sample size by ```{r} -fixed_design( - "milestone", +fixed_design_milestone( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, @@ -401,8 +383,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power of Milestone by ```{r} -fixed_design( - "milestone", +fixed_design_milestone( alpha = alpha, enroll_rate = enroll_rate, fail_rate = fail_rate, @@ -419,8 +400,7 @@ fixed_design( If one wants to get a power of 90\%, one can calculate the sample size by ```{r} -fixed_design( - "rd", +fixed_design_rd( alpha = alpha, power = 1 - beta, p_c = .15, @@ -435,8 +415,7 @@ fixed_design( Given the above enrollment rate and enrollment duration, one can calculate the power by ```{r} -fixed_design( - "rd", +fixed_design_rd( alpha = alpha, power = NULL, p_c = .15, @@ -452,8 +431,7 @@ fixed_design( # Examples to get multiple designs together ```{r, message=FALSE} -x_ahr <- fixed_design( - "ahr", +x_ahr <- fixed_design_ahr( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -461,8 +439,7 @@ x_ahr <- fixed_design( study_duration = study_duration ) -x_fh <- fixed_design( - "fh", +x_fh <- fixed_design_fh( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -472,8 +449,7 @@ x_fh <- fixed_design( gamma = 0.5 ) -x_mb <- fixed_design( - "mb", +x_mb <- fixed_design_mb( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -482,8 +458,7 @@ x_mb <- fixed_design( tau = 4 ) -x_lf <- fixed_design( - "lf", +x_lf <- fixed_design_lf( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -491,8 +466,7 @@ x_lf <- fixed_design( study_duration = study_duration ) -x_maxcombo <- fixed_design( - "maxcombo", +x_maxcombo <- fixed_design_maxcombo( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -503,8 +477,7 @@ x_maxcombo <- fixed_design( tau = c(-1, 4, 6) ) -x_rmst <- fixed_design( - "rmst", +x_rmst <- fixed_design_rmst( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, @@ -513,8 +486,7 @@ x_rmst <- fixed_design( tau = 30 ) -x_milestone <- fixed_design( - "milestone", +x_milestone <- fixed_design_milestone( alpha = alpha, ratio = ratio, enroll_rate = enroll_rate, From 785d453e381cc0549077b075996f11fdec12c7c9 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 11:02:01 -0400 Subject: [PATCH 13/30] update documentation --- NAMESPACE | 9 ++- man/fixed_design.Rd | 104 ---------------------------------- man/fixed_design_ahr.Rd | 70 +++++++++++++++++++++++ man/fixed_design_fh.Rd | 75 ++++++++++++++++++++++++ man/fixed_design_lf.Rd | 67 ++++++++++++++++++++++ man/fixed_design_maxcombo.Rd | 78 +++++++++++++++++++++++++ man/fixed_design_mb.Rd | 72 +++++++++++++++++++++++ man/fixed_design_milestone.Rd | 68 ++++++++++++++++++++++ man/fixed_design_rd.Rd | 55 ++++++++++++++++++ man/fixed_design_rmst.Rd | 67 ++++++++++++++++++++++ 10 files changed, 560 insertions(+), 105 deletions(-) delete mode 100644 man/fixed_design.Rd create mode 100644 man/fixed_design_ahr.Rd create mode 100644 man/fixed_design_fh.Rd create mode 100644 man/fixed_design_lf.Rd create mode 100644 man/fixed_design_maxcombo.Rd create mode 100644 man/fixed_design_mb.Rd create mode 100644 man/fixed_design_milestone.Rd create mode 100644 man/fixed_design_rd.Rd create mode 100644 man/fixed_design_rmst.Rd diff --git a/NAMESPACE b/NAMESPACE index 44bdd055..0d50f127 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,7 +13,14 @@ export(define_fail_rate) export(expected_accrual) export(expected_event) export(expected_time) -export(fixed_design) +export(fixed_design_ahr) +export(fixed_design_fh) +export(fixed_design_lf) +export(fixed_design_maxcombo) +export(fixed_design_mb) +export(fixed_design_milestone) +export(fixed_design_rd) +export(fixed_design_rmst) export(gridpts) export(gs_b) export(gs_create_arm) diff --git a/man/fixed_design.Rd b/man/fixed_design.Rd deleted file mode 100644 index 051f84e7..00000000 --- a/man/fixed_design.Rd +++ /dev/null @@ -1,104 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fixed_design.R -\name{fixed_design} -\alias{fixed_design} -\title{Fixed design sample size} -\usage{ -fixed_design( - method = c("ahr", "fh", "mb", "lf", "rd", "maxcombo", "rmst", "milestone"), - alpha = 0.025, - power = NULL, - ratio = 1, - study_duration = 36, - ... -) -} -\arguments{ -\item{method}{Sample size method. Default is \code{"ahr"}. -Other options include \code{"fh"}, \code{"mb"}, \code{"lf"}, \code{"rd"}, -\code{"maxcombo"}, \code{"milestone"}.} - -\item{alpha}{One-sided Type I error (strictly between 0 and 1).} - -\item{power}{Power (\code{NULL} to compute power or strictly between 0 -and \code{1 - alpha} otherwise).} - -\item{ratio}{Experimental:Control randomization ratio.} - -\item{study_duration}{Study duration.} - -\item{...}{Additional arguments like \code{enroll_rate}, \code{fail_rate}, -\code{rho}, \code{gamma}, \code{tau}.} -} -\value{ -A table. -} -\description{ -Computes fixed design sample size for many sample size methods. -Returns a tibble with a basic summary. -} -\examples{ -library(dplyr) - -# Average hazard ratio -x <- fixed_design( - "ahr", - alpha = .025, power = .9, - enroll_rate = define_enroll_rate(duration = 18, rate = 1), - fail_rate = define_fail_rate( - duration = c(4, 100), - fail_rate = log(2) / 12, - hr = c(1, .6), - dropout_rate = .001 - ), - study_duration = 36 -) -x \%>\% summary() - -# Lachin and Foulkes (uses gsDesign::nSurv()) -x <- fixed_design( - "lf", - alpha = .025, power = .9, - enroll_rate = define_enroll_rate(duration = 18, rate = 1), - fail_rate = define_fail_rate( - duration = 100, - fail_rate = log(2) / 12, - hr = .7, - dropout_rate = .001 - ), - study_duration = 36 -) -x \%>\% summary() - -# RMST -x <- fixed_design( - "rmst", - alpha = .025, power = .9, - enroll_rate = define_enroll_rate(duration = 18, rate = 1), - fail_rate = define_fail_rate( - duration = 100, - fail_rate = log(2) / 12, - hr = .7, - dropout_rate = .001 - ), - study_duration = 36, - tau = 18 -) -x \%>\% summary() - -# Milestone -x <- fixed_design( - "milestone", - alpha = .025, power = .9, - enroll_rate = define_enroll_rate(duration = 18, rate = 1), - fail_rate = define_fail_rate( - duration = 100, - fail_rate = log(2) / 12, - hr = .7, - dropout_rate = .001 - ), - study_duration = 36, - tau = 18 -) -x \%>\% summary() -} diff --git a/man/fixed_design_ahr.Rd b/man/fixed_design_ahr.Rd new file mode 100644 index 00000000..aca30b7b --- /dev/null +++ b/man/fixed_design_ahr.Rd @@ -0,0 +1,70 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_ahr.R +\name{fixed_design_ahr} +\alias{fixed_design_ahr} +\title{Fixed design sample size} +\usage{ +fixed_design_ahr( + alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + event = NULL +) +} +\arguments{ +\item{alpha}{One-sided Type I error.} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio (not yet implemented).} + +\item{study_duration}{Study duration.} + +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + +\item{event}{Targeted event at each analysis.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for AHR methods. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) + +# example 1: given power and compute sample size +x <- fixed_design_ahr( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36 +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_ahr( + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36 +) +x \%>\% summary() +} diff --git a/man/fixed_design_fh.Rd b/man/fixed_design_fh.Rd new file mode 100644 index 00000000..ff1b45a0 --- /dev/null +++ b/man/fixed_design_fh.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_fh.R +\name{fixed_design_fh} +\alias{fixed_design_fh} +\title{Fixed design sample size} +\usage{ +fixed_design_fh( + alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + rho = 0, + gamma = 0 +) +} +\arguments{ +\item{alpha}{One-sided Type I error.} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio (not yet implemented).} + +\item{study_duration}{Study duration.} + +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + +\item{rho}{test parameter in Fleming-Harrington method.} + +\item{gamma}{test parameter in Fleming-Harrington method.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for Fleming-Harrington method. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) + +# example 1: given power and compute sample size +x <- fixed_design_fh( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36, + rho = 1, gamma = 1 +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_fh( + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36, + rho = 1, gamma = 1 +) +x \%>\% summary() +} diff --git a/man/fixed_design_lf.Rd b/man/fixed_design_lf.Rd new file mode 100644 index 00000000..1ad78ce5 --- /dev/null +++ b/man/fixed_design_lf.Rd @@ -0,0 +1,67 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_lf.R +\name{fixed_design_lf} +\alias{fixed_design_lf} +\title{Fixed design sample size} +\usage{ +fixed_design_lf( + alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate +) +} +\arguments{ +\item{alpha}{One-sided Type I error (strictly between 0 and 1).} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio.} + +\item{study_duration}{Study duration.} + +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for Lachin-Foulkes method. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) + +# example 1: given power and compute sample size +x <- fixed_design_lf( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = 100, + fail_rate = log(2) / 12, + hr = .7, + dropout_rate = .001 + ), + study_duration = 36 +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_fh( + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = 100, + fail_rate = log(2) / 12, + hr = .7, + dropout_rate = .001 + ), + study_duration = 36 +) +x \%>\% summary() +} diff --git a/man/fixed_design_maxcombo.Rd b/man/fixed_design_maxcombo.Rd new file mode 100644 index 00000000..3d69d517 --- /dev/null +++ b/man/fixed_design_maxcombo.Rd @@ -0,0 +1,78 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_maxcombo.R +\name{fixed_design_maxcombo} +\alias{fixed_design_maxcombo} +\title{Fixed design sample size} +\usage{ +fixed_design_maxcombo( + alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + rho = c(0, 0, 1), + gamma = c(0, 1, 0), + tau = rep(-1, 3) +) +} +\arguments{ +\item{alpha}{One-sided Type I error (strictly between 0 and 1).} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio.} + +\item{study_duration}{Study duration.} + +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + +\item{rho}{A vector of numbers paring with gamma and tau for maxcombo test.} + +\item{gamma}{A vector of numbers paring with rho and tau for maxcombo test.} + +\item{tau}{A vector of numbers paring with gamma and rho for maxcombo test.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for many sample size methods. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) + +# example 1: given power and compute sample size +x <- fixed_design_maxcombo( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36, + rho = c(0, 0.5), gamma = c(0, 0), tau = c(-1, -1) +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_maxcombo( + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36, + rho = c(0, 0.5), gamma = c(0, 0), tau = c(-1, -1) +) +x \%>\% summary() +} diff --git a/man/fixed_design_mb.Rd b/man/fixed_design_mb.Rd new file mode 100644 index 00000000..e365a392 --- /dev/null +++ b/man/fixed_design_mb.Rd @@ -0,0 +1,72 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_mb.R +\name{fixed_design_mb} +\alias{fixed_design_mb} +\title{Fixed design sample size} +\usage{ +fixed_design_mb( + alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + tau = 6 +) +} +\arguments{ +\item{alpha}{One-sided Type I error.} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio.} + +\item{study_duration}{Study duration.} + +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + +\item{tau}{Test parameter of Magirr-Burman method.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for Magirr-Burman method. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) + +# example 1: given power and compute sample size +x <- fixed_design_mb( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36, + tau = 4 +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_mb( + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = c(4, 100), + fail_rate = log(2) / 12, + hr = c(1, .6), + dropout_rate = .001 + ), + study_duration = 36, + tau = 4 +) +x \%>\% summary() +} diff --git a/man/fixed_design_milestone.Rd b/man/fixed_design_milestone.Rd new file mode 100644 index 00000000..b0c40253 --- /dev/null +++ b/man/fixed_design_milestone.Rd @@ -0,0 +1,68 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_milestone.R +\name{fixed_design_milestone} +\alias{fixed_design_milestone} +\title{Fixed design sample size} +\usage{ +fixed_design_milestone( + alpha = 0.025, + power = NULL, + ratio = 1, + enroll_rate, + fail_rate, + study_duration = 36, + tau = NULL +) +} +\arguments{ +\item{alpha}{One-sided Type I error (strictly between 0 and 1).} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio.} + +\item{study_duration}{Study duration.} + +\item{tau}{Test parameter of milestone method.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for milestone method. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) +# example 1: given power and compute sample size +x <- fixed_design( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = 100, + fail_rate = log(2) / 12, + hr = .7, + dropout_rate = .001 + ), + study_duration = 36, + tau = 18 +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design( + "milestone", + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = 100, + fail_rate = log(2) / 12, + hr = .7, + dropout_rate = .001 + ), + study_duration = 36, + tau = 18 +) +x \%>\% summary() +} diff --git a/man/fixed_design_rd.Rd b/man/fixed_design_rd.Rd new file mode 100644 index 00000000..128aec4d --- /dev/null +++ b/man/fixed_design_rd.Rd @@ -0,0 +1,55 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_rd.R +\name{fixed_design_rd} +\alias{fixed_design_rd} +\title{Fixed design sample size} +\usage{ +fixed_design_rd( + alpha = 0.025, + power = NULL, + ratio = 1, + p_c, + p_e, + rd0 = 0, + n = NULL +) +} +\arguments{ +\item{alpha}{One-sided Type I error (strictly between 0 and 1).} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio.} + +\item{p_c}{A numerical value of the control arm rate.} + +\item{p_e}{A numerical value of the experimental arm rate.} + +\item{rd0}{Risk difference under null hypothesis, default is 0.} + +\item{n}{Sample size. If NULL with power input, the sample size will be +computed to achieve the targeted power} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for risk difference under unstratified design. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) + +# example 1: given power and compute sample size +x <- fixed_design_rd( + alpha = alpha, power = 1 - beta, p_c = .15, p_e = .1, + rd0 = 0, ratio = 1) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_rd( + alpha = alpha, power = NULL, p_c = .15, p_e = .1, + rd0 = 0, n = 2000, ratio = 1) +x \%>\% summary() +} diff --git a/man/fixed_design_rmst.Rd b/man/fixed_design_rmst.Rd new file mode 100644 index 00000000..0501b28c --- /dev/null +++ b/man/fixed_design_rmst.Rd @@ -0,0 +1,67 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fixed_design_rmst.R +\name{fixed_design_rmst} +\alias{fixed_design_rmst} +\title{Fixed design sample size} +\usage{ +fixed_design_rmst( + alpha = 0.025, + power = NULL, + ratio = 1, + study_duration = 36, + enroll_rate, + fail_rate, + tau = NULL +) +} +\arguments{ +\item{alpha}{One-sided Type I error (strictly between 0 and 1).} + +\item{power}{Power (\code{NULL} to compute power or strictly between 0 +and \code{1 - alpha} otherwise).} + +\item{ratio}{Experimental:Control randomization ratio.} + +\item{study_duration}{Study duration.} + +\item{tau}{Test parameter in RMST.} +} +\value{ +A table. +} +\description{ +Computes fixed design sample size for RMST methods. +Returns a tibble with a basic summary. +} +\examples{ +library(dplyr) +# example 1: given power and compute sample size +x <- fixed_design_rmst( + alpha = .025, power = .9, + enroll_rate = define_enroll_rate(duration = 18, rate = 1), + fail_rate = define_fail_rate( + duration = 100, + fail_rate = log(2) / 12, + hr = .7, + dropout_rate = .001 + ), + study_duration = 36, + tau = 18 +) +x \%>\% summary() + +# example 2: given sample size and compute power +x <- fixed_design_rmst( + alpha = .025, + enroll_rate = define_enroll_rate(duration = 18, rate = 20), + fail_rate = define_fail_rate( + duration = 100, + fail_rate = log(2) / 12, + hr = .7, + dropout_rate = .001 + ), + study_duration = 36, + tau = 18 +) +x \%>\% summary() +} From 22e26bd20a18ce2bf6141f4feb0093a85cb6f34f Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 11:07:07 -0400 Subject: [PATCH 14/30] update pkgdown.ymn --- _pkgdown.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index 2991dd63..90c4943d 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -23,11 +23,18 @@ footer: blank: "" reference: -- title: "High-level functions" +- title: "Fixed design" desc: > - Functions to calculate fixed/group sequential design under multiple tests. - contents: - - fixed_design + Functions to calculate power/sample size in fixed designs. + contents: + - fixed_design_ahr + - fixed_design_fh + - fixed_design_mb + - fixed_design_lf + - fixed_design_maxcombo + - fixed_design_milestone + - fixed_design_rmst + - fixed_design_rd - title: "Average hazard ratio" desc: > Functions for the average hazard ratio (AHR) method. From e6fc90797422bd01c5464d010708004ea337d3f4 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 11:23:25 -0400 Subject: [PATCH 15/30] fix pkgdown and some lintr issues --- R/fixed_design_ahr.R | 11 ++--------- R/fixed_design_fh.R | 14 ++------------ R/fixed_design_lf.R | 21 +-------------------- R/fixed_design_maxcombo.R | 12 +----------- R/fixed_design_mb.R | 12 +----------- R/fixed_design_milestone.R | 10 +--------- R/fixed_design_rd.R | 9 --------- R/fixed_design_rmst.R | 8 +------- vignettes/gsDesign2.Rmd | 3 +-- 9 files changed, 10 insertions(+), 90 deletions(-) diff --git a/R/fixed_design_ahr.R b/R/fixed_design_ahr.R index 06711c46..915d0609 100644 --- a/R/fixed_design_ahr.R +++ b/R/fixed_design_ahr.R @@ -21,7 +21,7 @@ #' Computes fixed design sample size for AHR methods. #' Returns a tibble with a basic summary. #' -#' @inheritParams gs_design_ahr +#' @inheritParams gs_design_ahr #' @inheritParams gs_power_ahr #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). @@ -33,7 +33,6 @@ #' #' @examples #' library(dplyr) -#' #' # example 1: given power and compute sample size #' x <- fixed_design_ahr( #' alpha = .025, power = .9, @@ -47,10 +46,9 @@ #' study_duration = 36 #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_ahr( -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = c(4, 100), @@ -75,7 +73,6 @@ fixed_design_ahr <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - # ------------------------- # # save inputs # # ------------------------- # @@ -84,7 +81,6 @@ fixed_design_ahr <- function(alpha = 0.025, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # @@ -107,7 +103,6 @@ fixed_design_ahr <- function(alpha = 0.025, analysis_time = study_duration ) } - ans <- tibble::tibble( design = "ahr", n = d$analysis$n, @@ -117,12 +112,10 @@ fixed_design_ahr <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "ahr" ) - class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/fixed_design_fh.R b/R/fixed_design_fh.R index 8cbd1eb9..c5febf77 100644 --- a/R/fixed_design_fh.R +++ b/R/fixed_design_fh.R @@ -27,14 +27,12 @@ #' @param study_duration Study duration. #' @param rho test parameter in Fleming-Harrington method. #' @param gamma test parameter in Fleming-Harrington method. -#' #' @return A table. #' #' @export #' #' @examples #' library(dplyr) -#' #' # example 1: given power and compute sample size #' x <- fixed_design_fh( #' alpha = .025, power = .9, @@ -49,10 +47,9 @@ #' rho = 1, gamma = 1 #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_fh( -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = c(4, 100), @@ -78,7 +75,6 @@ fixed_design_fh <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - # check test parameters, like rho, gamma if (length(rho) > 1) { stop("fixed_design_fh: multiple rho can not be used in Fleming-Harrington method!") @@ -86,7 +82,6 @@ fixed_design_fh <- function(alpha = 0.025, if (length(gamma) > 1) { stop("fixed_design_fh: multiple gamma can not be used in Fleming-Harrington method!") } - # ------------------------- # # save inputs # # ------------------------- # @@ -96,14 +91,12 @@ fixed_design_fh <- function(alpha = 0.025, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # weight <- function(x, arm0, arm1) { wlr_weight_fh(x, arm0, arm1, rho = rho, gamma = gamma) } - if (is.null(power)) { d <- gs_power_wlr( upar = qnorm(1 - alpha), lpar = -Inf, @@ -124,7 +117,6 @@ fixed_design_fh <- function(alpha = 0.025, analysis_time = study_duration ) } - ans <- tibble::tibble( design = "fh", n = d$analysis$n, @@ -134,13 +126,11 @@ fixed_design_fh <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "fh", design_par = list(rho = rho,gamma = gamma) - ) - + ) class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/fixed_design_lf.R b/R/fixed_design_lf.R index c8735dce..93234029 100644 --- a/R/fixed_design_lf.R +++ b/R/fixed_design_lf.R @@ -27,14 +27,10 @@ #' @param ratio Experimental:Control randomization ratio. #' @param study_duration Study duration. #' @inheritParams gs_design_ahr -#' #' @return A table. -#' #' @export -#' #' @examples #' library(dplyr) -#' #' # example 1: given power and compute sample size #' x <- fixed_design_lf( #' alpha = .025, power = .9, @@ -51,7 +47,7 @@ #' #' # example 2: given sample size and compute power #' x <- fixed_design_fh( -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = 100, @@ -75,7 +71,6 @@ fixed_design_lf <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - # ------------------------- # # save inputs # # ------------------------- # @@ -84,7 +79,6 @@ fixed_design_lf <- function(alpha = 0.025, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # @@ -96,7 +90,6 @@ fixed_design_lf <- function(alpha = 0.025, } else { n_stratum <- n_stratum1 } - if (n_stratum == 1) { m <- length(fail_rate$fail_rate) lambda_cc <- fail_rate$fail_rate @@ -121,13 +114,11 @@ fixed_design_lf <- function(alpha = 0.025, stratified_duration <- fail_rate %>% select(stratum, duration) %>% tidyr::pivot_wider(names_from = stratum, values_from = duration, values_fn = list) - ss <- do.call(cbind, lapply(stratified_duration, function(x) { x %>% unlist() })) %>% as.matrix() } - # calculate the lambdaC: event hazard rates for the control group stratified_lambdac <- fail_rate %>% select(stratum, fail_rate) %>% @@ -142,36 +133,29 @@ fixed_design_lf <- function(alpha = 0.025, stratified_eta <- fail_rate %>% select(stratum, dropout_rate) %>% tidyr::pivot_wider(names_from = stratum, values_from = dropout_rate, values_fn = list) - etaa <- do.call(cbind, lapply(stratified_eta, function(x) { x %>% unlist() })) %>% as.matrix() - # calculate the gamma: rates of entry by time period (rows) and strata (columns) stratified_enroll_rate <- enroll_rate %>% select(stratum, rate) %>% tidyr::pivot_wider(names_from = stratum, values_from = rate, values_fn = list) - gammaa <- do.call(cbind, lapply(stratified_enroll_rate, function(x) { x %>% unlist() })) %>% as.matrix() - # calculate the R: duration of time periods for recruitment rates specified in rows of gamma stratified_enroll_duration <- enroll_rate %>% select(stratum, duration) %>% tidyr::pivot_wider(names_from = stratum, values_from = duration, values_fn = list) - rr <- do.call(cbind, lapply(stratified_enroll_duration, function(x) { x %>% unlist() })) %>% as.matrix() } - # calculate the ahr as the hr in nSurv dd <- ahr(enroll_rate = enroll_rate, fail_rate = fail_rate, total_duration = study_duration, ratio = ratio) - # use nSuve to develop the design d <- gsDesign::nSurv( alpha = alpha, beta = if (is.null(power)) { @@ -195,7 +179,6 @@ fixed_design_lf <- function(alpha = 0.025, rr[, 1] }) ) - ans <- tibble::tibble( design = "lf", n = d$n, @@ -205,7 +188,6 @@ fixed_design_lf <- function(alpha = 0.025, alpha = d$alpha, power = d$power ) - y <- list( input = input, enroll_rate = enroll_rate %>% mutate(rate = rate * d$n / sum(enroll_rate$duration * enroll_rate$rate)), @@ -213,7 +195,6 @@ fixed_design_lf <- function(alpha = 0.025, analysis = ans, design = "lf" ) - class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/fixed_design_maxcombo.R b/R/fixed_design_maxcombo.R index 780f34f7..7800fc3b 100644 --- a/R/fixed_design_maxcombo.R +++ b/R/fixed_design_maxcombo.R @@ -31,13 +31,10 @@ #' @param gamma A vector of numbers paring with rho and tau for maxcombo test. #' @param tau A vector of numbers paring with gamma and rho for maxcombo test. #' @inheritParams gs_design_combo -#' #' @return A table. #' @export -#' #' @examples #' library(dplyr) -#' #' # example 1: given power and compute sample size #' x <- fixed_design_maxcombo( #' alpha = .025, power = .9, @@ -52,10 +49,9 @@ #' rho = c(0, 0.5), gamma = c(0, 0), tau = c(-1, -1) #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_maxcombo( -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = c(4, 100), @@ -82,7 +78,6 @@ fixed_design_maxcombo <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - # ------------------------- # # save inputs # # ------------------------- # @@ -92,7 +87,6 @@ fixed_design_maxcombo <- function(alpha = 0.025, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # @@ -103,7 +97,6 @@ fixed_design_maxcombo <- function(alpha = 0.025, tau = tau ) %>% mutate(test = seq(1, length(rho)), analysis = 1, analysis_time = study_duration) - # check if power is NULL or not if (is.null(power)) { d <- gs_power_combo( @@ -124,7 +117,6 @@ fixed_design_maxcombo <- function(alpha = 0.025, lower = gs_b, lpar = -Inf ) } - # get the output of MaxCombo ans <- tibble::tibble( design = "maxcombo", @@ -135,13 +127,11 @@ fixed_design_maxcombo <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "maxcombo", design_par = list(rho = rho, gamma = gamma, tau = tau) ) - class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/fixed_design_mb.R b/R/fixed_design_mb.R index 8a703bbe..ed8ef5d1 100644 --- a/R/fixed_design_mb.R +++ b/R/fixed_design_mb.R @@ -28,13 +28,10 @@ #' @param ratio Experimental:Control randomization ratio. #' @param study_duration Study duration. #' @param tau Test parameter of Magirr-Burman method. -#' #' @return A table. #' @export -#' #' @examples #' library(dplyr) -#' #' # example 1: given power and compute sample size #' x <- fixed_design_mb( #' alpha = .025, power = .9, @@ -49,10 +46,9 @@ #' tau = 4 #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_mb( -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = c(4, 100), @@ -77,11 +73,9 @@ fixed_design_mb <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - if (length(tau) > 1) { stop("fixed_design: multiple tau can not be used in Magirr-Burman method!") } - # ------------------------- # # save inputs # # ------------------------- # @@ -91,14 +85,12 @@ fixed_design_mb <- function(alpha = 0.025, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # weight <- function(x, arm0, arm1) { wlr_weight_fh(x, arm0, arm1, rho = -1, gamma = 0, tau = tau) } - if (is.null(power)) { d <- gs_power_wlr( enroll_rate = enroll_rate, @@ -121,7 +113,6 @@ fixed_design_mb <- function(alpha = 0.025, lower = gs_b, lpar = -Inf, analysis_time = study_duration) } - # get the output of MB ans <- tibble::tibble( design = "mb", @@ -132,7 +123,6 @@ fixed_design_mb <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "mb", design_par = list(tau = tau)) diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index bab8d8b8..4f5546f0 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -27,11 +27,8 @@ #' @param ratio Experimental:Control randomization ratio. #' @param study_duration Study duration. #' @param tau Test parameter of milestone method. -#' #' @return A table. -#' #' @export -#' #' @examples #' library(dplyr) #'# example 1: given power and compute sample size @@ -48,11 +45,10 @@ #' tau = 18 #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design( #' "milestone", -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = 100, @@ -83,7 +79,6 @@ fixed_design_milestone <- function(alpha = 0.025, if(!is.numeric(tau) | length(tau) > 1){ stop("fixed_design_milestone: tau should a scaler.") } - # ------------------------- # # save inputs # # ------------------------- # @@ -91,7 +86,6 @@ fixed_design_milestone <- function(alpha = 0.025, alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, tau = tau, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # @@ -110,7 +104,6 @@ fixed_design_milestone <- function(alpha = 0.025, test = "survival_difference", tau = tau) } - # get the output of MaxCombo ans <- tibble::tibble( design = "milestone", @@ -121,7 +114,6 @@ fixed_design_milestone <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index 0b243506..c2f84543 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -30,19 +30,15 @@ #' @param n Sample size. If NULL with power input, the sample size will be #' computed to achieve the targeted power #' @param ratio Experimental:Control randomization ratio. -#' #' @return A table. #' @export -#' #' @examples #' library(dplyr) -#' #' # example 1: given power and compute sample size #' x <- fixed_design_rd( #' alpha = alpha, power = 1 - beta, p_c = .15, p_e = .1, #' rd0 = 0, ratio = 1) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_rd( #' alpha = alpha, power = NULL, p_c = .15, p_e = .1, @@ -67,7 +63,6 @@ fixed_design_rd <- function(alpha = 0.025, if(!is.null(n) & !is.numeric(n) ){ stop("fixed_design_rd: n should be numerical values.") } - # ------------------------- # # save inputs # # ------------------------- # @@ -75,7 +70,6 @@ fixed_design_rd <- function(alpha = 0.025, alpha = alpha, power = power, ratio = ratio, p_c = p_c, p_e = p_e, n = n ) - # ------------------------- # # generate design # # ------------------------- # @@ -99,7 +93,6 @@ fixed_design_rd <- function(alpha = 0.025, rd0 = rd0, weight = "unstratified" ) } - # get the output of MaxCombo ans <- tibble::tibble( design = "rd", @@ -108,12 +101,10 @@ fixed_design_rd <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "rd" ) - class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index a04558a6..18d16004 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -29,7 +29,6 @@ #' @param tau Test parameter in RMST. #' @return A table. #' @export -#' #' @examples #' library(dplyr) #' # example 1: given power and compute sample size @@ -46,10 +45,9 @@ #' tau = 18 #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_rmst( -#' alpha = .025, +#' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( #' duration = 100, @@ -80,7 +78,6 @@ fixed_design_rmst <- function(alpha = 0.025, if(!is.numeric(tau) | length(tau) > 1){ stop("fixed_design_rmst: tau should a scaler.") } - # ------------------------- # # save inputs # # ------------------------- # @@ -88,7 +85,6 @@ fixed_design_rmst <- function(alpha = 0.025, alpha = alpha, power = power, ratio = ratio, study_duration = study_duration, tau = tau, enroll_rate = enroll_rate, fail_rate = fail_rate ) - # ------------------------- # # generate design # # ------------------------- # @@ -119,13 +115,11 @@ fixed_design_rmst <- function(alpha = 0.025, alpha = alpha, power = (d$bound %>% filter(bound == "upper"))$probability ) - y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "rmst", design_par = list(tau = tau), study_duration ) - class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/vignettes/gsDesign2.Rmd b/vignettes/gsDesign2.Rmd index c4b3030b..f290b7ca 100644 --- a/vignettes/gsDesign2.Rmd +++ b/vignettes/gsDesign2.Rmd @@ -122,8 +122,7 @@ Under the above enrollment, failure and dropout rate assumptions we now derive s ```{r} alpha <- .025 beta <- .1 # 1 - targeted power -d <- fixed_design( - x = "ahr", # Method for computing sample size +d <- fixed_design_ahr( enroll_rate = enroll_rate, # Relative enrollment rates fail_rate = fail_rate, # Failure rates from above alpha = alpha, # Type I error From 279d0363f76c488f1c70a6c8e5582c1fa29f039b Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 11:37:17 -0400 Subject: [PATCH 16/30] fix lintr issue --- R/fixed_design_fh.R | 2 +- R/fixed_design_lf.R | 4 ---- R/fixed_design_maxcombo.R | 1 - R/fixed_design_mb.R | 2 -- R/fixed_design_milestone.R | 6 +++--- R/fixed_design_rmst.R | 6 +++--- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/R/fixed_design_fh.R b/R/fixed_design_fh.R index c5febf77..24ad136d 100644 --- a/R/fixed_design_fh.R +++ b/R/fixed_design_fh.R @@ -129,7 +129,7 @@ fixed_design_fh <- function(alpha = 0.025, y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, - design = "fh", design_par = list(rho = rho,gamma = gamma) + design = "fh", design_par = list(rho = rho, gamma = gamma) ) class(y) <- c("fixed_design", class(y)) return(y) diff --git a/R/fixed_design_lf.R b/R/fixed_design_lf.R index 93234029..e40f4a05 100644 --- a/R/fixed_design_lf.R +++ b/R/fixed_design_lf.R @@ -44,7 +44,6 @@ #' study_duration = 36 #' ) #' x %>% summary() -#' #' # example 2: given sample size and compute power #' x <- fixed_design_fh( #' alpha = .025, @@ -103,7 +102,6 @@ fixed_design_lf <- function(alpha = 0.025, } } else { warning("Lachin-Foulkes is not recommended for stratified designs!") - temp <- fail_rate %>% group_by(stratum) %>% summarize(n_duration = n()) @@ -123,12 +121,10 @@ fixed_design_lf <- function(alpha = 0.025, stratified_lambdac <- fail_rate %>% select(stratum, fail_rate) %>% tidyr::pivot_wider(names_from = stratum, values_from = fail_rate, values_fn = list) - lambda_cc <- do.call(cbind, lapply(stratified_lambdac, function(x) { x %>% unlist() })) %>% as.matrix() - # calculate the eta: dropout hazard rates for the control group stratified_eta <- fail_rate %>% select(stratum, dropout_rate) %>% diff --git a/R/fixed_design_maxcombo.R b/R/fixed_design_maxcombo.R index 7800fc3b..0cde35de 100644 --- a/R/fixed_design_maxcombo.R +++ b/R/fixed_design_maxcombo.R @@ -21,7 +21,6 @@ #' Computes fixed design sample size for many sample size methods. #' Returns a tibble with a basic summary. #' -#' #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). diff --git a/R/fixed_design_mb.R b/R/fixed_design_mb.R index ed8ef5d1..12f53fcf 100644 --- a/R/fixed_design_mb.R +++ b/R/fixed_design_mb.R @@ -22,7 +22,6 @@ #' Returns a tibble with a basic summary. #' @inheritParams gs_design_wlr #' @inheritParams gs_power_wlr -#' #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). #' @param ratio Experimental:Control randomization ratio. @@ -126,7 +125,6 @@ fixed_design_mb <- function(alpha = 0.025, y <- list( input = input, enroll_rate = d$enroll_rate, fail_rate = d$fail_rate, analysis = ans, design = "mb", design_par = list(tau = tau)) - class(y) <- c("fixed_design", class(y)) return(y) } diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index 4f5546f0..2b5adb39 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -73,10 +73,10 @@ fixed_design_milestone <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - if(is.null(tau)){ + if(is.null(tau)) { tau <- study_duration - } - if(!is.numeric(tau) | length(tau) > 1){ + } + if(!is.numeric(tau) || length(tau) > 1) { stop("fixed_design_milestone: tau should a scaler.") } # ------------------------- # diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index 18d16004..b63749ed 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -72,10 +72,10 @@ fixed_design_rmst <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - if(is.null(tau)){ + if(is.null(tau)) { tau <- study_duration - } - if(!is.numeric(tau) | length(tau) > 1){ + } + if(!is.numeric(tau) || length(tau) > 1) { stop("fixed_design_rmst: tau should a scaler.") } # ------------------------- # From 14da125e22b8d4d0dbfea44f4179d00595bfd770 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 11:53:37 -0400 Subject: [PATCH 17/30] fix cmd check --- R/as_gt.R | 6 ++---- R/fixed_design_rd.R | 10 +++++----- man/as_gt.Rd | 6 ++---- man/fixed_design_ahr.Rd | 4 +--- man/fixed_design_fh.Rd | 4 +--- man/fixed_design_lf.Rd | 4 +--- man/fixed_design_maxcombo.Rd | 4 +--- man/fixed_design_mb.Rd | 4 +--- man/fixed_design_milestone.Rd | 3 +-- man/fixed_design_rd.Rd | 2 -- man/fixed_design_rmst.Rd | 3 +-- vignettes/articles/story-nph-futility.Rmd | 6 +++--- 12 files changed, 19 insertions(+), 37 deletions(-) diff --git a/R/as_gt.R b/R/as_gt.R index 1d897fd9..ba5fd809 100644 --- a/R/as_gt.R +++ b/R/as_gt.R @@ -66,8 +66,7 @@ as_gt <- function(x, ...) { #' # AHR # #' # ------------------------- # #' # under fixed power -#' fixed_design( -#' "ahr", +#' fixed_design_ahr( #' alpha = alpha, power = 1 - beta, #' enroll_rate = enroll_rate, fail_rate = fail_rate, #' study_duration = study_duration, ratio = ratio @@ -79,8 +78,7 @@ as_gt <- function(x, ...) { #' # FH # #' # ------------------------- # #' # under fixed power -#' fixed_design( -#' "fh", +#' fixed_design_fh( #' alpha = alpha, power = 1 - beta, #' enroll_rate = enroll_rate, fail_rate = fail_rate, #' study_duration = study_duration, ratio = ratio diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index c2f84543..0e88219a 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -27,7 +27,7 @@ #' @param p_c A numerical value of the control arm rate. #' @param p_e A numerical value of the experimental arm rate. #' @param rd0 Risk difference under null hypothesis, default is 0. -#' @param n Sample size. If NULL with power input, the sample size will be +#' @param n Sample size. If NULL with power input, the sample size will be #' computed to achieve the targeted power #' @param ratio Experimental:Control randomization ratio. #' @return A table. @@ -54,20 +54,20 @@ fixed_design_rd <- function(alpha = 0.025, # --------------------------------------------- # # check inputs # # --------------------------------------------- # - if(!is.numeric(p_c) | !is.numeric(p_e)){ + if(!is.numeric(p_c) || !is.numeric(p_e)) { stop("fixed_design_rd: p_c and p_e should be numerical values.") } - if(length(p_c) > 1 | length(p_e) > 1){ + if(length(p_c) > 1 || length(p_e) > 1) { stop("fixed_design_rd: p_c and p_e should be a scaler.") } - if(!is.null(n) & !is.numeric(n) ){ + if(!is.null(n) && !is.numeric(n) ) { stop("fixed_design_rd: n should be numerical values.") } # ------------------------- # # save inputs # # ------------------------- # input <- list( - alpha = alpha, power = power, ratio = ratio, + alpha = alpha, power = power, ratio = ratio, p_c = p_c, p_e = p_e, n = n ) # ------------------------- # diff --git a/man/as_gt.Rd b/man/as_gt.Rd index 24af882f..176b2728 100644 --- a/man/as_gt.Rd +++ b/man/as_gt.Rd @@ -98,8 +98,7 @@ beta <- 0.1 # AHR # # ------------------------- # # under fixed power -fixed_design( - "ahr", +fixed_design_ahr( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio @@ -111,8 +110,7 @@ fixed_design( # FH # # ------------------------- # # under fixed power -fixed_design( - "fh", +fixed_design_fh( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duration = study_duration, ratio = ratio diff --git a/man/fixed_design_ahr.Rd b/man/fixed_design_ahr.Rd index aca30b7b..d44c7ed6 100644 --- a/man/fixed_design_ahr.Rd +++ b/man/fixed_design_ahr.Rd @@ -39,7 +39,6 @@ Returns a tibble with a basic summary. } \examples{ library(dplyr) - # example 1: given power and compute sample size x <- fixed_design_ahr( alpha = .025, power = .9, @@ -53,10 +52,9 @@ x <- fixed_design_ahr( study_duration = 36 ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_ahr( - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = c(4, 100), diff --git a/man/fixed_design_fh.Rd b/man/fixed_design_fh.Rd index ff1b45a0..4ac78f34 100644 --- a/man/fixed_design_fh.Rd +++ b/man/fixed_design_fh.Rd @@ -42,7 +42,6 @@ Returns a tibble with a basic summary. } \examples{ library(dplyr) - # example 1: given power and compute sample size x <- fixed_design_fh( alpha = .025, power = .9, @@ -57,10 +56,9 @@ x <- fixed_design_fh( rho = 1, gamma = 1 ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_fh( - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = c(4, 100), diff --git a/man/fixed_design_lf.Rd b/man/fixed_design_lf.Rd index 1ad78ce5..e960e8a5 100644 --- a/man/fixed_design_lf.Rd +++ b/man/fixed_design_lf.Rd @@ -36,7 +36,6 @@ Returns a tibble with a basic summary. } \examples{ library(dplyr) - # example 1: given power and compute sample size x <- fixed_design_lf( alpha = .025, power = .9, @@ -50,10 +49,9 @@ x <- fixed_design_lf( study_duration = 36 ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_fh( - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = 100, diff --git a/man/fixed_design_maxcombo.Rd b/man/fixed_design_maxcombo.Rd index 3d69d517..00789f43 100644 --- a/man/fixed_design_maxcombo.Rd +++ b/man/fixed_design_maxcombo.Rd @@ -45,7 +45,6 @@ Returns a tibble with a basic summary. } \examples{ library(dplyr) - # example 1: given power and compute sample size x <- fixed_design_maxcombo( alpha = .025, power = .9, @@ -60,10 +59,9 @@ x <- fixed_design_maxcombo( rho = c(0, 0.5), gamma = c(0, 0), tau = c(-1, -1) ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_maxcombo( - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = c(4, 100), diff --git a/man/fixed_design_mb.Rd b/man/fixed_design_mb.Rd index e365a392..6146496b 100644 --- a/man/fixed_design_mb.Rd +++ b/man/fixed_design_mb.Rd @@ -39,7 +39,6 @@ Returns a tibble with a basic summary. } \examples{ library(dplyr) - # example 1: given power and compute sample size x <- fixed_design_mb( alpha = .025, power = .9, @@ -54,10 +53,9 @@ x <- fixed_design_mb( tau = 4 ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_mb( - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = c(4, 100), diff --git a/man/fixed_design_milestone.Rd b/man/fixed_design_milestone.Rd index b0c40253..18875236 100644 --- a/man/fixed_design_milestone.Rd +++ b/man/fixed_design_milestone.Rd @@ -49,11 +49,10 @@ x <- fixed_design( tau = 18 ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design( "milestone", - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = 100, diff --git a/man/fixed_design_rd.Rd b/man/fixed_design_rd.Rd index 128aec4d..86a17648 100644 --- a/man/fixed_design_rd.Rd +++ b/man/fixed_design_rd.Rd @@ -40,13 +40,11 @@ Returns a tibble with a basic summary. } \examples{ library(dplyr) - # example 1: given power and compute sample size x <- fixed_design_rd( alpha = alpha, power = 1 - beta, p_c = .15, p_e = .1, rd0 = 0, ratio = 1) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_rd( alpha = alpha, power = NULL, p_c = .15, p_e = .1, diff --git a/man/fixed_design_rmst.Rd b/man/fixed_design_rmst.Rd index 0501b28c..5bb754eb 100644 --- a/man/fixed_design_rmst.Rd +++ b/man/fixed_design_rmst.Rd @@ -49,10 +49,9 @@ x <- fixed_design_rmst( tau = 18 ) x \%>\% summary() - # example 2: given sample size and compute power x <- fixed_design_rmst( - alpha = .025, + alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( duration = 100, diff --git a/vignettes/articles/story-nph-futility.Rmd b/vignettes/articles/story-nph-futility.Rmd index a45e63b6..c3bd39d1 100644 --- a/vignettes/articles/story-nph-futility.Rmd +++ b/vignettes/articles/story-nph-futility.Rmd @@ -54,11 +54,11 @@ study_duation <- 34.86 ``` We now derive a fixed sample size based on these assumptions. -Ideally, we would allow a targeted event count and variable follow-up in `fixed_design()` so that the study duration will be computed automatically. +Ideally, we would allow a targeted event count and variable follow-up in `fixed_design_ahr()` so that the study duration will be computed automatically. ```{r} -fixedevents <- fixed_design( - x = "ahr", alpha = 0.025, power = NULL, +fixedevents <- fixed_design_ahr( + alpha = 0.025, power = NULL, enroll_rate = enroll_rate, fail_rate = fail_rate, study_duation = study_duation From 05d521a2c9e9481a4d1c2344b3dbf1d8f9eca46a Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 12:09:40 -0400 Subject: [PATCH 18/30] fix pkgdown and lintr issues --- R/fixed_design_milestone.R | 8 ++++---- R/fixed_design_rd.R | 6 +++--- R/fixed_design_rmst.R | 4 ++-- man/fixed_design_milestone.Rd | 4 ++-- vignettes/articles/story-nph-futility.Rmd | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index 2b5adb39..a317a31b 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -32,7 +32,7 @@ #' @examples #' library(dplyr) #'# example 1: given power and compute sample size -#' x <- fixed_design( +#' x <- fixed_design_milestone( #' alpha = .025, power = .9, #' enroll_rate = define_enroll_rate(duration = 18, rate = 1), #' fail_rate = define_fail_rate( @@ -46,7 +46,7 @@ #' ) #' x %>% summary() #' # example 2: given sample size and compute power -#' x <- fixed_design( +#' x <- fixed_design_milestone( #' "milestone", #' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), @@ -73,10 +73,10 @@ fixed_design_milestone <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - if(is.null(tau)) { + if (is.null(tau)) { tau <- study_duration } - if(!is.numeric(tau) || length(tau) > 1) { + if (!is.numeric(tau) || length(tau) > 1) { stop("fixed_design_milestone: tau should a scaler.") } # ------------------------- # diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index 0e88219a..a2f7eb54 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -54,13 +54,13 @@ fixed_design_rd <- function(alpha = 0.025, # --------------------------------------------- # # check inputs # # --------------------------------------------- # - if(!is.numeric(p_c) || !is.numeric(p_e)) { + if (!is.numeric(p_c) || !is.numeric(p_e)) { stop("fixed_design_rd: p_c and p_e should be numerical values.") } - if(length(p_c) > 1 || length(p_e) > 1) { + if (length(p_c) > 1 || length(p_e) > 1) { stop("fixed_design_rd: p_c and p_e should be a scaler.") } - if(!is.null(n) && !is.numeric(n) ) { + if (!is.null(n) && !is.numeric(n) ) { stop("fixed_design_rd: n should be numerical values.") } # ------------------------- # diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index b63749ed..9a8e378c 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -72,10 +72,10 @@ fixed_design_rmst <- function(alpha = 0.025, check_enroll_rate(enroll_rate) check_fail_rate(fail_rate) check_enroll_rate_fail_rate(enroll_rate, fail_rate) - if(is.null(tau)) { + if (is.null(tau)) { tau <- study_duration } - if(!is.numeric(tau) || length(tau) > 1) { + if (!is.numeric(tau) || length(tau) > 1) { stop("fixed_design_rmst: tau should a scaler.") } # ------------------------- # diff --git a/man/fixed_design_milestone.Rd b/man/fixed_design_milestone.Rd index 18875236..06fa0b0e 100644 --- a/man/fixed_design_milestone.Rd +++ b/man/fixed_design_milestone.Rd @@ -36,7 +36,7 @@ Returns a tibble with a basic summary. \examples{ library(dplyr) # example 1: given power and compute sample size -x <- fixed_design( +x <- fixed_design_milestone( alpha = .025, power = .9, enroll_rate = define_enroll_rate(duration = 18, rate = 1), fail_rate = define_fail_rate( @@ -50,7 +50,7 @@ x <- fixed_design( ) x \%>\% summary() # example 2: given sample size and compute power -x <- fixed_design( +x <- fixed_design_milestone( "milestone", alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), diff --git a/vignettes/articles/story-nph-futility.Rmd b/vignettes/articles/story-nph-futility.Rmd index c3bd39d1..fa3e5fe2 100644 --- a/vignettes/articles/story-nph-futility.Rmd +++ b/vignettes/articles/story-nph-futility.Rmd @@ -50,7 +50,7 @@ fail_rate <- define_fail_rate( ) ## Study duration was 34.8 in Korn & Freidlin Table 1 ## We change to 34.86 here to obtain 512 expected events more precisely -study_duation <- 34.86 +study_duration <- 34.86 ``` We now derive a fixed sample size based on these assumptions. @@ -61,7 +61,7 @@ fixedevents <- fixed_design_ahr( alpha = 0.025, power = NULL, enroll_rate = enroll_rate, fail_rate = fail_rate, - study_duation = study_duation + study_duration = study_duration ) fixedevents %>% From 661cf2e7e7c93c91d9ae1b43c22f3803d811ba78 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 15:39:35 -0400 Subject: [PATCH 19/30] fix cmd check and lintr issue --- R/fixed_design_milestone.R | 1 - man/fixed_design_milestone.Rd | 1 - 2 files changed, 2 deletions(-) diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index a317a31b..cc9d9fc5 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -47,7 +47,6 @@ #' x %>% summary() #' # example 2: given sample size and compute power #' x <- fixed_design_milestone( -#' "milestone", #' alpha = .025, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( diff --git a/man/fixed_design_milestone.Rd b/man/fixed_design_milestone.Rd index 06fa0b0e..f87aec22 100644 --- a/man/fixed_design_milestone.Rd +++ b/man/fixed_design_milestone.Rd @@ -51,7 +51,6 @@ x <- fixed_design_milestone( x \%>\% summary() # example 2: given sample size and compute power x <- fixed_design_milestone( - "milestone", alpha = .025, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( From b99d5d3a06779e5850ceba5ce5f6cc247f726eb2 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 15:45:11 -0400 Subject: [PATCH 20/30] lintr --- R/fixed_design_rd.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index a2f7eb54..1975fa06 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -60,7 +60,7 @@ fixed_design_rd <- function(alpha = 0.025, if (length(p_c) > 1 || length(p_e) > 1) { stop("fixed_design_rd: p_c and p_e should be a scaler.") } - if (!is.null(n) && !is.numeric(n) ) { + if (!is.null(n) && !is.numeric(n)) { stop("fixed_design_rd: n should be numerical values.") } # ------------------------- # From e414af8773afd68af6617a471baee053120cd95e Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 15:58:55 -0400 Subject: [PATCH 21/30] fix cmd check --- R/fixed_design_milestone.R | 3 ++- R/fixed_design_rd.R | 4 ++-- R/fixed_design_rmst.R | 3 ++- R/summary.R | 6 ++---- R/to_integer.R | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index cc9d9fc5..99753fee 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -20,7 +20,8 @@ #' #' Computes fixed design sample size for milestone method. #' Returns a tibble with a basic summary. -#' +#' +#' @inheritParams gs_design_ahr #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index 1975fa06..e4f13aff 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -36,12 +36,12 @@ #' library(dplyr) #' # example 1: given power and compute sample size #' x <- fixed_design_rd( -#' alpha = alpha, power = 1 - beta, p_c = .15, p_e = .1, +#' alpha = 0.025, power = 0.9, p_c = .15, p_e = .1, #' rd0 = 0, ratio = 1) #' x %>% summary() #' # example 2: given sample size and compute power #' x <- fixed_design_rd( -#' alpha = alpha, power = NULL, p_c = .15, p_e = .1, +#' alpha = 0.025, power = NULL, p_c = .15, p_e = .1, #' rd0 = 0, n = 2000, ratio = 1) #' x %>% summary() fixed_design_rd <- function(alpha = 0.025, diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index 9a8e378c..faed132c 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -20,7 +20,8 @@ #' #' Computes fixed design sample size for RMST methods. #' Returns a tibble with a basic summary. -#' +#' +#' @inheritParams gs_design_ahr #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). diff --git a/R/summary.R b/R/summary.R index ec1fe460..69a67b95 100644 --- a/R/summary.R +++ b/R/summary.R @@ -60,8 +60,7 @@ #' # AHR # #' # ------------------------- # #' # under fixed power -#' fixed_design( -#' "ahr", +#' fixed_design_ahr( #' alpha = alpha, #' power = 1 - beta, #' enroll_rate = enroll_rate, @@ -74,8 +73,7 @@ #' # FH # #' # ------------------------- # #' # under fixed power -#' fixed_design( -#' "fh", +#' fixed_design_fh( #' alpha = alpha, #' power = 1 - beta, #' enroll_rate = enroll_rate, diff --git a/R/to_integer.R b/R/to_integer.R index 36abb0a9..c7aa089d 100644 --- a/R/to_integer.R +++ b/R/to_integer.R @@ -44,7 +44,7 @@ to_integer <- function(x, ...) { #' #' # Average hazard ratio #' \donttest{ -#' x <- fixed_design("ahr", +#' x <- fixed_design_ahr( #' alpha = .025, power = .9, #' enroll_rate = define_enroll_rate(duration = 18, rate = 1), #' fail_rate = define_fail_rate( @@ -57,7 +57,7 @@ to_integer <- function(x, ...) { #' x %>% to_integer() #' #' # FH -#' x <- fixed_design("fh", +#' x <- fixed_design_fh( #' alpha = 0.025, power = 0.9, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( @@ -72,7 +72,7 @@ to_integer <- function(x, ...) { #' x %>% to_integer() #' #' # MB -#' x <- fixed_design("mb", +#' x <- fixed_design_mb( #' alpha = 0.025, power = 0.9, #' enroll_rate = define_enroll_rate(duration = 18, rate = 20), #' fail_rate = define_fail_rate( From 9d0af2413be45b1059114c49e241f47ca5e04c98 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 15:59:23 -0400 Subject: [PATCH 22/30] update documentation --- man/fixed_design_milestone.Rd | 4 ++++ man/fixed_design_rd.Rd | 4 ++-- man/fixed_design_rmst.Rd | 4 ++++ man/summary.Rd | 6 ++---- man/to_integer.Rd | 6 +++--- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/man/fixed_design_milestone.Rd b/man/fixed_design_milestone.Rd index f87aec22..1590e2a7 100644 --- a/man/fixed_design_milestone.Rd +++ b/man/fixed_design_milestone.Rd @@ -22,6 +22,10 @@ and \code{1 - alpha} otherwise).} \item{ratio}{Experimental:Control randomization ratio.} +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + \item{study_duration}{Study duration.} \item{tau}{Test parameter of milestone method.} diff --git a/man/fixed_design_rd.Rd b/man/fixed_design_rd.Rd index 86a17648..f7e5ebbb 100644 --- a/man/fixed_design_rd.Rd +++ b/man/fixed_design_rd.Rd @@ -42,12 +42,12 @@ Returns a tibble with a basic summary. library(dplyr) # example 1: given power and compute sample size x <- fixed_design_rd( - alpha = alpha, power = 1 - beta, p_c = .15, p_e = .1, + alpha = 0.025, power = 0.9, p_c = .15, p_e = .1, rd0 = 0, ratio = 1) x \%>\% summary() # example 2: given sample size and compute power x <- fixed_design_rd( - alpha = alpha, power = NULL, p_c = .15, p_e = .1, + alpha = 0.025, power = NULL, p_c = .15, p_e = .1, rd0 = 0, n = 2000, ratio = 1) x \%>\% summary() } diff --git a/man/fixed_design_rmst.Rd b/man/fixed_design_rmst.Rd index 5bb754eb..18910a5a 100644 --- a/man/fixed_design_rmst.Rd +++ b/man/fixed_design_rmst.Rd @@ -24,6 +24,10 @@ and \code{1 - alpha} otherwise).} \item{study_duration}{Study duration.} +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + \item{tau}{Test parameter in RMST.} } \value{ diff --git a/man/summary.Rd b/man/summary.Rd index dbceca5c..91d5b4b9 100644 --- a/man/summary.Rd +++ b/man/summary.Rd @@ -71,8 +71,7 @@ beta <- 0.1 # AHR # # ------------------------- # # under fixed power -fixed_design( - "ahr", +fixed_design_ahr( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, @@ -85,8 +84,7 @@ fixed_design( # FH # # ------------------------- # # under fixed power -fixed_design( - "fh", +fixed_design_fh( alpha = alpha, power = 1 - beta, enroll_rate = enroll_rate, diff --git a/man/to_integer.Rd b/man/to_integer.Rd index 68054c6c..0ef4f65d 100644 --- a/man/to_integer.Rd +++ b/man/to_integer.Rd @@ -35,7 +35,7 @@ library(gsDesign2) # Average hazard ratio \donttest{ -x <- fixed_design("ahr", +x <- fixed_design_ahr( alpha = .025, power = .9, enroll_rate = define_enroll_rate(duration = 18, rate = 1), fail_rate = define_fail_rate( @@ -48,7 +48,7 @@ x <- fixed_design("ahr", x \%>\% to_integer() # FH -x <- fixed_design("fh", +x <- fixed_design_fh( alpha = 0.025, power = 0.9, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( @@ -63,7 +63,7 @@ x <- fixed_design("fh", x \%>\% to_integer() # MB -x <- fixed_design("mb", +x <- fixed_design_mb( alpha = 0.025, power = 0.9, enroll_rate = define_enroll_rate(duration = 18, rate = 20), fail_rate = define_fail_rate( From 9f36b510e791e2744590a8ba06247e03c5a59786 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 16:07:10 -0400 Subject: [PATCH 23/30] lintr issue --- R/fixed_design_milestone.R | 1 - R/fixed_design_rmst.R | 1 - 2 files changed, 2 deletions(-) diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index 99753fee..cf339f95 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -20,7 +20,6 @@ #' #' Computes fixed design sample size for milestone method. #' Returns a tibble with a basic summary. -#' #' @inheritParams gs_design_ahr #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index faed132c..a8d59126 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -20,7 +20,6 @@ #' #' Computes fixed design sample size for RMST methods. #' Returns a tibble with a basic summary. -#' #' @inheritParams gs_design_ahr #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 From 25d86678843f485f4629f84bfecbc69662bd6e2a Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 16:11:58 -0400 Subject: [PATCH 24/30] fix warning from cmd check --- R/summary.R | 3 +-- R/to_integer.R | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/R/summary.R b/R/summary.R index 69a67b95..af9743b4 100644 --- a/R/summary.R +++ b/R/summary.R @@ -18,8 +18,7 @@ #' Summary for fixed design or group sequential design objects #' -#' @param object A design object returned by [fixed_design()], -#' [gs_design_ahr()], [gs_design_wlr()], or [gs_design_combo()]. +#' @param object A design object returned by fixed_design_xxx() and gs_design_xxx(). #' @param ... Additional parameters (not used). #' #' @return A summary table (data frame). diff --git a/R/to_integer.R b/R/to_integer.R index c7aa089d..554907ef 100644 --- a/R/to_integer.R +++ b/R/to_integer.R @@ -18,12 +18,10 @@ #' Rounds sample size to an even number for equal design #' -#' @param x An object returned by [fixed_design()], [gs_design_ahr()], -#' [gs_design_wlr()], or [gs_design_combo()]. +#' @param x An object returned by fixed_design_xxx() and gs_design_xxx(). #' @param ... Additional parameters (not used). #' -#' @return A list similar to the output of [fixed_design()], -#' [gs_design_ahr()], [gs_design_wlr()], or [gs_design_combo()], +#' @return A list similar to the output of fixed_design_xxx() and gs_design_xxx(), #' except the sample size is an integer. #' #' @export to_integer From 1505dc6aed75f2bb2568a268986a34a7d3b6dcd5 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Mon, 17 Jul 2023 16:30:22 -0400 Subject: [PATCH 25/30] update documentation --- man/summary.Rd | 3 +-- man/to_integer.Rd | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/man/summary.Rd b/man/summary.Rd index 91d5b4b9..5f5cbe5e 100644 --- a/man/summary.Rd +++ b/man/summary.Rd @@ -18,8 +18,7 @@ ) } \arguments{ -\item{object}{A design object returned by \code{\link[=fixed_design]{fixed_design()}}, -\code{\link[=gs_design_ahr]{gs_design_ahr()}}, \code{\link[=gs_design_wlr]{gs_design_wlr()}}, or \code{\link[=gs_design_combo]{gs_design_combo()}}.} +\item{object}{A design object returned by fixed_design_xxx() and gs_design_xxx().} \item{...}{Additional parameters (not used).} diff --git a/man/to_integer.Rd b/man/to_integer.Rd index 0ef4f65d..00c94bf9 100644 --- a/man/to_integer.Rd +++ b/man/to_integer.Rd @@ -13,8 +13,7 @@ to_integer(x, ...) \method{to_integer}{gs_design}(x, sample_size = TRUE, ...) } \arguments{ -\item{x}{An object returned by \code{\link[=fixed_design]{fixed_design()}}, \code{\link[=gs_design_ahr]{gs_design_ahr()}}, -\code{\link[=gs_design_wlr]{gs_design_wlr()}}, or \code{\link[=gs_design_combo]{gs_design_combo()}}.} +\item{x}{An object returned by fixed_design_xxx() and gs_design_xxx().} \item{...}{Additional parameters (not used).} @@ -22,8 +21,7 @@ to_integer(x, ...) sample size to an even integer.} } \value{ -A list similar to the output of \code{\link[=fixed_design]{fixed_design()}}, -\code{\link[=gs_design_ahr]{gs_design_ahr()}}, \code{\link[=gs_design_wlr]{gs_design_wlr()}}, or \code{\link[=gs_design_combo]{gs_design_combo()}}, +A list similar to the output of fixed_design_xxx() and gs_design_xxx(), except the sample size is an integer. } \description{ From d3ef23aa34da716a2afa17a680bfcc8a7e79b304 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Tue, 18 Jul 2023 09:45:02 -0400 Subject: [PATCH 26/30] address yilong's comments --- R/fixed_design_ahr.R | 8 ++++---- man/fixed_design_ahr.Rd | 14 +++++++------- vignettes/articles/usage-fixed-design.Rmd | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/R/fixed_design_ahr.R b/R/fixed_design_ahr.R index 915d0609..86ead893 100644 --- a/R/fixed_design_ahr.R +++ b/R/fixed_design_ahr.R @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size +#' Fixed design using average hazard ratio under non-proportional hazards #' #' Computes fixed design sample size for AHR methods. #' Returns a tibble with a basic summary. @@ -59,12 +59,12 @@ #' study_duration = 36 #' ) #' x %>% summary() -fixed_design_ahr <- function(alpha = 0.025, +fixed_design_ahr <- function(enroll_rate, + fail_rate, + alpha = 0.025, power = NULL, ratio = 1, study_duration = 36, - enroll_rate, - fail_rate, event = NULL ) { # --------------------------------------------- # diff --git a/man/fixed_design_ahr.Rd b/man/fixed_design_ahr.Rd index d44c7ed6..3461bfd1 100644 --- a/man/fixed_design_ahr.Rd +++ b/man/fixed_design_ahr.Rd @@ -2,19 +2,23 @@ % Please edit documentation in R/fixed_design_ahr.R \name{fixed_design_ahr} \alias{fixed_design_ahr} -\title{Fixed design sample size} +\title{Fixed design using average hazard ratio under non-proportional hazards} \usage{ fixed_design_ahr( + enroll_rate, + fail_rate, alpha = 0.025, power = NULL, ratio = 1, study_duration = 36, - enroll_rate, - fail_rate, event = NULL ) } \arguments{ +\item{enroll_rate}{Enrollment rates.} + +\item{fail_rate}{Failure and dropout rates.} + \item{alpha}{One-sided Type I error.} \item{power}{Power (\code{NULL} to compute power or strictly between 0 @@ -24,10 +28,6 @@ and \code{1 - alpha} otherwise).} \item{study_duration}{Study duration.} -\item{enroll_rate}{Enrollment rates.} - -\item{fail_rate}{Failure and dropout rates.} - \item{event}{Targeted event at each analysis.} } \value{ diff --git a/vignettes/articles/usage-fixed-design.Rmd b/vignettes/articles/usage-fixed-design.Rmd index 6b59cd7e..f06da3ee 100644 --- a/vignettes/articles/usage-fixed-design.Rmd +++ b/vignettes/articles/usage-fixed-design.Rmd @@ -26,16 +26,16 @@ library(dplyr) # Introduction -In this vignette, we introduce the key functionality of `fixed_design()` in `gsDesign2`. -Generally speaking, `fixed_design()` is capable of both power calculations and sample size calculations under many methods, including - -- AHR -- Fleming-Harrington (FH) [@farrington1990test] -- Magirr-Burman (MB) -- Lachin-Foulkes (LF) [@lachin1986evaluation] -- RMST [@yung2020sample] -- Milestone [@yung2020sample] -- Risk difference (RD) [@mehrotra2000minimum]. +In this vignette, we introduce the key functionality of `fixed_design_xxx()` in `gsDesign2`. +Generally speaking, `fixed_design_xxx()` is capable of both power calculations and sample size calculations under many methods, including + +- `fixed_design_ahr()`: AHR +- `fixed_design_fh()`Fleming-Harrington (FH) [@farrington1990test] +- `fixed_design_mb()`Magirr-Burman (MB) +- `fixed_design_lf()`Lachin-Foulkes (LF) [@lachin1986evaluation] +- `fixed_design_rmst()`RMST [@yung2020sample] +- `fixed_design_milestone()`Milestone [@yung2020sample] +- `fixed_design_rd()`Risk difference (RD) [@mehrotra2000minimum]. Throughout this vignette, we assume the design parameter is From a4905dfd42678faed1f8070e4236178f90e64e20 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Tue, 18 Jul 2023 11:05:29 -0400 Subject: [PATCH 27/30] fix cmd check --- NAMESPACE | 1 - man/pw_info.Rd | 1 - 2 files changed, 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 0a054b64..119325e9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,7 +21,6 @@ export(fixed_design_mb) export(fixed_design_milestone) export(fixed_design_rd) export(fixed_design_rmst) -export(gridpts) export(gs_b) export(gs_create_arm) export(gs_design_ahr) diff --git a/man/pw_info.Rd b/man/pw_info.Rd index b23d8a8f..91ac6b8e 100644 --- a/man/pw_info.Rd +++ b/man/pw_info.Rd @@ -94,7 +94,6 @@ fail_rate <- define_fail_rate( dropout_rate = .001, hr = c(.9, .75, .8, .6) ) - # Give results by change-points in the piecewise model ahr(enroll_rate = enroll_rate, fail_rate = fail_rate, total_duration = c(15, 30)) From 1a767050927e672a8e6f36cf1bd84713a48ace83 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Tue, 18 Jul 2023 11:21:17 -0400 Subject: [PATCH 28/30] update documentation --- R/fixed_design_ahr.R | 5 +++-- R/fixed_design_fh.R | 8 ++++---- R/fixed_design_lf.R | 9 ++++----- R/fixed_design_maxcombo.R | 9 ++++----- R/fixed_design_mb.R | 6 ++++-- R/fixed_design_milestone.R | 8 ++++---- R/fixed_design_rd.R | 9 ++++----- R/fixed_design_rmst.R | 8 ++++---- man/fixed_design_ahr.Rd | 5 +++-- man/fixed_design_fh.Rd | 11 ++++++++--- man/fixed_design_lf.Rd | 11 ++++++++--- man/fixed_design_maxcombo.Rd | 11 ++++++++--- man/fixed_design_mb.Rd | 11 ++++++++++- man/fixed_design_milestone.Rd | 11 ++++++++--- man/fixed_design_rd.Rd | 11 ++++++++--- man/fixed_design_rmst.Rd | 11 ++++++++--- 16 files changed, 92 insertions(+), 52 deletions(-) diff --git a/R/fixed_design_ahr.R b/R/fixed_design_ahr.R index 86ead893..874b2d37 100644 --- a/R/fixed_design_ahr.R +++ b/R/fixed_design_ahr.R @@ -18,8 +18,9 @@ #' Fixed design using average hazard ratio under non-proportional hazards #' -#' Computes fixed design sample size for AHR methods. -#' Returns a tibble with a basic summary. +#' Computes fixed design sample size (given power) or power (given sample size) +#' for AHR methods. +#' Returns a list with a basic summary. #' #' @inheritParams gs_design_ahr #' @inheritParams gs_power_ahr diff --git a/R/fixed_design_fh.R b/R/fixed_design_fh.R index 24ad136d..095df802 100644 --- a/R/fixed_design_fh.R +++ b/R/fixed_design_fh.R @@ -16,10 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' -#' Computes fixed design sample size for Fleming-Harrington method. -#' Returns a tibble with a basic summary. +#' Fixed design using Fleming-Harrington method method (Farrington and Manning 1990). +#' Computes fixed design sample size (given power) or power (given sample size) +#' for Fleming-Harrington method method. +#' Returns a list with a basic summary. #' @inheritParams gs_design_wlr #' @inheritParams gs_power_wlr #' @param power Power (`NULL` to compute power or strictly between 0 diff --git a/R/fixed_design_lf.R b/R/fixed_design_lf.R index e40f4a05..d27f8ac0 100644 --- a/R/fixed_design_lf.R +++ b/R/fixed_design_lf.R @@ -16,11 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' -#' Computes fixed design sample size for Lachin-Foulkes method. -#' Returns a tibble with a basic summary. -#' +#' Fixed design using Lachin-Foulkes method (Farrington and Manning 1990). +#' Computes fixed design sample size (given power) or power (given sample size) +#' for Lachin-Foulkes method method. +#' Returns a list with a basic summary. #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). diff --git a/R/fixed_design_maxcombo.R b/R/fixed_design_maxcombo.R index 0cde35de..99c94c58 100644 --- a/R/fixed_design_maxcombo.R +++ b/R/fixed_design_maxcombo.R @@ -16,11 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' -#' Computes fixed design sample size for many sample size methods. -#' Returns a tibble with a basic summary. -#' +#' Fixed design using maxcombo method. +#' Computes fixed design sample size (given power) or power (given sample size) +#' for maxcombo method. +#' Returns a list with a basic summary. #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). diff --git a/R/fixed_design_mb.R b/R/fixed_design_mb.R index 12f53fcf..4249cfd9 100644 --- a/R/fixed_design_mb.R +++ b/R/fixed_design_mb.R @@ -16,10 +16,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' #' Computes fixed design sample size for Magirr-Burman method. #' Returns a tibble with a basic summary. +#' Fixed design using Magirr-Burman method. +#' Computes fixed design sample size (given power) or power (given sample size) +#' for Magirr-Burman method. +#' Returns a list with a basic summary. #' @inheritParams gs_design_wlr #' @inheritParams gs_power_wlr #' @param power Power (`NULL` to compute power or strictly between 0 diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index cf339f95..51319019 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -16,10 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' -#' Computes fixed design sample size for milestone method. -#' Returns a tibble with a basic summary. +#' Fixed design using milestone method (Yung and Liu 2020). +#' Computes fixed design sample size (given power) or power (given sample size) +#' for milestone method. +#' Returns a list with a basic summary. #' @inheritParams gs_design_ahr #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index e4f13aff..74363e85 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -16,11 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' -#' Computes fixed design sample size for risk difference under unstratified design. -#' Returns a tibble with a basic summary. -#' +#' Fixed design for binary outcome measuring in risk difference (Mehrotra and Railkar 2000). +#' Computes fixed design sample size (given power) or power (given sample size) +#' for binary outcome measuring in risk difference. +#' Returns a list with a basic summary. #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 #' and `1 - alpha` otherwise). diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index a8d59126..c7e115f7 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -16,10 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design sample size -#' -#' Computes fixed design sample size for RMST methods. -#' Returns a tibble with a basic summary. +#' Fixed design using RMST method (Yung and Liu 2020). +#' Computes fixed design sample size (given power) or power (given sample size) +#' for RMST methods. +#' Returns a list with a basic summary. #' @inheritParams gs_design_ahr #' @param alpha One-sided Type I error (strictly between 0 and 1). #' @param power Power (`NULL` to compute power or strictly between 0 diff --git a/man/fixed_design_ahr.Rd b/man/fixed_design_ahr.Rd index 3461bfd1..186feac1 100644 --- a/man/fixed_design_ahr.Rd +++ b/man/fixed_design_ahr.Rd @@ -34,8 +34,9 @@ and \code{1 - alpha} otherwise).} A table. } \description{ -Computes fixed design sample size for AHR methods. -Returns a tibble with a basic summary. +Computes fixed design sample size (given power) or power (given sample size) +for AHR methods. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_fh.Rd b/man/fixed_design_fh.Rd index 4ac78f34..7a2e0d1a 100644 --- a/man/fixed_design_fh.Rd +++ b/man/fixed_design_fh.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/fixed_design_fh.R \name{fixed_design_fh} \alias{fixed_design_fh} -\title{Fixed design sample size} +\title{Fixed design using Fleming-Harrington method method (Farrington and Manning 1990). +Computes fixed design sample size (given power) or power (given sample size) +for Fleming-Harrington method method. +Returns a list with a basic summary.} \usage{ fixed_design_fh( alpha = 0.025, @@ -37,8 +40,10 @@ and \code{1 - alpha} otherwise).} A table. } \description{ -Computes fixed design sample size for Fleming-Harrington method. -Returns a tibble with a basic summary. +Fixed design using Fleming-Harrington method method (Farrington and Manning 1990). +Computes fixed design sample size (given power) or power (given sample size) +for Fleming-Harrington method method. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_lf.Rd b/man/fixed_design_lf.Rd index e960e8a5..2c27592d 100644 --- a/man/fixed_design_lf.Rd +++ b/man/fixed_design_lf.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/fixed_design_lf.R \name{fixed_design_lf} \alias{fixed_design_lf} -\title{Fixed design sample size} +\title{Fixed design using Lachin-Foulkes method (Farrington and Manning 1990). +Computes fixed design sample size (given power) or power (given sample size) +for Lachin-Foulkes method method. +Returns a list with a basic summary.} \usage{ fixed_design_lf( alpha = 0.025, @@ -31,8 +34,10 @@ and \code{1 - alpha} otherwise).} A table. } \description{ -Computes fixed design sample size for Lachin-Foulkes method. -Returns a tibble with a basic summary. +Fixed design using Lachin-Foulkes method (Farrington and Manning 1990). +Computes fixed design sample size (given power) or power (given sample size) +for Lachin-Foulkes method method. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_maxcombo.Rd b/man/fixed_design_maxcombo.Rd index 00789f43..d2e111b2 100644 --- a/man/fixed_design_maxcombo.Rd +++ b/man/fixed_design_maxcombo.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/fixed_design_maxcombo.R \name{fixed_design_maxcombo} \alias{fixed_design_maxcombo} -\title{Fixed design sample size} +\title{Fixed design using maxcombo method. +Computes fixed design sample size (given power) or power (given sample size) +for maxcombo method. +Returns a list with a basic summary.} \usage{ fixed_design_maxcombo( alpha = 0.025, @@ -40,8 +43,10 @@ and \code{1 - alpha} otherwise).} A table. } \description{ -Computes fixed design sample size for many sample size methods. -Returns a tibble with a basic summary. +Fixed design using maxcombo method. +Computes fixed design sample size (given power) or power (given sample size) +for maxcombo method. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_mb.Rd b/man/fixed_design_mb.Rd index 6146496b..477d8a47 100644 --- a/man/fixed_design_mb.Rd +++ b/man/fixed_design_mb.Rd @@ -2,7 +2,12 @@ % Please edit documentation in R/fixed_design_mb.R \name{fixed_design_mb} \alias{fixed_design_mb} -\title{Fixed design sample size} +\title{Computes fixed design sample size for Magirr-Burman method. +Returns a tibble with a basic summary. +Fixed design using Magirr-Burman method. +Computes fixed design sample size (given power) or power (given sample size) +for Magirr-Burman method. +Returns a list with a basic summary.} \usage{ fixed_design_mb( alpha = 0.025, @@ -36,6 +41,10 @@ A table. \description{ Computes fixed design sample size for Magirr-Burman method. Returns a tibble with a basic summary. +Fixed design using Magirr-Burman method. +Computes fixed design sample size (given power) or power (given sample size) +for Magirr-Burman method. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_milestone.Rd b/man/fixed_design_milestone.Rd index 1590e2a7..9a06f8e5 100644 --- a/man/fixed_design_milestone.Rd +++ b/man/fixed_design_milestone.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/fixed_design_milestone.R \name{fixed_design_milestone} \alias{fixed_design_milestone} -\title{Fixed design sample size} +\title{Fixed design using milestone method (Yung and Liu 2020). +Computes fixed design sample size (given power) or power (given sample size) +for milestone method. +Returns a list with a basic summary.} \usage{ fixed_design_milestone( alpha = 0.025, @@ -34,8 +37,10 @@ and \code{1 - alpha} otherwise).} A table. } \description{ -Computes fixed design sample size for milestone method. -Returns a tibble with a basic summary. +Fixed design using milestone method (Yung and Liu 2020). +Computes fixed design sample size (given power) or power (given sample size) +for milestone method. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_rd.Rd b/man/fixed_design_rd.Rd index f7e5ebbb..245ceef2 100644 --- a/man/fixed_design_rd.Rd +++ b/man/fixed_design_rd.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/fixed_design_rd.R \name{fixed_design_rd} \alias{fixed_design_rd} -\title{Fixed design sample size} +\title{Fixed design for binary outcome measuring in risk difference (Mehrotra and Railkar 2000). +Computes fixed design sample size (given power) or power (given sample size) +for binary outcome measuring in risk difference. +Returns a list with a basic summary.} \usage{ fixed_design_rd( alpha = 0.025, @@ -35,8 +38,10 @@ computed to achieve the targeted power} A table. } \description{ -Computes fixed design sample size for risk difference under unstratified design. -Returns a tibble with a basic summary. +Fixed design for binary outcome measuring in risk difference (Mehrotra and Railkar 2000). +Computes fixed design sample size (given power) or power (given sample size) +for binary outcome measuring in risk difference. +Returns a list with a basic summary. } \examples{ library(dplyr) diff --git a/man/fixed_design_rmst.Rd b/man/fixed_design_rmst.Rd index 18910a5a..80653505 100644 --- a/man/fixed_design_rmst.Rd +++ b/man/fixed_design_rmst.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/fixed_design_rmst.R \name{fixed_design_rmst} \alias{fixed_design_rmst} -\title{Fixed design sample size} +\title{Fixed design using RMST method (Yung and Liu 2020). +Computes fixed design sample size (given power) or power (given sample size) +for RMST methods. +Returns a list with a basic summary.} \usage{ fixed_design_rmst( alpha = 0.025, @@ -34,8 +37,10 @@ and \code{1 - alpha} otherwise).} A table. } \description{ -Computes fixed design sample size for RMST methods. -Returns a tibble with a basic summary. +Fixed design using RMST method (Yung and Liu 2020). +Computes fixed design sample size (given power) or power (given sample size) +for RMST methods. +Returns a list with a basic summary. } \examples{ library(dplyr) From 12fd09879da60fb65cd88bd22e6efe05dc47d923 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Tue, 18 Jul 2023 11:22:07 -0400 Subject: [PATCH 29/30] typo --- R/fixed_design_ahr.R | 2 +- man/fixed_design_ahr.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/fixed_design_ahr.R b/R/fixed_design_ahr.R index 874b2d37..c73cae51 100644 --- a/R/fixed_design_ahr.R +++ b/R/fixed_design_ahr.R @@ -19,7 +19,7 @@ #' Fixed design using average hazard ratio under non-proportional hazards #' #' Computes fixed design sample size (given power) or power (given sample size) -#' for AHR methods. +#' for AHR method. #' Returns a list with a basic summary. #' #' @inheritParams gs_design_ahr diff --git a/man/fixed_design_ahr.Rd b/man/fixed_design_ahr.Rd index 186feac1..24d5ce31 100644 --- a/man/fixed_design_ahr.Rd +++ b/man/fixed_design_ahr.Rd @@ -35,7 +35,7 @@ A table. } \description{ Computes fixed design sample size (given power) or power (given sample size) -for AHR methods. +for AHR method. Returns a list with a basic summary. } \examples{ From 4b87732f42293106613bcf0831270df2ce5fce27 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Tue, 18 Jul 2023 11:29:58 -0400 Subject: [PATCH 30/30] lintr --- R/fixed_design_ahr.R | 2 +- R/fixed_design_fh.R | 4 ++-- R/fixed_design_lf.R | 4 ++-- R/fixed_design_maxcombo.R | 4 ++-- R/fixed_design_mb.R | 4 ++-- R/fixed_design_milestone.R | 2 +- R/fixed_design_rd.R | 2 +- R/fixed_design_rmst.R | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/fixed_design_ahr.R b/R/fixed_design_ahr.R index c73cae51..d32a5861 100644 --- a/R/fixed_design_ahr.R +++ b/R/fixed_design_ahr.R @@ -18,7 +18,7 @@ #' Fixed design using average hazard ratio under non-proportional hazards #' -#' Computes fixed design sample size (given power) or power (given sample size) +#' Computes fixed design sample size (given power) or power (given sample size) #' for AHR method. #' Returns a list with a basic summary. #' diff --git a/R/fixed_design_fh.R b/R/fixed_design_fh.R index 095df802..c8d31353 100644 --- a/R/fixed_design_fh.R +++ b/R/fixed_design_fh.R @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design using Fleming-Harrington method method (Farrington and Manning 1990). -#' Computes fixed design sample size (given power) or power (given sample size) +#' Fixed design using Fleming-Harrington method method (Farrington and Manning 1990). +#' Computes fixed design sample size (given power) or power (given sample size) #' for Fleming-Harrington method method. #' Returns a list with a basic summary. #' @inheritParams gs_design_wlr diff --git a/R/fixed_design_lf.R b/R/fixed_design_lf.R index d27f8ac0..019a9adf 100644 --- a/R/fixed_design_lf.R +++ b/R/fixed_design_lf.R @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design using Lachin-Foulkes method (Farrington and Manning 1990). -#' Computes fixed design sample size (given power) or power (given sample size) +#' Fixed design using Lachin-Foulkes method (Farrington and Manning 1990). +#' Computes fixed design sample size (given power) or power (given sample size) #' for Lachin-Foulkes method method. #' Returns a list with a basic summary. #' @param alpha One-sided Type I error (strictly between 0 and 1). diff --git a/R/fixed_design_maxcombo.R b/R/fixed_design_maxcombo.R index 99c94c58..18c6a095 100644 --- a/R/fixed_design_maxcombo.R +++ b/R/fixed_design_maxcombo.R @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -#' Fixed design using maxcombo method. -#' Computes fixed design sample size (given power) or power (given sample size) +#' Fixed design using maxcombo method. +#' Computes fixed design sample size (given power) or power (given sample size) #' for maxcombo method. #' Returns a list with a basic summary. #' @param alpha One-sided Type I error (strictly between 0 and 1). diff --git a/R/fixed_design_mb.R b/R/fixed_design_mb.R index 4249cfd9..56cecea1 100644 --- a/R/fixed_design_mb.R +++ b/R/fixed_design_mb.R @@ -18,8 +18,8 @@ #' Computes fixed design sample size for Magirr-Burman method. #' Returns a tibble with a basic summary. -#' Fixed design using Magirr-Burman method. -#' Computes fixed design sample size (given power) or power (given sample size) +#' Fixed design using Magirr-Burman method. +#' Computes fixed design sample size (given power) or power (given sample size) #' for Magirr-Burman method. #' Returns a list with a basic summary. #' @inheritParams gs_design_wlr diff --git a/R/fixed_design_milestone.R b/R/fixed_design_milestone.R index 51319019..d9911db1 100644 --- a/R/fixed_design_milestone.R +++ b/R/fixed_design_milestone.R @@ -17,7 +17,7 @@ # along with this program. If not, see . #' Fixed design using milestone method (Yung and Liu 2020). -#' Computes fixed design sample size (given power) or power (given sample size) +#' Computes fixed design sample size (given power) or power (given sample size) #' for milestone method. #' Returns a list with a basic summary. #' @inheritParams gs_design_ahr diff --git a/R/fixed_design_rd.R b/R/fixed_design_rd.R index 74363e85..309df258 100644 --- a/R/fixed_design_rd.R +++ b/R/fixed_design_rd.R @@ -17,7 +17,7 @@ # along with this program. If not, see . #' Fixed design for binary outcome measuring in risk difference (Mehrotra and Railkar 2000). -#' Computes fixed design sample size (given power) or power (given sample size) +#' Computes fixed design sample size (given power) or power (given sample size) #' for binary outcome measuring in risk difference. #' Returns a list with a basic summary. #' @param alpha One-sided Type I error (strictly between 0 and 1). diff --git a/R/fixed_design_rmst.R b/R/fixed_design_rmst.R index c7e115f7..a53bc1c3 100644 --- a/R/fixed_design_rmst.R +++ b/R/fixed_design_rmst.R @@ -17,7 +17,7 @@ # along with this program. If not, see . #' Fixed design using RMST method (Yung and Liu 2020). -#' Computes fixed design sample size (given power) or power (given sample size) +#' Computes fixed design sample size (given power) or power (given sample size) #' for RMST methods. #' Returns a list with a basic summary. #' @inheritParams gs_design_ahr