Skip to content
Permalink
Browse files

fixed a degree of freedom typo in tcrit, updated example

  • Loading branch information...
jm3594 committed Oct 2, 2019
1 parent 8515bc6 commit 356f7e5a0ac5dc39ef71ce71b7cdb156d5cbf241
Showing with 7 additions and 15 deletions.
  1. +4 −13 R/crtpwr.sw.R
  2. +3 −2 man/crtpwr.sw.Rd
@@ -44,9 +44,10 @@
#' # Find the required number of clusters switching to intervention at each time point for a trial
#' # with alpha = 0.05, power = 0.80, nsubjects = 50, ntimes = 5, d = 1.5 units, icc = 0.2,
#' # rho_c = 0.80, rho_s = 0.50, and vart = 16 square-units.
#' crtpwr.sw(nsubjects = 50 , ntimes = 5, d = 1.5, icc = 0.2, rho_c = 0.80, rho_s = 0.50, vart = 16)
#' crtpwr.sw(nsubjects = 50, ntimes = 5, d = 1.5, icc = 0.2, rho_c = 0.80, rho_s = 0.50, vart = 16)
#' #
#' # The result, nclusters = 1.899014, suggests 2 clusters per condition should be used.
#' # The result, nclusters = 2.134918, suggests 3 clusters switching per time point should be used. This
#' # means that the total number of clusters in the study is nclusters*ntimes = 3*5 = 15.
#'
#' @references Hooper, R., Teerenstra, S., Hoop, E., and Eldridge, S. (2016)
#' Sample size calculation for stepped wedge and other longitudinal cluster
@@ -77,16 +78,6 @@ crtpwr.sw <- function(alpha = 0.05, power = 0.80, nclusters = NA,

target <- neednames[needind]

# create sample size adjustment
# in cross-sectional design, total number of subjects is
# nclusters*nsubjects*(ntimes + 1)
# if rho_s = 0, cross-sectional so nadj = ntimes + 1
if(rho_s == 0){
nadj <- ntimes + 1
} else {
nadj <- 1
}

# evaluate power
pwr <- quote({

@@ -105,7 +96,7 @@ crtpwr.sw <- function(alpha = 0.05, power = 0.80, nclusters = NA,
# zstat <- abs(d)/sqrt( 4*vart/(nclusters*nsubjects*ntimes)*VIF )
# pnorm(zcrit, zstat, lower.tail = FALSE)

tcrit <- qt(alpha/2, ntimes*(nclusters - 1), lower.tail = FALSE)
tcrit <- qt(alpha/2, ntimes*nclusters - (ntimes + 2), lower.tail = FALSE)
ncp <- abs(d)/sqrt( 4*vart/(nclusters*nsubjects*ntimes)*VIF )
pt(tcrit, ntimes*nclusters - (ntimes + 2), ncp, lower.tail = FALSE)#+
#pt(-tcrit, 2*(nclusters - 1), ncp, lower.tail = TRUE)

Some generated files are not rendered by default. Learn more.

0 comments on commit 356f7e5

Please sign in to comment.
You can’t perform that action at this time.