R: Power

From MathWiki

Table of contents

General reference

  • Cohen, J. (1992). A Power Primer, Psychological Bulletin, 1 155--159. [1] (http://resolver.scholarsportal.info.ezproxy.library.yorku.ca/resolve/00332909/v112i0001/155_app&form=pdf&file=file.pdf)

Power graph for one-way Anova

Enlarge
   dex <- expand.grid( within.var = 1, groups = 3, between.var = seq(.2,1,.05), power = c(.7,.8,.85,.9,.95))

   n <- numeric(0)
   for ( i in 1:nrow(dex)) {
       ni <- do.call("power.anova.test", dex[i,])$n
   }

   dex$n <- n
   td( new = T)
   td( col = c('black','blue','red','green'))
   xyplot( n ~ between.var, dex, groups = power, type = 'l',  lwd = 1.5,
       auto.key = list(title= "Power",columns= 2,lines = T, points = F),
       xlab = "Between variance / Within variance",
       ylab = "n within each group",
       panel = function(x,y,...) {
           panel.xyplot(x,y,...)
           panel.abline(v=seq(.2,1,.1),col='grey')
           panel.abline(h=seq(2,40,2),col='grey')
       })



R example for power calculation


      
>       
> grpmeans <- c( 5, 6, 7)
> wvar <- 1
>
> # The argument which is NULL will be calculated:
>
> power.anova.test(
+       groups = length(grpmeans) ,
+       n = NULL ,
+       between.var = var(grpmeans),
+       within.var = wvar,
+       sig.level = .05,
+       power = .9)

     Balanced one-way analysis of variance power calculation 

         groups = 3
              n = 7.431865
    between.var = 1
     within.var = 1
      sig.level = 0.05
          power = 0.9



The following funtions computes the power of a design to test a specified linear hypothesis.

power.glh <- function( means, n , within.var, sig.level = 0.9) {
     
}
 NOTE: n is number in each group 

> 

Power

power.fisher.test(statmod)
                           Power of Fisher's Exact Test for Comparing
                           Proportions

power.anova.test(stats)    Power calculations for balanced one-way analysis of
                           variance tests
power.prop.test(stats)     Power calculations two sample test for proportions
power.t.test(stats)        Power calculations for one and two sample t tests
print.power.htest(stats)   Print method for power calculation object


Additional:

asypow.power(asypow)       Asymptotic Power
pbsize(gap)                Power for population-based association design
pow_int(gsl)               Power functions
bpower(Hmisc)              Power and Sample Size for Two-Sample Binomial Test
ciapower(Hmisc)            Power of Interaction Test for Exponential Survival
cpower(Hmisc)              Power of Cox/log-rank Two-Sample Test
gbayes(Hmisc)              Gaussian Bayesian Posterior and Predictive
                          Distributions
popower(Hmisc)             Power and Sample Size for Ordinal Response
samplesize.bin(Hmisc)      Sample Size for 2-sample Binomial
spower(Hmisc)              Simulate Power of 2-Sample Test for Survival under
                          Complex Conditions
power.bc(qtlDesign)        Power calculations for Backcross
power.f2(qtlDesign)        Power calculations for F2 intercross

See also