FAQ/power/onesampn - CBU statistics Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
In thi sntence, what word is mad fro the mising letters?

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)