Package 'LPower'

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

Help Index


Calculates either the power, sample size, or detectable effect for a longitudinal study with a repeated measures design.

Description

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.

Usage

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))

Arguments

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 rx_effect. The code is betas=rep(rx_effect/(matrix(betas,1,m[2])%*%mcontrast),m[2])*betas

Value

A vector giving the detectable difference, sample size and power.

Note

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)

Author(s)

David A. Schoenfeld

References

Diggle, P., Liang, K.Y. and Zeger, S.L., 1994. Longitudinal data analysis. New York: Oxford University Press, 5, pp 59, ISBN:9780198522843

See Also

randomEffectsMatrix, randomSlopesMatrix

Examples

#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)

Calculates the variance covariance matrix for a multivariate normal vector when there are random effects.

Description

Computes the variance covariance matrix of an mm vector which results from a random effects model.

Usage

randomEffectsMatrix(zMatrix, vs, sigma2)

Arguments

zMatrix

An mXpm X p design matrix which specifies how pp random variables with zero mean are linearly related to the m-dimensional normal vector.

vs

The pXpp X p variance covariance matrix of the random effects,

sigma2

The error variance.

Details

We assume that yt=μt+Σγjzt,j+σ2ϵy_{t}=\mu_t+\Sigma \gamma_j z_{t,j}+\sigma^2 \epsilon, where γj\gamma_j are random variables with mean 00 and and variance covariance vs, and zz is zMatrix, ϵ\epsilon is a standard normal random variable. The zMatrix could be a list of matricies

Value

Either a single variance covariance matrix or a list of them if zMatrix is a list.

Author(s)

David A. Schoenfeld

See Also

LPower,randomSlopesMatrix

Examples

#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 the xMatrix and zMatrix, and attrition rates for a two treatment clinical trial analyzed using the random slopes model.

Description

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.

Usage

randomSlopesMatrix(visit, vs, sigma2, dropPerMonth,baselineTreatment=FALSE)

Arguments

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.

Details

This calculates the matrices for the random slopes model yt=μ+β1t+β2tI(rx=1)+u+bt+σ2ϵy_{t}=\mu+\beta_1 t+ \beta_2 t*I(\rm{rx}=1)+u+b t+\sigma^2 \epsilon, where u,b,ϵu,b,\epsilon 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.

Value

A list of xMatrix,vMatrix,attritionRates for input into LPower

Author(s)

David A. Schoenfeld

References

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.

See Also

LPower

Examples

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)