```
gr <- rep(c('T','C'),64)
y <- ifelse(gr=='C',0,2)
dta <- data.frame(y=y,X=gr)
cutoff <- qt(.025,nrow(dta))
sim1 <- function(){
dta$y <- dta$y+rnorm(length(dta$X),0,4) # generate (with uncertainty)
res <- t.test(data=dta,y~X) # analyze
c(res$estimate %*% c(-1,1),res$statistic,res$p.value) # keep results
}
sims <- replicate(10000,sim1()) # large number of iterations
dimnames(sims)[[1]] <- c('diff','t.stat','p.val')
mean(sims['p.val',] < .05) # p-values
[1] 0.8029
mean(sims['t.stat',] < cutoff) # t-statistics
[1] 0.8029
mean(sims['diff',] > sd(sims['diff',])*cutoff*(-1)) # estimated differences
[1] 0.8024
```