diff --git a/npRCT_functions.R b/npRCT_functions.R new file mode 100644 index 0000000..54da803 --- /dev/null +++ b/npRCT_functions.R @@ -0,0 +1,44 @@ +# -------------------------------------------- +# --------------npRCT Function---------------- +# -------------------------------------------- + + + +npRCT.pwr.t.test <- function(d1 = 0.5, d2 = 0.5, + sig.level1 = 0.05, sig.level2 = 0.05, + power1 = 0.8, power2 = 0.8, + type1 = "two.sample", type2 = "two.sample", + alternative1 = "two.sided", alternative2 = "two.sided", + suppressInfo = FALSE) { + + # Load required package + require("pwr") + + # Run power calculation for first t-test (traditional part of RCST) + t1 <- pwr.t.test(d = d1, sig.level = sig.level1, power = power1, type = type1, + alternative = alternative1) + + # Run power calculation for second t-test (stratified part of RCST) + t2 <- pwr.t.test(d = d2, sig.level = sig.level2, power = power2, type = type2, + alternative = alternative2) + + # Compute sample sizes (per group) + n1 = ceiling(t1$n) + n2 = t2$n + n2_rct = ceiling(n2 / 2) # n still traditionally randomised in stratified part + + n_strat = n1 - n2_rct + n_total = n_strat + n2 + + # Create output + output = data.frame(n_strat = n_strat, + n_total = n_total) + + # Information message for output + if(suppressInfo == FALSE) { + cat("Find here sample sizes per group for the time point\nof stratification (=n_strat) as well as for the complete\nRandomised Controlled Stratified Trial (=n_total)\n\n") + } + + # End function by returning the output data.frame + return(output) +}