This is the main function of the SteppedPower package. It calls the constructor functions for the design matrix and covariance matrix, and then calculates the variance of the intervention effect estimator. The latter is then used to compute the power of a Wald test of a (given) intervention effect.
wlsPower(
Cl = NULL,
timepoints = NULL,
DesMat = NULL,
trtDelay = NULL,
incomplete = NULL,
timeAdjust = "factor",
period = NULL,
dsntype = "SWD",
mu0,
mu1,
marginal_mu = FALSE,
sigma = 1,
tau = NULL,
eta = NULL,
tauAR = NULL,
rho = NULL,
gamma = NULL,
psi = NULL,
alpha_0_1_2 = NULL,
CovMat = NULL,
N = NULL,
Power = NULL,
family = "gaussian",
N_range = c(1, 1000),
sig.level = 0.05,
dfAdjust = "none",
INDIV_LVL = FALSE,
verbose = 1
)
integer (vector), number of clusters per sequence group (in SWD), or number in control and intervention (in parallel designs)
numeric (scalar or vector), number of timepoints (periods). If design is swd, timepoints defaults to length(Cl)+1. Defaults to 1 for parallel designs.
matrix of dimension ... , if supplied, `timepoints`,`Cl`,`trtDelay` are ignored.
numeric (possibly vector), value(s) between 0 and 1 specifying the intervention effect in the first (second ... ) intervention phase
integer, either a vector (only for SWD) or a matrix. A vector defines the number of periods before and after the switch from control to intervention that are observed. A matrix consists of 1's for observed clusterperiods and 0's for unobserved clusterperiods.
character, specifies adjustment for time periods. One of the following: "factor", "linear", "none", "periodic". Defaults to "factor".
numeric (scalar)
character, defines the type of design. Options are "SWD", "parallel" and "parallel_baseline", defaults to "SWD".
numeric (scalar), mean under control
numeric (scalar), mean under treatment
logical. Only relevant for non-gaussian outcome. Indicates whether mu0 and mu1 are to be interpreted as marginal prevalence under control and under treatment, respectively, or whether they denote the prevalence conditional on random effects being 0 (It defaults to the latter).
numeric, residual error of cluster means if no N given.
numeric, standard deviation of random intercepts
numeric (scalar or matrix), standard deviation of random slopes. If `eta` is given as scalar, `trtMat` is needed as well.
numeric (scalar), value between 0 and 1. Defaults to NULL. If `tauAR` is not NULL, the random intercept `tau` is AR1-correlated. *Currently not compatible with `rho`!=0 !*
numeric (scalar), correlation of `tau` and `eta`
numeric (scalar), random time effect
numeric (scalar), random subject specific intercept. Leads to a closed cohort setting
numeric vector of length 3, that consists of alpha_0, alpha_1 and alpha_2. This is an alternative way to define the correlation structure, following Li et al. (2018).
numeric, a positive-semidefinite matrix with
(#Clusters
numeric, number of individuals per cluster. Either a scalar, vector of length #Clusters or a matrix of dimension #Clusters x timepoints. Defaults to 'rep(1,sum(Cl))' if not passed.
numeric, a specified target power. If supplied, the minimal `N` is returned.
character, distribution family. One of "gaussian", "binomial". Defaults to "gaussian"
numeric, vector specifying the lower and upper bound for `N`, ignored if `Power` is NULL.
numeric (scalar), significance level, defaults to 0.05
character, one of the following: "none","between-within", "containment", "residual".
logical, should the computation be conducted on an individual level? This leads to longer run time and is mainly for diagnostic purposes.
integer, how much information should the function return?
The return depends on the `verbose` parameter. If `verbose`=0, only the power is returned If `verbose`=1 (the default), a list containing power and the parameters of the specific setting is returned. If requested (by `verbose`=2) this list also contains relevant matrices.
Let
# NOT RUN {
## See also vignette for more examples
##
##
## stepped wedge design with 5 Clusters in 5 sequences,
## residual standard deviation 2,
## cluster effect sd = 0.33, and 10 individuals per cluster.
## Further, let the mean under the null and alternative hypothesis 0 and 1,
## respectively.
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, N=10)
##
##
## ... with auto-regressive cluster effect `tauAR=0.7`.
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, tauAR=0.7, N=10)
##
##
## ... with varying cluster size
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, N=c(12,8,10,9,14))
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33,
N=matrix(c(12,8,10,9,14,
11,8,10,9,13,
11,7,11,8,12,
10,7,10,8,11,
9,7, 9,7,11,
9,6, 8,7,11),5,6))
##
##
## ... with random treatment effect (with standard deviation 0.2),
## which is correlated with the cluster effect with `rho`=0.25.
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, eta=.2, rho=.25, N=10)
##
##
## ... with missing observations (a.k.a. incomplete stepped wedge design)
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, N=10, incomplete=3)
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, N=10,
incomplete=matrix(c(1,1,1,0,0,
1,1,1,1,0,
1,1,1,1,1,
1,1,1,1,1,
0,1,1,1,1,
0,0,1,1,1),5,6))
## -> the same.
##
## ... with two levels of clustering. This arises if the patients are
## observed over the whole study period
## (often referred to as closed cohort design) or if subclusters exist
## (such as wards within clinics). For
mod_aggr <- wlsPower(mu0=0, mu1=1, Cl=rep(1,5),
sigma=2, tau=0.33, psi=.25,
N=10, incomplete=3, verbose=2)
mod_indiv <- wlsPower(mu0=0, mu1=1, Cl=rep(1,5),
sigma=2, tau=0.33, psi=.25,
N=10, incomplete=3, verbose=2, INDIV_LVL=TRUE)
mod_aggr
mod_indiv
## Compare covariance matrices of first cluster
mod_aggr$CovarianceMatrix[1:6,1:6] ; mod_indiv$CovarianceMatrix[1:60,1:60]
##
##
## stepped wedge design with 5 Clusters in 5 sequences, residual sd = 2,
## cluster effect sd = 0.33. How many Individuals are needed to achieve a
## power of 80% ?
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, Power=.8)
##
## ... How many are needed if we have a closed cohort design with a random
## individuum effect of .7?
wlsPower(mu0=0, mu1=1, Cl=rep(1,5), sigma=2, tau=0.33, psi=.7, Power=.8)
##
##
## longitudinal parallel design, with 5 time periods, 3 clusters in treatment
## and control arm each.
wlsPower(mu0=0, mu1=1, Cl=c(3,3), sigma=2, tau=0.33, N=10,
dsntype="parallel", timepoints=5)
##
##
##
## ... with one baseline period and four parallel periods
wlsPower(mu0=0, mu1=1, Cl=c(3,3), sigma=2, tau=0.33, N=10,
dsntype="parallel_baseline", timepoints=c(1,4))
##
##
##
## cross-over design with two timepoints before and two after the switch
wlsPower(mu0=0, mu1=1, Cl=c(3,3), sigma=2, tau=0.33, N=10,
dsntype="crossover", timepoints=c(2,2))
##
##
##
## stepped wedge design with 32 Individuals in 8 sequences, binomial outcome,
## 50% incidence under control, 25% incidence under interventional treatment.
## cluster effect sd = 0.5 (ICC of 1/3 under control),
## every individual is its own cluster.
## ... with incidences defined conditional on cluster effect=0
wlsPower(mu0=0.5, mu1=0.25, Cl=rep(4,8), tau=0.5, N=1,
family="binomial")
##
##
## ... with marginally defined incidences
wlsPower(mu0=0.5, mu1=0.25, Cl=rep(4,8), tau=0.5, N=1,
family="binomial", marginal_mu=TRUE)
# }
Run the code above in your browser using DataLab