I tried to replicate the following simple t-test and this calculates t = -3.5985:
t.test(gktlists ~ small, data=star, var.equal=FALSE)
Here is what I did:
mean_small <- mean(star$gktlists[star$small == 1], na.rm = TRUE)
mean_large <- mean(star$gktlists[star$small == 0], na.rm = TRUE)
print(mean_small - mean_large)
var_small <- var(star$gktlists[star$small == 1], na.rm=TRUE)
var_large <- var(star$gktlists[star$small == 0], na.rm=TRUE)
len_small <- length(star$gktlists[star$small == 1])
len_large <- length(star$gktlists[star$small == 0])
(mean_large - mean_small) / sqrt(var_small / len_small + var_large / len_large)
But I get a different t-statistic, t = -3.746202. Is that only due to rounding errors or is the t.test() doing something different than I expect. What am I doing wrong?
Using
sleep
data, your code works actually fine for me.