I'd like to bootstrap a two sample t-test. My DV is some psychological variable. I have two groups (women and men), unequal sizes and I do not assume equal variances. I'm not sure if my code or/and my thinking is correct, 'cause in the end I got 0 t-statistics greater than t-statistic from original data.
group_k # women: N=377
group_m # men: N=306
t.est <- t.test(group_k, group_m, var.equal=FALSE)$stat
# t
# 5.659757
nullA <- group_k - mean(group_k, na.rm=T)
nullB <- group_m - mean(group_m, na.rm=T)
set.seed(1)
b <- function(){
A <- sample(nullA, 200, replace=T) # is 200-element from 377-element sample ok?
B <- sample(nullB, 200, replace=T)
stud_test <- t.test(A, B, var.equal=FALSE)
stud_test$stat
}
t.stat.vect = vector(length=10000)
t.vect <- replicate(10000, b())
1 - mean(t.est>t.vect)
# [1] 0 :(
I have some additional questions:
- Why not bootstrapping simply differences between women and men?
- How to choose bootstrap sample size? In other words, is 200-elements from 377- and 306-element groups OK? Should they be 377 and 306, respectively, as this post recommends?
The idea behind subtracting means was here - gung's reply. I thought that it can be directly taken from ANOVA case to Student's t test.
[UPDATE 13XII] I corrected my code, but results are still awkward to me:
t.est <- t.test(group_k, group_m, var.equal=FALSE)$stat
# t = 5.6598, df = 255.185, p-value = 4.066e-08
b <- function(){
A <- sample(group_k, 377, replace=T)
B <- sample(group_m, 306, replace=T)
stud_test <- t.test(A, B, var.equal=FALSE)
stud_test$stat
}
t.stat.vect = vector(length=10000)
t.vect <- replicate(10000, b())
1 - mean(t.est>t.vect)
[1] 0.5042
Is it possible that using original samples the difference between means is "so significant" (p-value = 4.066e-08), but the bootstrap samples shows that actually it's not (0.5042) ??
t.vect
) are less thant.est
.mean(c(TRUE, TRUE, TRUE, ..., TRUE))
is 1. So, 1-1 = 0. $\endgroup$