Skip to content

Commit f29849d

Browse files
committed
update arguments for sampleSize
1 parent 0b88528 commit f29849d

File tree

4 files changed

+33
-55
lines changed

4 files changed

+33
-55
lines changed

R/SampleSize.R

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#' @param sigma_list list of sigma vectors, each element corresponds to a comparator with a sigma vector of size number of endpoints.
77
#' @param cor_mat matrix specifying the correlation matrix between endpoints, used along with sigma_list to calculate the varcov list in case it is not provided.
88
#' @param sigmaB number between subject variance only for 2x2 design.
9-
#' @param Eper Vector of length 2, specifying the period effect in `dtype = "2x2"` design, applied to c(Period 0, Period 1).
10-
#' @param Eco Vector of length 2, specifying the carry-over effect for each arm in `dtype = "2x2"` design, applied to c(Reference, Treatment).
9+
#' @param Eper Optional. Vector of length 2 specifying the period effect in a `dtype = "2x2"` design, applied to c(Period 0, Period 1). Defaults to `c(0, 0)` if not provided. Ignored for `dtype = "parallel"`.
10+
#' @param Eco Optional. Vector of length 2 specifying the carry-over effect for each arm in a `dtype = "2x2"` design, applied to c(Reference, Treatment). Defaults to `c(0, 0)` if not provided. Ignored for `dtype = "parallel"`.
1111
#' @param rho Correlation parameter applied uniformly across all endpoint pairs, used with sigma_list to calculate varcov if cor_mat or varcov_list are not provided.
1212
#' @param TAR vector of allocation rates with allocation rates of the arm, default is equivalent rate.
1313
#' @param arm_names Optional vector with the treatment names. If not supplied, it will be derived from mu_list.
@@ -81,26 +81,16 @@
8181
#' FDA = c("AUClast", "Cmax"))
8282
#'
8383
#'# Run the simulation
84-
#'sampleSize(power = 0.9, # target power
85-
#' alpha = 0.05,
86-
#' mu_list = mu_list,
87-
#' sigma_list = sigma_list,
88-
#' lequi.tol = lequi.tol,
89-
#' uequi.tol = uequi.tol,
90-
#' list_comparator = list_comparator,
91-
#' list_y_comparator = list_y_comparator,
92-
#' adjust = "no",
93-
#' dtype = "parallel",
94-
#' ctype = "ROM",
95-
#' vareq = FALSE,
96-
#' lognorm = TRUE,
97-
#' ncores = 1,
98-
#' nsim = 50,
99-
#' seed = 1234)
84+
#'sampleSize(power = 0.9, alpha = 0.05, mu_list = mu_list,
85+
#' sigma_list = sigma_list, lequi.tol = lequi.tol,
86+
#' uequi.tol = uequi.tol, list_comparator = list_comparator,
87+
#' list_y_comparator = list_y_comparator, adjust = "no",
88+
#' dtype = "parallel", ctype = "ROM", vareq = FALSE,
89+
#' lognorm = TRUE, ncores = 1, nsim = 50, seed = 1234)
10090
#'
10191
#' @export
10292
sampleSize <- function(mu_list, varcov_list=NA, sigma_list=NA, cor_mat=NA,
103-
sigmaB =NA, Eper = c(0,0), Eco = c(0,0), rho=0,
93+
sigmaB =NA, Eper, Eco, rho=0,
10494
TAR=NA,
10595
arm_names=NA,
10696
ynames_list=NA,
@@ -132,6 +122,10 @@ sampleSize <- function(mu_list, varcov_list=NA, sigma_list=NA, cor_mat=NA,
132122
optimization_method = "fast"
133123
){
134124

125+
# Assign default values for Eper and Eco
126+
if (missing(Eper)) Eper <- c(0, 0)
127+
if (missing(Eco)) Eco <- c(0, 0)
128+
135129
# is mu provided?
136130
if (all(is.na(mu_list))) {
137131
stop("mu_list must be provided")
@@ -462,7 +456,7 @@ sampleSize <- function(mu_list, varcov_list=NA, sigma_list=NA, cor_mat=NA,
462456
}
463457

464458
# Check if dtype is "parallel" and Eper or Eco are non-default
465-
if ((any(Eper != c(0, 0)) || any(Eco != c(0, 0)))) {
459+
if (any(Eper != c(0, 0)) || any(Eco != c(0, 0))) {
466460
warning("Eper and Eco are only applicable for dtype = '2x2'. Non-default values for Eper or Eco will be ignored in parallel design.")
467461
}
468462
} else {

man/sampleSize.Rd

Lines changed: 11 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-error_no_sigma.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_that("error no sigma_list provided", {
1111
# Same treatment allocation rate
1212
TAR = c(1,1,1) # we assume same allocation rate in both arms
1313

14-
expect_error(SimTOST::estSampleSize( mu_list = mu_list,
14+
expect_error(SimTOST::sampleSize( mu_list = mu_list,
1515
sigma_list = sigma_list,
1616
varcov_list = NA,
1717
power = 0.9,

tests/testthat/test-same_results.R

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,13 @@ testthat::test_that("Return expected result", {
3333
uequi.tol <- c(AUCinf = 1.25, AUClast = 1.25, Cmax = 1.25)
3434

3535
# Pass the user parameters into a list of parameters and calculate the sample size
36-
res_cal <- SimTOST::estSampleSize( mu_list = mu_list,
37-
sigma_list = sigma_list,
38-
power = 0.9,
39-
dtype = "parallel",
40-
ctype = "ROM",
41-
vareq = T,
42-
lognorm = T,
43-
k=3,
44-
list_comparator = list_comparator,
45-
list_y_comparator = list_y_comparator,
46-
lequi.tol = lequi.tol,
47-
uequi.tol = uequi.tol,
48-
ncores=1)
36+
res_cal <- sampleSize(mu_list = mu_list, sigma_list = sigma_list,
37+
power = 0.9, dtype = "parallel", ctype = "ROM",
38+
vareq = T, lognorm = T, k = 3,
39+
list_comparator = list_comparator,
40+
list_y_comparator = list_y_comparator,
41+
lequi.tol = lequi.tol, uequi.tol = uequi.tol,
42+
ncores = 1)
4943

5044
expect_equal(res_cal$response[["n_total"]], 150, tolerance = 6)
5145
})

0 commit comments

Comments
 (0)