FAQ/power/onesampn - CBU statistics Wiki

Revision 1 as of 2008-02-29 12:16:13

Clear message
location: FAQ / power / onesampn

= One sample t-test in R=

For a (two-tailed) type I error, alpha, testing a sample of size n with mean and sd we can obtain the power as below in R.

Copy and Paste the below into R.

fn <- function (alpha,mean,sd,n) {
pow <- 1 - pt(abs(qt(alpha/2, n-1)), n-1, (mean/sd)*sqrt(n))
cat("Power of (two-sided) equal groups unpaired t-test is")
print(pow)
 }

Specify inputs:

alpha <- 0.05
mean <- 1
sd <- 4
n <- 130

and run

fn(alpha,mean,sd,n)