Learn R Programming

swCRTdesign (version 3.3)

swPwr: Power of Stepped Wedge Cluster Randomized Trial (SW CRT)

Description

swPwr returns (two-sided) power of treatment effect (\(\theta\)) for the specified SW CRT design using a linear models weighted least squares (WLS) approach for an immediate treatment effect (IT) model or an exposure time indicator (ETI) model (Kenny et al, 2022). The response/outcome of interest can be binomial or Gaussian distributed and is assumed to come from a model with random intercepts, random treatment effects, and random cluster-specific time effects. Variance components can be specified using either tau, eta, rho, and gamma, or icc and cac (see details). If a random intercepts only model is used (i.e., eta and gamma are 0 and n is constant over clusters and time), then the power calculation is comparable to the closed-form formula of [Hussey and Hughes, 2007]. See [Voldal et al., 2020] for more guidance. This function is also available as a Shiny app at https://swcrtdesign.shinyapps.io/stepped_wedge_power_calculation/.

Usage

swPwr(design, distn, n, mu0, mu1, H=NULL, sigma, tau, eta, rho, gamma,
icc, cac, alpha=0.05, retDATA=FALSE, silent=FALSE)

Value

numeric (matrix): swPwr returns the power of treatment effect (\(\theta\)), where the variance of treatment effect is computed by WLS.

numeric (list): swPwr returns all specified and computed items as objects of a list if retDATA = TRUE.

design

list: The stepped wedge design object as input.

distn

character: Distribution assumed (gaussian or binomial).

n

integer (scalar, vector, or matrix): Number of observations: (scalar) for all clusters and all time points; (vector) for each cluster at all time points; and (matrix) for each cluster at each time point, where rows correspond to clusters and columns correspond to time.

mu0

numeric (scalar): Mean outcome in the control group.

mu1

numeric (scalar): Mean outcome in intervention group. Note: treatment effect is difference in means \(\theta = \mu_1 - \mu_0\).

sigma

numeric (scalar): Standard deviation input. For binomial distribution, sigma = NA

tau

numeric (scalar): Standard deviation of random intercepts.

eta

numeric (scalar): Standard deviation of random treatment effects.

rho

numeric (scalar): Correlation between random intercepts and random treatment effects.

gamma

numeric (scalar): Standard deviation of random time effects.

icc

numeric (scalar): Within-period intra-cluster correlation. Can be used with CAC instead of tau, eta, rho, and gamma; see details.

cac

numeric (scalar): Cluster auto-correlation. Can be used with ICC instead of tau, eta, rho, and gamma; see details.

alpha

numeric (scalar): Statistical significance level.

Xmat

numeric (matrix): Design matrix for this SW CRT design.

Wmat

numeric (matrix): Covariance matrix for this SW CRT design.

var.theta.WLS

numeric (scalar): Variance estimate of \(\theta\) using weighted least squares (WLS) for this SW CRT design.

pwrWLS

numeric (scalar): Power of treatment effect (\(\theta\)) using weighted least squares (WLS) for this SW CRT design.

pwrCLOSED

numeric (scalar): Power of treatment effect (\(\theta\)) using closed-form formula from Hughes, et al. (2003) for this SW CRT design. Returned if eta and gamma are 0 and n is constant over clusters and time.

Arguments

design

list: A stepped wedge design object, typically from swDsn, that includes at least the following components: ## swDsn, swDsn.unique.clusters, clusters, n.clusters, total.time

distn

character: Distribution assumed (gaussian or binomial). Currently, 'Binomial' implies Bernoulli.

n

integer (scalar, vector, or matrix): Number of observations: (scalar) for all clusters and all time points; (vector) for each cluster at all time points; and (matrix) for each cluster at each time point, where rows correspond to clusters and columns correspond to time. n can also be used to specify a design with transition periods (e.g. in the first time period that each sequence receives treatment, no observations are collected from that sequence). Simply define n as a matrix with a sample size of 0 during every transition period.

