Title: | Computes Sample Size for a Stepped Wedge Design, using Simulation-Based Calculations |
---|---|
Description: | Provides a suite of functions for the sample size calculations and power analysis in a Stepped Wedge Trial. Contains functions for closed-form sample size calculation (based on a set of specific models) and simulation-based procedures that can extend the basic framework. |
Authors: | Gianluca Baio, Rosie Leech |
Maintainer: | Gianluca Baio <[email protected]> |
License: | file LICENSE |
Version: | 0.3.2 |
Built: | 2024-10-24 20:24:28 UTC |
Source: | https://github.com/giabaio/SWSamp |
Sample size calculations for a Stepped Wedge Trial
Package: | SWSamp |
Type: | Package |
Version: | 0.3.2 |
Date: | 2021-11-10 |
License: | GPL2 |
LazyLoad: | yes |
The package provides a suite of function to compute the power for a Stepped Wedge Design under different assumptions. The package can generate power based on simulations or use closed-formulae based on Hussey et Hughes
Gianluca Baio
Maintainer: Gianluca Baio ([email protected])
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
Hussey M and Hughes J. Design and analysis of stepped wedge cluster randomized trials. Contemporary Clinical Trials. 28(2):182-91. Epub 2006 Jul 7. Feb 2007
Given some inputs determines the optimal combination of clusters/time points to get a set level of power.
cluster.search( target.power = NULL, I = NULL, J = NULL, H = NULL, K, design = "cross-sec", mu = 0, b.trt, b.time = NULL, sigma.y = NULL, sigma.e = NULL, rho = NULL, sigma.a = NULL, rho.ind = NULL, sigma.v = NULL, n.sims = 1000, formula = NULL, family = "gaussian", natural.scale = TRUE, sig.level = 0.05, n.cores = NULL, ... )
cluster.search( target.power = NULL, I = NULL, J = NULL, H = NULL, K, design = "cross-sec", mu = 0, b.trt, b.time = NULL, sigma.y = NULL, sigma.e = NULL, rho = NULL, sigma.a = NULL, rho.ind = NULL, sigma.v = NULL, n.sims = 1000, formula = NULL, family = "gaussian", natural.scale = TRUE, sig.level = 0.05, n.cores = NULL, ... )
target.power |
The target power (eg 0.8) |
I |
A vector specifying the range in which to search for the optimal
number of clusters, eg |
J |
Number of time points |
H |
Number of units randomised at each time point |
K |
Average size of each cluster |
design |
type of design. Can be |
mu |
baseline outcome value |
b.trt |
Treatment effect |
b.time |
Time effect |
sigma.y |
total standard deviation |
sigma.e |
individual standard deviation |
rho |
Intra-class correlation coefficient |
sigma.a |
the sd of the the cluster-level intercept (default at NULL) |
rho.ind |
individual-level ICC (for cohorts) |
sigma.v |
the sd of the cluster-level slope (by intervention, default at NULL) |
n.sims |
Number of simulations to be used (default=1000) |
formula |
Formula describing the model to be used |
family |
The model family to be used. Default value is 'gaussian' and other possibile choices are 'binomial' or 'poisson' |
natural.scale |
Indicator for whether the input is passed on the natural scale or on the scale of the linear predictor. By default is set to TRUE. In the case of family='gaussian' it does not have any effect, since the link for the linear predictor is the identity. But for family='binomial' or family='poisson', the user has to specify when the input is given on the logit or log scale |
sig.level |
Significance level (default=0.05) |
n.cores |
Specifies the number of processors to be used for the computation (default=NULL, which means that R will try and figure out) |
... |
Additional arguments |
Optimum_I |
The value of the optimal number of clusters |
power |
The estimated power in correspondence of the optimal I |
time2run |
Computational time |
Rosie Leach
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
Hussey M and Hughes J. Design and analysis of stepped wedge cluster randomized trials. Contemporary Clinical Trials. 28(2):182-91. Epub 2006 Jul 7. Feb 2007
#cluster.search(I=c(4,10),target.power=.8,J=6,K=30,mu=1.5,b.trt=.8,rho=0, #family="poisson",n.sims=10)
#cluster.search(I=c(4,10),target.power=.8,J=6,K=30,mu=1.5,b.trt=.8,rho=0, #family="poisson",n.sims=10)
Sample size calculations for a SWT using a cross-sectional design. This is based on (the correct version) of Woertman et al (2013), as described in Baio et al (2015).
DE.woert( outcome = "cont", input, K, J, B = 1, T = 1, rho, sig.level = 0.05, power = 0.8 )
DE.woert( outcome = "cont", input, K, J, B = 1, T = 1, rho, sig.level = 0.05, power = 0.8 )
outcome |
String. Type of outcome. Options are |
input |
input = a list containing the arguments. This differs depending on the type of outcome, as follows: - continuous outcome: 1) delta (treatment effect) 2) sd (standard deviation) - binary outcome: 1) p1 (baseline probability of outcome) 2) either p2 (treatment probability of outcome), or OR (treatment effect as OR) - count outcome: 1) r1 (baseline rate of outcome) 2) either r2 (treatment rate of outcome), or RR (treatment effect as RR) |
K |
average cluster size |
J |
number of time points (excluding baseline) |
B |
number of baseline measurement times |
T |
number of measurement times during each crossover |
rho |
ICC |
sig.level |
significance level (default = 0.05) |
power |
Power (default = 0.8) |
n.cls.swt |
Number of clusters required to reach the pre-specified power with the given significance level. |
n.pts |
The total number of participants required. |
DE.woert |
The resulting Design Effect. |
CF |
The resulting Correction Factor. |
n.rct |
The original individual RCT sample required to reach the pre-specified power with the given significance level. |
Gianluca Baio
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
# Continuous outcome input <- list(delta=-0.3875,sd=1.55) K <- 20 J <- 5 rho <- .2 DE.woert(input=input,K=K,J=J,rho=rho) # # Binary outcome input <- list(OR=.53,p1=.26) DE.woert(outcome="bin",input=input,K=K,J=J,rho=rho) # # Count outcome input <- list(RR=.8,r1=1.5) DE.woert(outcome="count",input=input,K=K,J=J,rho=rho)
# Continuous outcome input <- list(delta=-0.3875,sd=1.55) K <- 20 J <- 5 rho <- .2 DE.woert(input=input,K=K,J=J,rho=rho) # # Binary outcome input <- list(OR=.53,p1=.26) DE.woert(outcome="bin",input=input,K=K,J=J,rho=rho) # # Count outcome input <- list(RR=.8,r1=1.5) DE.woert(outcome="count",input=input,K=K,J=J,rho=rho)
Sample size calculations for binary outcomes based on the formula provided by Hussey and Hughes (2007)
HH.binary( p1, OR, I, J, K, rho = 0, sig.level = 0.05, which.var = "within", X = NULL )
HH.binary( p1, OR, I, J, K, rho = 0, sig.level = 0.05, which.var = "within", X = NULL )
p1 |
Baseline probability of the outcome (for the controls) |
OR |
Value of the expected Odds Ratio (for the intervention vs control) |
I |
Number of clusters |
J |
Number of time points |
K |
Average size of each cluster |
rho |
Intra-class correlation coefficient (default=0) |
sig.level |
Significance level (default=0.05) |
which.var |
String character specifying which variance to be considered
(options are the default value |
X |
A design matrix for the stepped wedge design, indicating the time at which each of the clusters should switch the active intervention. By default is NULL and automatically computed, but can be passed as an extra argument as a user-defined matrix with I rows and (J+1) columns |
power |
The resulting power |
sigma.y |
The estimated total (marginal) sd for the outcome |
sigma.e |
The estimated residual sd |
sigma.a |
The resulting cluster-level sd |
setting |
A list including the following values: - n.clusters = The number of clusters - n.time.points = The number of 'active' time points - avg.cluster.size = The average cluster size - design.matrix = The design matrix for the SWT under consideration |
Gianluca Baio
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
Hussey M and Hughes J. Design and analysis of stepped wedge cluster randomized trials. Contemporary Clinical Trials. 28(2):182-91. Epub 2006 Jul 7. Feb 2007
HH.binary(p1=.26,OR=.55,I=10,J=5,K=20,rho=.2)
HH.binary(p1=.26,OR=.55,I=10,J=5,K=20,rho=.2)
Sample size calculations for count outcomes based on the formula provided by Hussey and Hughes (2007)
HH.count( lambda1, RR, I, J, K, rho = 0, sig.level = 0.05, which.var = "within", X = NULL )
HH.count( lambda1, RR, I, J, K, rho = 0, sig.level = 0.05, which.var = "within", X = NULL )
lambda1 |
Baseline value for the rate at which the outcome occurs |
RR |
Relative risk (of the intervention vs the control) |
I |
Number of clusters |
J |
Number of time points |
K |
Average size of each cluster |
rho |
Intra-class correlation coefficient (default=0) |
sig.level |
Significance level (default=0.05) |
which.var |
String character specifying which variance to be considered
(options are the default value |
X |
A design matrix for the stepped wedge design, indicating the time at which each of the clusters should switch the active intervention. By default is NULL and automatically computed, but can be passed as an extra argument as a user-defined matrix with I rows and (J+1) columns |
power |
The resulting power |
sigma.y |
The estimated total (marginal) sd for the outcome |
sigma.e |
The estimated residual sd |
sigma.a |
The resulting cluster-level sd |
setting |
A list including the following values: - n.clusters = The number of clusters - n.time.points = The number of 'active' time points - avg.cluster.size = The average cluster size - design.matrix = The design matrix for the SWT under consideration |
Gianluca Baio
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
Hussey M and Hughes J. Design and analysis of stepped wedge cluster randomized trials. Contemporary Clinical Trials. 28(2):182-91. Epub 2006 Jul 7. Feb 2007
HH.count(lambda1=1.55,RR=.87,I=10,J=5,K=20,rho=.2)
HH.count(lambda1=1.55,RR=.87,I=10,J=5,K=20,rho=.2)
Sample size calculations for normal outcomes based on the formula provided by Hussey and Hughes (2007)
HH.normal( mu, b.trt, sigma, I, J, K, rho = 0, sig.level = 0.05, which.var = "within", X = NULL )
HH.normal( mu, b.trt, sigma, I, J, K, rho = 0, sig.level = 0.05, which.var = "within", X = NULL )
mu |
Mean value of the outcome for the controls |
b.trt |
Treatment effect against controls |
sigma |
Value of the standard deviation (if |
I |
Number of clusters |
J |
Number of time points |
K |
Average size of each cluster |
rho |
Intra-class correlation coefficient (default=0) |
sig.level |
Significance level (default=0.05) |
which.var |
String character specifying which variance to be considered
(options are the default value |
X |
A design matrix for the stepped wedge design, indicating the time at which each of the clusters should switch the active intervention. By default is NULL and automatically computed, but can be passed as an extra argument as a user-defined matrix with I rows and (J+1) columns |
power |
The resulting power |
sigma.y |
The estimated total (marginal) sd for the outcome |
sigma.e |
The estimated residual sd |
sigma.a |
The resulting cluster-level sd |
setting |
A list including the following values: - n.clusters = The number of clusters - n.time.points = The number of 'active' time points - avg.cluster.size = The average cluster size - design.matrix = The design matrix for the SWT under consideration |
Gianluca Baio
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
Hussey M and Hughes J. Design and analysis of stepped wedge cluster randomized trials. Contemporary Clinical Trials. 28(2):182-91. Epub 2006 Jul 7. Feb 2007
HH.normal(mu=.3,b.trt=-.3875,I=10,J=5,K=20,rho=.2,sigma=1.55)
HH.normal(mu=.3,b.trt=-.3875,I=10,J=5,K=20,rho=.2,sigma=1.55)
Simulates trial data for a SWT with normally distributed outcome
make.swt( I = NULL, J = NULL, H = NULL, K, design = "cross-sec", mu = NULL, b.trt, b.time = NULL, sigma.y = NULL, sigma.e = NULL, rho, sigma.a = NULL, rho.ind = NULL, sigma.v = NULL, X = NULL, family = "gaussian", natural.scale = TRUE )
make.swt( I = NULL, J = NULL, H = NULL, K, design = "cross-sec", mu = NULL, b.trt, b.time = NULL, sigma.y = NULL, sigma.e = NULL, rho, sigma.a = NULL, rho.ind = NULL, sigma.v = NULL, X = NULL, family = "gaussian", natural.scale = TRUE )
I |
Number of clusters |
J |
Number of time points |
H |
Number of units randomised at each time point |
K |
Average size of each cluster |
design |
type of design. Can be |
mu |
baseline outcome value |
b.trt |
Treatment effect |
b.time |
Time effect |
sigma.y |
total standard deviation |
sigma.e |
individual standard deviation |
rho |
Intra-class correlation coefficient |
sigma.a |
the sd of the the cluster-level intercept (default at NULL) |
rho.ind |
individual-level ICC (for cohorts) |
sigma.v |
the sd of the cluster-level slope (by intervention, default at NULL) |
X |
A design matrix for the SWT. Default at NULL (will be computed automatically) |
family |
The model family to be used. Default value is 'gaussian' and other possibile choices are 'binomial' or 'poisson' |
natural.scale |
Indicator for whether the input is passed on the natural scale or on the scale of the linear predictor. By default is set to TRUE. In the case of family='gaussian' it does not have any effect, since the link for the linear predictor is the identity. But for family='binomial' or family='poisson', the user has to specify when the input is given on the logit or log scale |
data |
A data frame containing the resulting simulated dataset |
Gianluca Baio, Rosie Leach
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
See Also sim.power
Simulation-based power calculations for a SWT with normally distributed outcome
sim.power( I, J, H = NULL, K, design = "cross-sec", mu = 0, b.trt, b.time = NULL, sigma.y = NULL, sigma.e = NULL, rho = NULL, sigma.a = NULL, rho.ind = NULL, sigma.v = NULL, n.sims = 1000, formula = NULL, family = "gaussian", natural.scale = TRUE, sig.level = 0.05, n.cores = NULL, method = "lme", plot = FALSE, ... )
sim.power( I, J, H = NULL, K, design = "cross-sec", mu = 0, b.trt, b.time = NULL, sigma.y = NULL, sigma.e = NULL, rho = NULL, sigma.a = NULL, rho.ind = NULL, sigma.v = NULL, n.sims = 1000, formula = NULL, family = "gaussian", natural.scale = TRUE, sig.level = 0.05, n.cores = NULL, method = "lme", plot = FALSE, ... )
I |
Number of clusters |
J |
Number of time points |
H |
Number of units randomised at each time point |
K |
Average size of each cluster |
design |
type of design. Can be |
mu |
baseline outcome value |
b.trt |
Treatment effect |
b.time |
Time effect |
sigma.y |
total standard deviation |
sigma.e |
individual standard deviation |
rho |
Intra-class correlation coefficient |
sigma.a |
the sd of the the cluster-level intercept (default at NULL) |
rho.ind |
individual-level ICC (for cohorts) |
sigma.v |
the sd of the cluster-level slope (by intervention, default at NULL) |
n.sims |
Number of simulations to be used (default=1000) |
formula |
Formula describing the model to be used |
family |
The model family to be used. Default value is 'gaussian' and other possibile choices are 'binomial' or 'poisson' |
natural.scale |
Indicator for whether the input is passed on the natural scale or on the scale of the linear predictor. By default is set to TRUE. In the case of family='gaussian' it does not have any effect, since the link for the linear predictor is the identity. But for family='binomial' or family='poisson', the user has to specify when the input is given on the logit or log scale |
sig.level |
Significance level (default=0.05) |
n.cores |
Specifies the number of processors to be used for the computation (default=NULL, which means that R will try and figure out) |
method |
A string specifying the method to be used for the calculation.
The default value is |
plot |
Shows a plot of the moving average of the resulting power after
10
of the estimate towards some common value. The default is |
... |
Additional optional arguments. The user can specify a function
named |
power |
The resulting estimated power, for the given
configuration. If the model does not include random effects, this is based
on the p-value computed by |
time2run |
Running time, in seconds |
ci.power |
Estimated 95% confidence interval for the power - based on normal approximation |
theta |
Estimated treatment effect with standard error |
rnd.eff.sd |
Estimated variance components |
setting |
A list summarising the assumptions in terms of number of clusters, time points, type of model, formula used |
Gianluca Baio
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.
mu1=0.3 b.trt=-0.3875 sigma.e=1.55 J=5 K=20 sig.level=0.05 n.sims=10 rho=0.5 pow.cont <- sim.power(I=14,J=J,H=NULL,K=K,rho=rho,mu=mu1,sigma.e=sigma.e,b.trt=b.trt, formula=NULL,n.sims=n.sims,sig.level=sig.level,n.cores=2) pow.cont$power pow.cont$ci pow.cont$time2run.sec pow.cont$rnd.eff.sd^2
mu1=0.3 b.trt=-0.3875 sigma.e=1.55 J=5 K=20 sig.level=0.05 n.sims=10 rho=0.5 pow.cont <- sim.power(I=14,J=J,H=NULL,K=K,rho=rho,mu=mu1,sigma.e=sigma.e,b.trt=b.trt, formula=NULL,n.sims=n.sims,sig.level=sig.level,n.cores=2) pow.cont$power pow.cont$ci pow.cont$time2run.sec pow.cont$rnd.eff.sd^2
Constructs a basic SWT design matrix
sw.design.mat(I, J, H = NULL)
sw.design.mat(I, J, H = NULL)
I |
Number of clusters |
J |
Number of time points |
H |
Number of units randomised at each time point |
Returns a design matrix X
Gianluca Baio
Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.