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
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
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
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
There are two ways of installing
SWSamp. A "stable" version is packaged and binary files are available for Windows and as source. To install the stable version on a Windows machine, run the following commands
Note that you need to specify a vector of repositories - the first one hosts
SWSamp, while the second one should be an official CRAN mirror. You can select whichever one you like, but a CRAN mirror must be provided, so that
install.packages() can also install the "dependencies" (e.g. other packages that are required for
survHE to work). The third one is used to install the package
INLA, which can be used to perform simulation-based sample size calculations using a Bayesian approach. This process can be quite lengthy, if you miss many of the relevant packages.
To install from source (e.g. on a Linux machine), run
The second way involves using the "development" version of
SWSamp - this will usually be updated more frequently and may be continuously tested. On Windows machines, you need to install a few dependencies, including Rtools first, e.g. by running
pkgs <- c("foreach", "doParallel", "iterators", "parallel", "Matrix","lme4","INLA","Rtools","devtools")
repos <- c("https://cran.rstudio.com", "https://www.math.ntnu.no/inla/R/stable")
install.packages(pkgs,repos=repos,dependencies = "Depends")
before installing the package using
Under Linux or MacOS, it is sufficient to install the package via
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.
Current release: 0.3 (17 August 2016).