Learn R Programming

swCRTdesign (version 2.1)

swSim: Simulating individual-level data for specified study design of Stepped Wedge Cluster Randomized Trial (SW CRT)

Description

swSim returns individual-level data set of a SW CRT study design for the specified number of clusters per wave, fractional treatment effect at each time after crossing over from control, time (standard SW CRT time computed; extending trial beyond standard time needs to be specified by the user), family (and link function), number of individuals per cluster per wave, mean in control arm, mean in treatment arm, time effect, pooled standard deviation for both arms, standard deviation of random intercepts, standard deviation of random slopes, correlation between random intercepts and random slopes, time point label, specified random seed, and option to simulate data with time on treatment lag.

Usage

swSim(design, family, n, mu0, mu1, time.effect, sigma, tau, eta, rho = 0, time.lab = NULL, seed = NULL, retTimeOnTx = FALSE)

Arguments

design
list: A stepped wedge design object, typically from swDsn, that includes at least the following components: ## swDsn, clusters, n.clusters, total.time
family
character: Used in typical way. However, only Gaussian, Binomial, and Poisson families accepted. Also, only identity, logit, and log links accepted, but any combination of the three families and three link functions (i.e., do not have to specify canonical link). ***NOTE: It is the users responsibility to make sure specified parameters (mu0, mu1, time.effect, sigma, tau, eta, rho) are ALL on SAME scale as specified link function.***
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.
mu0
numeric (scalar): Mean in control arm/group.
mu1
numeric (scalar): Mean in treatment arm/group.
time.effect
integer (scalar or vector): Time effect at each time point (added to mean at each time).
sigma
numeric (scalar): Pooled treatment and control arm standard deviation. Ignored if family != Gaussian
tau
numeric (scalar): Standard deviation of random intercepts.
eta
numeric (scalar): Standard deviation of random slopes.
rho
numeric (scalar): Correlation between random intercepts and random slopes. The default value is 0 (i.e., uncorrelated)
time.lab
character (vector): Labeling for time points when output is display; choice of labeling does not affect results.
seed
integer (scalar): An initial random seed.
retTimeOnTx
logical: If TRUE, simulates data with time on treatment lag. If FALSE, simulates data ignoring time on treatment lag. The default is FALSE.

Value

numeric (data frame): Returns the following (individual-level) variables corresponding to the specified SW CRT design:

References

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

Examples

Run this code
library(swCRTdesign)
# Example 1 [ n = scalar; can be vector (for different n for each cluster, 
# n=rep(120,22)) or matrix (different n for each cluster at each time point, 
# n=matrix(120,22,5)) ]

# generate SW data (fractional treatment effect)
design <- swDsn(clusters=c(6,6,6,4), tx.effect=c(0.8,0.9,1.0), extra.time=0, all.ctl.time0=TRUE)
swGenData.nScalar <- swSim( design,
family=binomial(link="logit"), n=120, 
mu0=log(0.1/0.9), mu1=log(0.9) + log(0.1/0.9),
time.effect=c(0,.2,.3,.4,.5)*0, sigma=1, tau=0.2, eta=0, 
rho=0, time.lab=seq(0,12,3), seed=5, retTimeOnTx=FALSE)

# summarize SW data by wave
swSummary(response.var, tx.var, time.var, cluster.var, swGenData.nScalar, 
type="mean", digits=3)$response.wave

swSummary(response.var, tx.var, time.var, cluster.var, swGenData.nScalar, 
type="mean", digits=3)$swDsn

Run the code above in your browser using DataLab