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") print(pow) }
Specify inputs:
alpha <- 0.05 mean <- 1 sd <- 4 n <- 130
and run
fn(alpha,mean,sd,n)