## Consider these values for EX-EY. for (d in c(0.5,1,1.5)) { ## Consider these sample sizes (for both the X and Y sample). for (n in c(10,20,30)) { ## Consider these values for var(X) and var(Y) (we are assuming ## that the variances are equal here). for (v in c(1,2,3)) { ## Generate 1000 data sets from the appropriate alternative ## distribution. X = array(d + sqrt(v)*rnorm(n*1000), c(1000,n)) Y = array(sqrt(v)*rnorm(n*1000), c(1000,n)) ## Calculate T-statistics for the simulated data sets. MX = apply(X, 1, mean) MY = apply(Y, 1, mean) VX = apply(X, 1, var) VY = apply(Y, 1, var) Sp2 = ((n-1)*VX + (n-1)*VY) / (2*n-2) TS = (MX-MY) / sqrt(2*Sp2/n) ## This is an estimate of the power. pw = mean(TS > qt(0.95, 2*n-2)) ## Print the result. print(c(d, n, v, pw)) } } }