FAQ/power/onesampn - CBU statistics Wiki
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. These results agree with this on-line calculator.

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

Specify inputs:

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

and run


None: FAQ/power/onesampn (last edited 2013-03-08 10:17:23 by localhost)