Version: | 1.0 |
Type: | Package |
Title: | Sampling Data Within Different Study Designs for Cluster Randomized Trials |
Date: | 2017-01-20 |
Author: | Diana Trutschel, Hendrik Treutler |
Maintainer: | Diana Trutschel <Diana.Trutschel@dzne.de> |
Description: | Package provides the possibility to sampling complete datasets from a normal distribution to simulate cluster randomized trails for different study designs. |
License: | GPL-3 |
RoxygenNote: | 5.0.1 |
Imports: | mvtnorm, stats |
Suggests: | knitr, rmarkdown, lme4 |
VignetteBuilder: | knitr |
Packaged: | 2017-02-06 12:28:06 UTC; trutscheld |
NeedsCompilation: | no |
Repository: | CRAN |
Date/Publication: | 2017-02-06 14:28:31 |
covariance matrix for the multivariate normal distributed variables
Description
covariance matrix of the normal distribution under cluster randomized study type given a design and a type
Usage
CovMat.Design(K, J, I, sigma.1.q, sigma.2.q = NULL, sigma.3.q)
Arguments
K |
number of timepoints or measurments (design parameter) |
J |
number of subjects |
I |
number of clusters (design parameter) |
sigma.1.q |
variance of the lowest level (error variance or within subject variance) |
sigma.2.q |
secound level variance (e.g. within cluster and between subject variance), by default NULL and then a cross-sectional type |
sigma.3.q |
third level variance (e.g. between cluster variance) |
Value
V covariance matrix
Examples
K<-6 #measurement (or timepoints)
I<-10 #Cluster
J<-2 #number of subjects
sigma.1<-0.1
sigma.3<-0.9
CovMat.Design(K, J, I,sigma.1.q=sigma.1, sigma.3.q=sigma.3)
sigma.1<-0.1
sigma.2<-0.4
sigma.3<-0.9
CovMat.Design(K, J, I,sigma.1.q=sigma.1, sigma.2.q=sigma.2, sigma.3.q=sigma.3)
diagonal block matrix
Description
create a diagonal block matrix
Usage
blockMatrixDiagonal(...)
Arguments
... |
a list of matrices |
Value
diagonal block matrix concatinated from this list of matrices
Examples
m1<-matrix(round(runif(4*4),1),nrow=4,ncol=4)
m2<-matrix(round(runif(4*4),1),nrow=4,ncol=4)
blockMatrixDiagonal(m1,m2,m2,m1)
sigma.1<-0.1
sigma.2<-0.4
J<-10 #subjects
I<-3 #cluster
V.i<-sigma.2*matrix(1,nrow=J,ncol=J)+sigma.1*diag(1, nrow=J,ncol=J) #Covarianmatrix of one cluster
x<-lapply(1:I, function(X) V.i)
blockMatrixDiagonal(x) #Covarianmatrix of all cluster
Power calculation within stepped wedge design model by Hussey et.al or Heo&Kim
Description
Calculation of power for a lmm with cluster as random effect, fixed timepoint effects, but set to null, TP number of timepoints, I number of cluster. The design matrix has to be coded by zeros and ones.
Usage
calcPower.SWD(ThetaEst, alpha = 0.05, Design, sigmaq, tauq,
sigmaq.error = NULL, noSub = NULL, time = TRUE,
type = "cross-sectional")
Arguments
ThetaEst |
expected treatment effect |
alpha |
singificance level (by default 0.05) |
Design |
design matrix for a given SWD model |
sigmaq |
within cluster variance(between subject variance) |
tauq |
between cluster variance |
sigmaq.error |
within subject variance/error variance |
noSub |
number of subjects within each cluster and each timepoint (for all an equal size) |
time |
a logical (FALSE, if no time trends are expected, otherwise TRUE) is only relevant for evaluation of cross-sectional data |
type |
is of cross-sectional (by default) or longitudinal assigns the type of data (2 or 3 level nested structure) |
Value
Aproximated power of two tailed test, although the design matrix is fractionated, then power is not valid formula used for cross-sectional data provided by Michael A. Hussey and James P. Hughes, Design and analysis of stepped wedge cluster randomized trials, Contemporary Clinical Trials(28),2007, and for longitudinal data by Heo M., Kim N., Rinke ML., Wylie-Rosett J., Sample size determinations for stepped-wedge clinical trials from a three-level data hierarchy perspective, Stat Methods Med Res., 2016
Examples
noCl<-10
noT<-6
switches<-2
DM<-designMatrix(noCl,noT,switches)
sigma.e <- 2
sigma.alpha <- 2
#Power for cross-sectional SWD design by formula of Hussey&Hughes
calcPower.SWD(ThetaEst=1,Design=DM, sigmaq=sigma.e^2, tauq=sigma.alpha^2, time=FALSE)
calcPower.SWD(ThetaEst=1,Design=DM, sigmaq=sigma.e^2, tauq=sigma.alpha^2, time=TRUE)
#Power for longitudinal SWD design by formula of Heo&Kim
DM.new<-NULL
for(i in 1:dim(DM)[2]){
DM.new<-cbind(DM.new,DM[,i], DM[,i])
}
s.e <- sqrt(7/10)
s <- sqrt(2/10)
s.a <- sqrt(1/10 )
K<- 10 #number of participants within each 'cell'
calcPower.SWD(ThetaEst=1, Design=DM.new, s.a^2, s^2, s.e^2, noSub=K, type="longitudinal")
Design matrix for complete data within design
Description
create design matrix for complete data within design
Usage
completeDataDesignMatrix(J, X)
Arguments
J |
number of subjects |
X |
given design matrix |
Value
design matrix for complete data within design
Examples
K<-6 #measurement (or timepoints)
I<-10 #Cluster
J<-2 #number of subjects
X<-designMatrix(nC=I, nT=K, nSw=2)
completeDataDesignMatrix(J, X)
Design matrix for SWD model
Description
create design matrix for a given setup of a stepped wedge design
Usage
designMatrix(nC, nT, nSw, swP = NULL, design = "SWD")
Arguments
nC |
number of cluster |
nT |
number of timepoints |
nSw |
number of cluster : within parallel recieve the control (nC-nSw receive the intervention), within cross-over recieve the pattern (0, 1) (nC-nSw receive the pattern (1,0)) for nearly the same number of time points, within SWD switches from control to intervention per time point |
swP |
is the time point the cluster cross over the condition in a cross over study, if not given then it is nearly half of the time past |
design |
is the study type (parallel, cross-sectional, stepped wedge) |
Value
design matrix for a given setup of a stepped wedge design
Examples
designMatrix(5,6,1)
K<-6 #measurement (or timepoints)
I<-10 #Cluster
designMatrix(nC=I, nT=K, nSw=2)
Design matrix for SWD model under a grade of intervention implementation pattern
Description
Creates a implementation matrix for a given stepped wedge design and grade of intervention implementation pattern
Usage
implemMatrix.SWD(nC, nT, nSw, pattern)
Arguments
nC |
Number of clusters |
nT |
Number of timepoint |
nSw |
number of clusters switches from control to treatment at each timepoint |
pattern |
a vector for grade of intervention implementation pattern, which gives the derivation from 100 percent effectiveness over time |
Value
Design matrix for SWD model under a grade of intervention implementation pattern
Examples
implemMatrix.SWD(5,6,1, c(seq(0.4,1,0.2),1))
K<-6 #measurement (or timepoints)
I<-10 #Cluster
implemMatrix.SWD(nC=I, nT=K, nSw=2, pattern=c(seq(0.4,1,0.2),1))
Sampling Response of individuals within a SWD model
Description
Sample data (response) for given numbers of individuals by given a model (of a parallel, cross-sectional, stepped wedge design study)
Usage
sampleData(type, K, J, I, D, A = NULL, V, parameters)
Arguments
type |
of the design is either cross-sectional (cross-sec) or longitudinal (longitudinal) |
K |
number of timepoints or measurments (design parameter) |
J |
number of subjects |
I |
number of clusters (design parameter) |
D |
a complete data design matrix corresponding to the assumed model |
A |
a complete data design matrix corresponding to the true data, if A is null, then A is equal to D |
V |
covariance matrix for the normal distribution |
parameters |
corresponding to the model (regression fixed effects coefficients) |
Value
Data of individuals intensities corresponds to the SWD model and full model parameter information
Examples
K<-6 #measurement (or timepoints)
I<-10 #Cluster
J<-2 #number of subjects
X<-designMatrix(nC=I, nT=K, nSw=2)
D<-completeDataDesignMatrix(J, X)
sigma.1<-0.1
sigma.3<-0.9
type<-"cross-sec"
V<-CovMat.Design(K, J, I, sigma.1=sigma.1, sigma.3=sigma.3)
mu.0<-0
theta<-1
betas<-rep(0, K-1)
parameters<-c(mu.0, betas, theta)
sample.data<-sampleData(type = type, K=K,J=J,I=I, D=D, V=V, parameters=parameters)
xtabs(~cluster+measurement, data=sample.data)