R/pwr.lancova.R

#' Power Calculation for LANCOVA
#'
#' Compute the statistical power of the LANCOVA test.
#'
#' @param k the number of groups.
#' @param n the number of observations per group.
#' @param rho_sqrd the pretest-posttest correlation
#' @param r_sqrd the expected explained variance (on the logged scale)
#' @param alpha the significance level (default=.05)
#' @return \item{power}{the statistical power of test}
#' @examples
#' pwr.lancova(3,40,.1,.4,.05)
#' @export
#' @importFrom stats pf qf
#' @references Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale,NJ: Lawrence Erlbaum.


pwr.lancova<-function(k,n,r_sqrd,rho_sqrd,alpha=.05){
  lambda <- k * n * r_sqrd*(1-r_sqrd)/(1-rho_sqrd)
  power <- pf(qf(alpha, k - 1, (n - 1) * k-1, lower.tail = FALSE),
       k - 1, (n - 1) * k-1, lambda, lower.tail = FALSE)
  list('the number of group' = k,
       'the per-group sample size' = n,
       'pretest-posttest correlation'= rho_sqrd,
       'r squared' = r_sqrd,
       'significance level' = alpha,
       'power' = power)
}
QMmmmLiu/lamme documentation built on May 31, 2019, 5:19 p.m.