n2.power <- function(J, K, prop=1.0, n.sims, effect.size , mu.a.true, sigma.item.true, sigma.id.true, sigma.y.true ){ signif.f <- rep(NA, n.sims) signif.x1 <- rep(NA, n.sims) signif.x2 <- rep(NA, n.sims) signif.x3 <- rep(NA, n.sims) N <- J*K for (s in 1:n.sims){ x1.true <- effect.size x2.true <- effect.size x3.true <- effect.size f.true <- effect.size # simulate fixation times fake <- ffd.fake(J,K,mu.a.true, x1.true, x2.true, x3.true, f.true, sigma.item.true, sigma.id.true, sigma.y.true) fake$ix <- 1:N fake <- fake[sample(fake$ix, prop*N), ] lme.power <- lmer(y ~ f + x1 + x2 + x3 + (1|id) + (1|item), data=fake) theta.f.hat <- fixef(lme.power)["f"] theta.f.se <- sqrt(vcov(lme.power)[2,2])#["f","f"]) signif.f[s] <- (theta.f.hat - 2*theta.f.se) > 0 # returns TRUE or FALSE theta.x1.hat <- fixef(lme.power)["x1"] theta.x1.se <- sqrt(vcov(lme.power)[3,3])#["x1","x1"]) signif.x1[s] <- (theta.x1.hat - 2*theta.x1.se) > 0 # returns TRUE or FALSE theta.x2.hat <- fixef(lme.power)["x2"] theta.x2.se <- sqrt(vcov(lme.power)[4,4])#["x2","x2"]) signif.x2[s] <- (theta.x2.hat - 2*theta.x2.se) > 0 # returns TRUE or FALSE theta.x3.hat <- fixef(lme.power)["x3"] theta.x3.se <- sqrt(vcov(lme.power)[5,5])#["x3","x3"]) signif.x3[s] <- (theta.x3.hat - 2*theta.x3.se) > 0 # returns TRUE or FALSE } signif<-cbind(signif.f, signif.x1, signif.x2, signif.x3) }