Skip to content

Commit

Permalink
Included script with function
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Kappelmann committed Dec 13, 2019
1 parent 6901d5f commit 81958e6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions npRCT_functions.R
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 81958e6

Please sign in to comment.