LittleInferenceBook
LittleInferenceBook copied to clipboard
Invalid r code for t groups. Minor correction needed.
Under the heading Mistakenly treating the sleep data as grouped the R code uses the value of x_1 and x_2 - these should be g_1 and g_2 respectively. Thus the code should read:
n1 <- length(g1); n2 <- length(g2)
sp <- sqrt( ((n1 - 1) * sd(g1)^2 + (n2-1) * sd(g2)^2) / (n1 + n2-2))
md <- mean(g2) - mean(g1)
semd <- sp * sqrt(1 / n1 + 1/n2)
rbind(
md + c(-1, 1) * qt(.975, n1 + n2 - 2) * semd,
t.test(g2, g1, paired = FALSE, var.equal = TRUE)$conf,
t.test(g2, g1, paired = TRUE)$conf
)
I noticed this too!