FAQ/power/onesampn - CBU statistics Wiki

Please enter your password of your account at the remote wiki below.
/!\ You should trust both wikis because the password could be read by the particular administrators.

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