nrep <- 1000 set.seed(123321) dat.l <- list() for(i in 1:nrep) { g1 <- cbind(1, rnorm(100, 0, 1)) g2 <- cbind(2, rnorm(100, 0.5, 1)) dat <- data.frame(rbind(g1, g2)) colnames(dat) <- c("group", "y") dat.l[[i]] <- dat } # The following code will not work because the default t.test function does not have the formula argument. See the help page of t.test. outeq.l <- lapply(dat.l, t.test, formula = y ~ group, var.equal = TRUE) outneq.l <- lapply(dat.l, t.test, formula = y ~ group) # We can trick it by the following code: funttest <- function(data, var.equal = FALSE) t.test(y ~ group, data, var.equal = var.equal) outeq.l <- lapply(dat.l, funttest, var.equal = TRUE) outneq.l <- lapply(dat.l, funttest) cieqs <- sapply(outeq.l, "[[", "conf.int") cineqs <- sapply(outneq.l, "[[", "conf.int") coverageeq <- cieqs[1,] < -0.5 & cieqs[2,] > -0.5 coverageneq <- cineqs[1,] < -0.5 & cineqs[2,] > -0.5 mean(coverageeq) mean(coverageneq) widtheq <- abs(cieqs[2,] - cieqs[1,]) widthneq <- abs(cineqs[2,] - cineqs[1,]) mean(widtheq) sd(widtheq) mean(widthneq) sd(widthneq) diffwidth <- widtheq - widthneq mean(diffwidth) sd(diffwidth)