mu0

numeric (scalar): Mean outcome in the control group. See also documentation for H, below.

mu1

numeric (scalar): Mean outcome in the treatment group. Note: Treatment effect is the difference in means \(\theta = \mu_1 - \mu_0\). See also documentation for H, below.

H

numeric (vector): If NULL, then swPwr assumes an immediate, constant treatment effect (IT) model. If not NULL, then an exposure time indicator (ETI) model is assumed and H should be a vector as long as the longest treatment effect lag (typically, number of time periods minus one). H specifies the desired linear combination of exposure time treatment effects. For example, in a stepped wedge trial with 5 time periods and four exposure times, H = rep(.25,4) gives the average treatment effect over the four exposure times; H = c(0,0,.5,.5) ignores the first two periods after the intervention is introduced and averages the remaining periods. mu0 and mu1 give expected values of the linear combination of exposure time treatment effects under the null and alternative hypotheses, respectively.

sigma

numeric (scalar): Standard deviation when assuming Gaussian distribution (distn=gaussian). For binomial distribution \(\sigma^2\) is automatically set to \(\bar{\mu}(1-\bar{\mu})\) where \(\bar{\mu} = (\mu_1 + \mu_0)/2\)

tau

numeric (scalar): Standard deviation of random intercepts.

eta

numeric (scalar): Standard deviation of random treatment effects.

rho

numeric (scalar): Correlation between random intercepts and random treatment effects.

gamma

numeric (scalar): Standard deviation of random time effects.

icc

numeric (scalar): Within-period intra-cluster correlation. Can be used with CAC instead of tau, eta, rho, and gamma; see details.

cac

numeric (scalar): Cluster auto-correlation. Can be used with ICC instead of tau, eta, rho, and gamma; see details.

alpha

numeric (scalar): Two-sided statistical significance level.

retDATA

logical: if TRUE, all stored (input, intermediate, and output) values of swPwr are returned. Default value is FALSE.

silent

logical: if TRUE, hides a warning about differences in argument order between version 3.0 and prior versions. When n is not a scalar, also hides reminder about order of entries in n. Default value is FALSE.

Author

James P Hughes, Navneet R Hakhu, and Emily C Voldal

Details

The two-sided statistical power of treatment effect \((\theta = \mu_1 - \mu_0)\) is $$ Pwr(\theta) = \Phi( Z - z_{1 - \alpha /2} ) + \Phi( -Z - z_{1 - \alpha /2} ) $$ where $$ Z = \frac{ |\theta| }{ \sqrt{Var(\hat{\theta}_{WLS})} } $$ and \(\Phi\) is the cumulative distribution function of the standard normal \(N(0,1)\) distribution. If H is non-NULL then the \(\mu\) are assumed to be equal to H\(\delta\) where \(\delta\) is a vector of exposure time treatment effects.

When eta (and rho) are 0, instead of using tau, eta, rho, and gamma, the icc and cac can be used to define the variability of the random intercepts and time effects. In this model, $$ ICC = \frac{\tau^2+\gamma^2}{\tau^2+\gamma^2+\sigma^2} $$ $$ CAC = \frac{\tau^2}{\tau^2+\gamma^2} $$

References

Hussey MA, Hughes JP. Design and analysis of stepped wedge cluster randomized trials. Contemporary Clinical Trials 2007;28:182-191.

Kenny A, Voldal E, Xia F, Heagerty PJ, Hughes JP. Analysis of stepped wedge cluster randomized trials in the presence of a time-varying treatment effect. Statistics in Medicine, in press, 2022.

Voldal EC, Hakhu NR, Xia F, Heagerty PJ, Hughes JP. swCRTdesign: An R package for stepped wedge trial design and analysis. Computer Methods and Programs in Biomedicine 2020;196:105514.

Examples

