#http://cran.r-project.org/ AND DOWNLOAD THE R LATEST RELEASE: R-2.x.y.

#COPY AND PASTE INTO R AND, AMEND INPUTS AS DESIRED] 


delta <- 1
pow <- 0.9
alpha <- 0.05
mdiff <- 3
sd <- 4
#
#[THEN COPY AND PASTE THE BELOW INTO R] 
#[SAMPLE SIZE FOR GIVEN POWER]


fn <- function(n1) {
(pow - (1 - pt(abs(qt(alpha/2,n1+(delta*n1)-2)), n1+(delta*n1)-2,
mdiff/sqrt((sd*sd)/n1+(sd*sd)/(n1*delta)))) )^2
 }

nout<- nlm(fn,2)
nout<- trunc(nout$estimate+1)
cat("Sample size per group for (two-tailed) unpaired t-test")
print(nout)


#[COPY AND PASTE INTO R]
#[POWER FOR A GIVEN SET OF CRITERIA] 


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(alpha/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 <- 1
alpha <- 0.05
mean1 <- 3
mean2 <- 0
sd1 <- 4
sd2 <- 4
n1 <- 38
#
#AND RUN 
#
fn(alpha,delta,mean1,mean2,sd1,sd2,n1)
