[R] Formula of power.t.test

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu May 13 08:52:41 CEST 2004


Xiaorong Chen wrote:

> Dear Sir or Madam,
> 
> What is the formula for power.t.test(delta=delta, sd=segma, sig.level=0.05, 
> power=0.8, type="one.sample", alternative="one.sided")$n?

See the code of power.t.test by just typing the name of that function 
into the console:

   power.t.test

and you'll easily see that the code collapses in your case to:

   tsample <- 1
   tside <- 1
   p.body <- quote({
     nu <- (n - 1) * tsample
     pt(qt(sig.level/tside, nu, lower = FALSE),
       nu, ncp = sqrt(n/tsample) * delta/sd, lower = FALSE)
   })
   n <- uniroot(function(n) eval(p.body) - power, c(2, 1e+07))$root


Uwe Ligges


> Thank you very much for the help!
> 
> Best,
> 
> Xiaorong
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list