Run this code
library(swCRTdesign)
# Example 1 (Random Intercepts Only, standard Stepped Wedge (SW) design)
swPwr.Ex1.RIO.std <- swPwr(swDsn(c(6,6,6,6)), distn="binomial",
n=120, mu0=0.05, mu1=0.035, tau=0.01, eta=0, rho=0, gamma=0, alpha=0.05, retDATA=FALSE)
swPwr.Ex1.RIO.std

# Example 2 (Random Intercepts Only, extended SW design)
swPwr.Ex1.RIO.extend <- swPwr(swDsn(c(6,6,6,6), extra.time=3), distn="binomial",
n=120, mu0=0.05, mu1=0.035, tau=0.01, eta=0, rho=0, gamma=0,
alpha=0.05, retDATA=FALSE)
swPwr.Ex1.RIO.extend

# Example 3 (Independent Random Intercepts and Treatment effects, standard SW design)
swPwr.Ex1.IRIS <- swPwr(swDsn(c(6,6,6,6)), distn="binomial",
n=120, mu0=0.05, mu1=0.035, tau=0.01, eta=0.0045, rho=0, gamma=0,
alpha=0.05, retDATA=FALSE)
swPwr.Ex1.IRIS

# Example 4 (Correlated Random Intercepts and Slopes, standard SW design)
swPwr.Ex1.CRIS <- swPwr(swDsn(c(6,6,6,6)), distn="binomial",
n=120, mu0=0.05, mu1=0.035, tau=0.01, eta=0.0045, rho=0.4, gamma=0,
alpha=0.05, retDATA=FALSE)
swPwr.Ex1.CRIS

# Example 5 (Random time effect and correlated Random Intercepts and Slopes, standard SW design)
swPwr.Ex1.RTCRIS <- swPwr(swDsn(c(6,6,6,6)), distn="binomial",
n=120, mu0=0.05, mu1=0.035, tau=0.01, eta=0.0045, rho=0.4, gamma = 0.1,
alpha=0.05, retDATA=FALSE)
swPwr.Ex1.RTCRIS

#Example 6 (Sample size varying by cluster)
sample.size.vector <- c(35219,53535,63785,456132,128670,96673,
           51454,156667,127440,68615,56502,17719,
           75931,58655,52874,75936)
swPwr.Ex1.vector <- swPwr(swDsn(c(4,3,5,4)), distn="gaussian",
n=sample.size.vector, mu0=2.66, mu1=2.15,
sigma=sqrt(1/2.66), tau=0.31, eta=0.2, rho=0, gamma = 0.15,
alpha=0.05, retDATA=FALSE)
swPwr.Ex1.vector

#Example 7 (Sample size varying by cluster and time)
sample.size.matrix <- matrix(c(26, 493,  64,  45,  48, 231, 117,  17,  49,  36,  19,  77, 67, 590,
261, 212,  67, 318, 132,  58,  44,  57,  59,  78, 115, 532, 176, 199,  73, 293, 129,  79,  51,
62, 109,  94, 174, 785, 133,  79, 120, 305, 224,  99,  83,  79, 122, 122, 94, 961,  90, 131, 166,
352, 316,  59,  54, 131, 101, 133),nrow=12,ncol=5, byrow=FALSE)
swPwr.Ex1.matrix <- swPwr(swDsn(c(3,3,3,3)), distn="binomial",
n=sample.size.matrix, mu0=0.08, mu1=0.06, tau=0.017, eta=0.006, rho=-0.5, gamma = 0,
alpha=0.05, retDATA=FALSE)
swPwr.Ex1.matrix

#Example 8 (Using ICC and CAC)
swPwr.Ex1.icccac <- swPwr(swDsn(c(6,6,6,6)), distn="gaussian",
n=120, mu0=0.05, mu1=0.035, sigma=0.1, icc=0.02, cac=0.125, alpha=0.05, retDATA=FALSE)
swPwr.Ex1.icccac

Run the code above in your browser using DataLab