SWSamp: Simulation-based sample size calculations for a Stepped Wedge Trial (and more)
Introduction
SWSamp
is an R
package designed to allow a wide range of simulation-based sample size calculations, specifically (but not exclusively!) for a Stepped Wedge Trial (SWT) and is based on the general framework described in Baio et al (2015). In its current version, SWSamp
consists of 5 main functions: the first one (which is currently in fact specified by three different commands) performs the analytic sample size calculations using the method of Hussey and Hughes (2007). This can be used as a quick alternative for more standard designs or as a first-order approximation in the case of complicated designs (eg including multiple layers of correlation). The second function replicates the sample size calculations based on the (correct form of) the “design effect” specified by Woertman et al (2013). This too can be used very effectively in relatively standard cases, but is less efficient in cases of more complex designs. The core functions of SWSamp
are make.swt
, which can be used to simulate data as obtained by a reasonably wide range of possible SWTs and sim.power
, which actually performs the simulation-based computation of the required sample size. More importantly, sim.power
can be used to compute the sample size for other data generating processes (DGPs) or designs (ie not specifically for a SWT), which increases the applicability of SWSamp
.
In order to speed up the computation process (which can be intensive, under particularly complex designs), SWSamp
is designed to take full advantage of R
multi-core processing. For this reason, SWSamp
“imports” the NAMESPACE of the R
packages foreach
, doParallel
, iterators
and parallel
(technically, this means that these packages need to be installed on the user’s local machine, for SWSamp
to work). In addition to these, SWSamp formally “depends” on the R package lme4, which can be used to fit linear and generalized linear mixed-effects models. This is relevant when analysing a SWT (which invariably includes some form of clustering in the DGP). Other modelling strategies could be used instead, for example Generalised Estimating Equations (GEE, Zeger and Liang 1986) or a full Bayesian model, eg based on Integrated Nested Laplace Approximation (INLA, Rue et al, 2009). In the current release (version 0.3), the Bayesian approach based on INLA is implemented and can be used by setting the optional parameter method="inla"
.
Installation
On Windows machines, you need to install a few dependencies, including Rtools first, e.g. by running
<- c("foreach", "doParallel", "iterators", "parallel", "Matrix","lme4",
pkgs "INLA","Rtools","remotes")
<- c("https://cran.rstudio.com", "https://www.math.ntnu.no/inla/R/stable")
repos install.packages(pkgs,repos=repos,dependencies = "Depends")
before installing the package using remotes
:
::install_github("giabaio/SWSamp") remotes
Under Linux or MacOS, it is sufficient to install the package via devtools
:
install.packages("remotes")
:install_github("giabaio/SWSamp") remotes
A full documentation guide available here, including a description of the methods specifically used for a SWT and some for more general data-generating processes.
Last updated: 17 July 2023