Title: | Calculates Power, Sample Size, or Detectable Effect for Longitudinal Analyses |
---|---|
Description: | Computes power, or sample size or the detectable difference for a repeated measures model with attrition. It requires the variance covariance matrix of the observations but can compute this matrix for several common random effects models. See Diggle, P, Liang, KY and Zeger, SL (1994, ISBN:9780198522843). |
Authors: | David A. Schoenfeld |
Maintainer: | David A. Schoenfeld <[email protected]> |
License: | Unlimited |
Version: | 0.1.1 |
Built: | 2024-10-31 22:25:11 UTC |
Source: | CRAN |
Provide two of three parameters (power, sample size, detectable effect) and it supplies the third in a design with repeated measures. It requires the design matrix, and the variance covariance matrix of the repeated measures. It can also take into account of attrition at each of the time points in the model.
LPower(rx_effect = NULL, sample_size = NULL, allocationRatio = c(1, 1), power = NULL, contrast=c(rep(0,dim(xMatrix[[1]])[2]-1),1), xMatrix, vMatrix, attritionRates = 0, alpha = 0.025, simulate=FALSE,nsims=1000,betas=c(rep(0,dim(xMatrix[[1]])[2]-1),1))
LPower(rx_effect = NULL, sample_size = NULL, allocationRatio = c(1, 1), power = NULL, contrast=c(rep(0,dim(xMatrix[[1]])[2]-1),1), xMatrix, vMatrix, attritionRates = 0, alpha = 0.025, simulate=FALSE,nsims=1000,betas=c(rep(0,dim(xMatrix[[1]])[2]-1),1))
rx_effect |
The size of the effect to be detected. Set to Null if this is the parameter to be calculated. |
sample_size |
The total sample size of the study. |
allocationRatio |
The allocation ratio, the allocation to each arm in the study or to each group of patients that have a distinct design matrix. |
power |
The desired power. Null if the power is to be computed. |
contrast |
The contrast to be estimated, the default value, which is valid if the xMatrix paramter is a list is c(0,...1). That is the last parameter is the effect of interest. |
xMatrix |
A list of matricies giving the regression coefficients for each patient group, note that the all must have the same dimensions. |
vMatrix |
A list of variance covariance matricies for each patient group. A single matrix also will work if all patients groups have the same variance covariance matrix. All must have the same dimensions. |
attritionRates |
A vector which is the rate of attrition between each visit. Attrition is considered to be exponential between visits. |
alpha |
The significance level |
simulate |
Logical, indicating that you also want to run a simulation to calculate the power given the calculated sample size or detectable difference. |
nsims |
Number of simulations to use |
betas |
Coefficient value for simulations. Note that betas is rescaled so that the value of the contrast is |
A vector giving the detectable difference, sample size and power.
The code to analyse the model used in the simulation is something like
mod2 = nlme::gls(y~X1+X2+X3, correlation = corSymm(form = ~visits|subject),
weights = varIdent(form =~1|visits), na.action = na.omit, data = df)
with test statistic.
sum(contrast * mod2$coefficients)/sqrt(t(mcontrast)
mod2$varBeta %*% mcontrast)
David A. Schoenfeld
Diggle, P., Liang, K.Y. and Zeger, S.L., 1994. Longitudinal data analysis. New York: Oxford University Press, 5, pp 59, ISBN:9780198522843
randomEffectsMatrix
, randomSlopesMatrix
#This would be what would be used for an analysis of covariance assuming #a correlation of 0.3 and a standard deviation of 5.46. LPower(sample_size=60,power=.8, xMatrix=list(matrix(c(1,1,0,1,0,0),2,3),matrix(c(1,1,0,1,0,1),2,3)), vMatrix=5.46^2*matrix(c(1,0.3,0.3,1),2,2),attritionRates=0.1)
#This would be what would be used for an analysis of covariance assuming #a correlation of 0.3 and a standard deviation of 5.46. LPower(sample_size=60,power=.8, xMatrix=list(matrix(c(1,1,0,1,0,0),2,3),matrix(c(1,1,0,1,0,1),2,3)), vMatrix=5.46^2*matrix(c(1,0.3,0.3,1),2,2),attritionRates=0.1)
Computes the variance covariance matrix of an vector which results from a random effects model.
randomEffectsMatrix(zMatrix, vs, sigma2)
randomEffectsMatrix(zMatrix, vs, sigma2)
zMatrix |
An |
vs |
The |
sigma2 |
The error variance. |
We assume that ,
where
are random variables with mean
and and variance covariance
vs
, and is
zMatrix
, is a standard normal random variable.
The
zMatrix
could be a list of matricies
Either a single variance covariance matrix or a list of them if zMatrix is a list.
David A. Schoenfeld
#Creates random variance covariance matrix for random follow up model #where baseline is random among patients and all follow up have a compound symetry structure #from a common random effect vars=randomEffectsMatrix(cbind(rep(1,5),matrix(c(0,rep(1,4)),5,1)), matrix(c(31.8,.8527,.8527,.6687),2,2),2.7085) LPower(sample_size=40,power=.8, xMatrix=list(cbind(1,c(0,rep(1,4)),0),cbind(1,c(0,rep(1,4)),c(0,rep(1,4)))),vMatrix=vars) #Creates random variance covariance matrix for random slopes model vars=randomEffectsMatrix(cbind(rep(1,5),0:4), matrix(c(31.8,.8527,.8527,.6687),2,2),2.7085) LPower(sample_size=40,power=.8, xMatrix=list(cbind(1,0:4,0),cbind(1,0:4,0:4)),vMatrix=vars)
#Creates random variance covariance matrix for random follow up model #where baseline is random among patients and all follow up have a compound symetry structure #from a common random effect vars=randomEffectsMatrix(cbind(rep(1,5),matrix(c(0,rep(1,4)),5,1)), matrix(c(31.8,.8527,.8527,.6687),2,2),2.7085) LPower(sample_size=40,power=.8, xMatrix=list(cbind(1,c(0,rep(1,4)),0),cbind(1,c(0,rep(1,4)),c(0,rep(1,4)))),vMatrix=vars) #Creates random variance covariance matrix for random slopes model vars=randomEffectsMatrix(cbind(rep(1,5),0:4), matrix(c(31.8,.8527,.8527,.6687),2,2),2.7085) LPower(sample_size=40,power=.8, xMatrix=list(cbind(1,0:4,0),cbind(1,0:4,0:4)),vMatrix=vars)
In the random slopes model each patient has a linear trajectory over time with a random intercept and slope. The intercepts are assumed to be the same for each of two treatment groups and the treatment effect is measured by the difference in average slopes.
randomSlopesMatrix(visit, vs, sigma2, dropPerMonth,baselineTreatment=FALSE)
randomSlopesMatrix(visit, vs, sigma2, dropPerMonth,baselineTreatment=FALSE)
visit |
A vector of visit times or a list of two visit time vectors if the treatments have different visit times. |
vs |
The variance covariance matrix of the intercept and slope random effects. |
sigma2 |
The error variance. |
dropPerMonth |
Either a single number which is the attrition rate or a vector of attrition rates for each visit. Note this would have length one less than the number of visits since the attrition after the last visit would not be used. |
baselineTreatment |
A logical indicating whether their treatment is in the model as a main effect. In a random slopes model the effect or treatment is measured by the treatment-time interaction. |
This calculates the matrices for the random slopes model
,
where
are random variables. Note that a treatment main effect is not included in the model by default, because in a randomized study the treatments should be the same at the baseline visit. This practice may vary.
A list of xMatrix,vMatrix,attritionRates
for input into LPower
David A. Schoenfeld
Q Yi and T. Panzarella. Estimating sample size for tests on trends across repeated measurements with missing data based on the interaction term in a mixed model. Control Clin Trials, 23(5):481–96, 2002.
vars=randomSlopesMatrix(list(c(0,1,2,4,6),c(0,1,2,4,6)), matrix(c(31.8,.8527,.8527,.6687),2,2),2.7085,.02) LPower(sample_size=40,power=.8,xMatrix=vars$xMatrix, vMatrix=vars$vMatrix,attritionRates=vars$attritionRates)
vars=randomSlopesMatrix(list(c(0,1,2,4,6),c(0,1,2,4,6)), matrix(c(31.8,.8527,.8527,.6687),2,2),2.7085,.02) LPower(sample_size=40,power=.8,xMatrix=vars$xMatrix, vMatrix=vars$vMatrix,attritionRates=vars$attritionRates)