@@ -65,7 +65,7 @@ power_cal <- function(n,nsim,param,param.d,seed,ncores){
6565 size [size < 2 ] <- 2
6666 size_ndrop <- ceiling((1 - param.d $ dropout [names(size )])* size )
6767 size_ndrop [size_ndrop < 2 ] <- 2
68- n_drop <- sum(size )- sum(size_ndrop )
68+ n_drop <- sum(size ) - sum(size_ndrop )
6969
7070 } else if (param.d $ dtype == " 2x2" ) {
7171 # expected
@@ -199,6 +199,7 @@ test_studies <- function(nsim, n, comp, param, param.d, arm_seed, ncores){
199199 }
200200
201201 if (param.d $ ctype == " ROM" & param.d $ lognorm == TRUE ){
202+ # Convert data to lognorm scale
202203 if (param.d $ dtype == " parallel" ){
203204 SigmaT <- as.matrix(log(SigmaT / (muT %*% t(muT ))+ 1 ))
204205 SigmaR <- as.matrix(log(SigmaR / (muR %*% t(muR ))+ 1 ))
@@ -214,125 +215,42 @@ test_studies <- function(nsim, n, comp, param, param.d, arm_seed, ncores){
214215 uequi.tol <- log(uequi.tol )
215216 }
216217
217- # Get typey the positions of the primarly in C++
218- if (any(param $ type_y [endp ] == 1 ) ) {
219- typey <- which(param $ type_y [endp ] == 1 ) - 1
220- } else { # in case no primary endpoint is specified
221- typey = - 1
222- }
223-
224218 # Use C++ code to run the simulations for parallel design
225- if (ncores == 1 & param.d $ dtype == " parallel" ) {
219+ if (param.d $ dtype == " parallel" ) {
226220 result <- run_simulations_par(nsim = nsim , n = n , muT = muT , muR = muR ,
227- SigmaT = as.matrix(SigmaT ),
228- SigmaR = as.matrix(SigmaR ),
229- lequi_tol = lequi.tol , uequi_tol = uequi.tol ,
230- alpha = alpha ,
231- dropout = as.numeric(c(dropout [treat1 ], dropout [treat2 ])),
232- typey = typey ,
233- adseq = param.d $ adjust == " seq" , k = k ,
234- arm_seed_T = arm_seed [,treat1 ],
235- arm_seed_R = arm_seed [,treat2 ],
236- ctype = param.d $ ctype ,
237- lognorm = param.d $ lognorm ,
238- TART = param $ TAR_list [[treat1 ]],
239- TARR = param $ TAR_list [[treat2 ]],
240- vareq = param.d $ vareq )
221+ SigmaT = as.matrix(SigmaT ),
222+ SigmaR = as.matrix(SigmaR ),
223+ lequi_tol = lequi.tol , uequi_tol = uequi.tol ,
224+ alpha = alpha ,
225+ dropout = as.numeric(c(dropout [treat1 ], dropout [treat2 ])),
226+ typey = param $ type_y ,
227+ adseq = param.d $ adjust == " seq" , k = k ,
228+ arm_seed_T = arm_seed [,treat1 ],
229+ arm_seed_R = arm_seed [,treat2 ],
230+ ctype = param.d $ ctype ,
231+ lognorm = param.d $ lognorm ,
232+ TART = param $ TAR_list [[treat1 ]],
233+ TARR = param $ TAR_list [[treat2 ]],
234+ vareq = param.d $ vareq )
235+ } else { # 2x2 cross-over design
236+ result <- run_simulations_2x2(nsim = nsim , ctype = param.d $ ctype ,
237+ lognorm = param.d $ lognorm ,
238+ n = n , muT = muT , muR = muR ,
239+ SigmaW = as.matrix(SigmaW ),
240+ lequi_tol = lequi.tol , uequi_tol = uequi.tol ,
241+ alpha = alpha , sigmaB = sigmaB ,
242+ dropout = dropout ,
243+ Eper = param $ Eper , Eco = param $ Eco ,
244+ typey = param $ type_y ,
245+ adseq = param.d $ adjust == " seq" , k = k ,
246+ arm_seed = arm_seed [,comp ])
247+ }
241248 rownames(result ) <- paste0(c(" totaly" , endp ,
242- paste0(" mu_" ,endp ," _" ,treat1 ),
243- paste0(" mu_" ,endp ," _" ,treat2 ),
244- paste0(" sd_" ,endp ," _" ,treat1 ),
245- paste0(" sd_" ,endp ," _" ,treat1 ))," Comp:" ,treat1 ," vs " ,treat2 )
246- return (result )
247- }
248-
249- result <- mcsapply(1 : nsim , function (i ){
250- arm_seedx <- arm_seed [i ,]
251- if (param.d $ dtype == " parallel" ) {
252- if (param.d $ ctype == " DOM" | (param.d $ ctype == " ROM" & param.d $ lognorm == TRUE ) ) {
253- outtest <- as.vector(test_par_dom(n = n , muT = muT , muR = muR ,
254- SigmaT = as.matrix(SigmaT ),
255- SigmaR = as.matrix(SigmaR ),
256- lequi_tol = lequi.tol ,uequi_tol = uequi.tol ,
257- alpha = alpha , k = k ,
258- dropout = as.numeric(c(dropout [treat1 ], dropout [treat2 ])),
259- typey = typey ,
260- adseq = param.d $ adjust == " seq" ,
261- arm_seedT = arm_seedx [treat1 ],
262- arm_seedR = arm_seedx [treat2 ],
263- TART = param $ TAR_list [[treat1 ]],
264- TARR = param $ TAR_list [[treat2 ]],
265- vareq = param.d $ vareq ))
266-
267-
268- }else { # ROM & normal distribution
269- outtest <- as.vector(test_par_rom(n = n , muT = muT , muR = muR ,
270- SigmaT = as.matrix(SigmaT ),
271- SigmaR = as.matrix(SigmaR ),
272- lequi_tol = lequi.tol ,
273- uequi_tol = uequi.tol ,
274- alpha = alpha , k = k ,
275- dropout = as.numeric(c(dropout [treat1 ],dropout [treat2 ])),
276- typey = typey ,
277- adseq = param.d $ adjust == " seq" ,
278- arm_seedT = arm_seedx [treat1 ],
279- arm_seedR = arm_seedx [treat2 ],
280- TART = param $ TAR_list [[treat1 ]],
281- TARR = param $ TAR_list [[treat2 ]],
282- vareq = param.d $ vareq ))
283- }
284-
285- names(outtest ) <- paste0(c(" totaly" , endp ,
286249 paste0(" mu_" ,endp ," _" ,treat1 ),
287250 paste0(" mu_" ,endp ," _" ,treat2 ),
288251 paste0(" sd_" ,endp ," _" ,treat1 ),
289252 paste0(" sd_" ,endp ," _" ,treat1 ))," Comp:" ,treat1 ," vs " ,treat2 )
290-
291- }else { # 2X2
292- if (param.d $ ctype == " DOM" | (param.d $ ctype == " ROM" & param.d $ lognorm == TRUE )){
293- outtest <- as.vector(test_2x2_dom(n = n , muT = muT , muR = muR ,
294- SigmaW = as.matrix(SigmaW ),
295- lequi_tol = lequi.tol ,
296- uequi_tol = uequi.tol ,
297- sigmaB = sigmaB ,
298- dropout = dropout ,
299- typey = typey ,
300- adseq = param.d $ adjust == " seq" ,
301- Eper = param $ Eper , Eco = param $ Eco ,
302- arm_seed = arm_seedx [comp ],
303- alpha = alpha ,
304- k = k ))
305- names(outtest ) <- paste0(c(" totaly" , endp ,
306- paste0(" mu_" ,endp ," _" ,treat1 ),
307- paste0(" mu_" ,endp ," _" ,treat2 ),
308- paste0(" sdw_" ,endp ," _" ,treat1 ),
309- paste0(" sdb_" ,endp ," _" ,treat1 ))," Comp:" ,treat1 ," vs " ,treat2 )
310-
311- }else { # ROM & normal distribution
312- outtest <- as.vector(test_2x2_rom(n = n , muT = muT , muR = muR ,
313- SigmaW = as.matrix(SigmaW ),
314- lequi_tol = lequi.tol ,
315- uequi_tol = uequi.tol ,
316- sigmaB = sigmaB ,
317- dropout = dropout ,
318- typey = typey ,
319- adseq = param.d $ adjust == " seq" ,
320- Eper = param $ Eper , Eco = param $ Eco , arm_seed = arm_seedx [comp ],
321- alpha = alpha ,
322- k = k ))
323-
324- }
325- names(outtest ) <- paste0(c(" totaly" , endp ,
326- paste0(" mu_" ,endp ," _" ,treat1 ),
327- paste0(" mu_" ,endp ," _" ,treat2 ),
328- paste0(" sdw_" ,endp ," _" ,treat1 ),
329- paste0(" sdb_" ,endp ," _" ,treat1 ))," Comp:" ,treat1 ," vs " ,treat2 )
330-
331- }
332-
333- outtest
334- }, mc.cores = ncores )
335- return (result )
253+ return (result )
336254}
337255
338256
@@ -493,6 +411,7 @@ mcsapply <- function (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE) {
493411# ' @param verbose Logical, if `TRUE`, the message is displayed; if `FALSE`, the message is suppressed.
494412# '
495413# ' @return NULL (invisible). This function is used for side effects (displaying messages).
414+ # ' @keywords internal
496415info_msg <- function (message , verbose ) {
497416 if (verbose ) message(message )
498417}
0 commit comments