Simulations, of course, do not provide a more exact answer than a
formula, when a formula is available. The value of simulations is that
you can stress your assumptions a bit by adding some non-normality,
heterogeneity of variances, and so forth. Under those situations, the
formulas for power may be approximate or may not even exist.
Here's some code in R that shows how to get power when there is a half a
standard deviation shift and the sample size is 64 in each group.
alpha <- 0.05
alt <- "two.sided"
mu1 <- 0
mu2 <- 0.5
sigma1 <- 1
sigma2 <- 1
n1 <- 64
n2 <- 64
nreps <- 1000
pv <- rep(NA,nreps)
for (i in 1:nreps) {
x1 <- rnorm(n1,mu1,sigma1)
x2 <- rnorm(n2,mu2,sigma2)
pv[i] <- t.test(x1,x2,paired=FALSE,alternative=alt)$p.value
}
power <- sum(pv<alpha)/nreps
lower.ci.power <- power-1.96*sqrt(power*(1-power)/nreps)
upper.ci.power <- power+1.96*sqrt(power*(1-power)/nreps)
It's trivial, I'm sure, to do this in SAS also, but I stopped using SAS
ten years ago.
--
Steve Simon, Standard Disclaimer
The Monthly Mean is celebrating its first anniversary.
Find out more about the newsletter that dares
to call itself "average" at www.pmean.com/news