R code Power for unequal groups unpaired t-test
Delta is the ratio of group 2 to group 1, alpha is (two-tailed) type I error, group means, mean1 and mean2, with standard deviations, sd1 and sd2, and n1 is the number in group 1. Power is outputted.
[COPY AND PASTE INTO R]
fn <- function (alpha,delta,mean1,mean2,sd1,sd2,n1) {
mdiff <- mean1 - mean2
sd <- sqrt((n1*sd1*sd1+n1*delta*sd2*sd2)/(n1+delta*n1-2))
pow <- 1 - pt(abs(qt(beta/2, n1+(delta*n1)-2)), n1+(delta*n1)-2,
mdiff/sqrt((sd*sd)/n1+(sd*sd)/(n1*delta)))
cat("Power for (two-tailed) unequal sized groups unpaired t-test =")
print(pow)
}[THEN ENTER INPUTS IN FORM BELOW]
delta <- 2 alpha <- 0.05 mean1 <- 2 mean2 <- 0 sd1 <- 4 sd2 <- 5 n1 <- 45
AND RUN
fn(alpha,delta,mean1,mean2,sd1,sd2,n1)
