Confidence interval to check for difference: Use 1.96 SE and not 1.96 SD !

Let create two variables of length 100, one with mean 10 (A) and one with mean 12 (B) both with SD=2. Of course the two variables overlap.

A <- rnorm(100, 10, 2)

B <- rnorm(100, 12, 2)

library(HelpersMG)

barplot_errbar(c(mean(A) ,mean(B)), errbar.y = c(1.96*sd(A), 1.96*sd(B)), las=1, ylim=c(0, 20), main="1.96 x SD")

Now do a t test. It is highly significant:

t.test(A, B)


Welch Two Sample t-test


data:  A and B

t = -7.8344, df = 197.93, p-value = 2.82e-13

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

 -2.737632 -1.636588

sample estimates:

mean of x mean of y 

 9.741912 11.929021 

Then if you want use the overall of confidence interval, use SE:

barplot_errbar(c(mean(A) ,mean(B)), errbar.y = c(1.96*sd(A)/sqrt(length(A)),  1.96*sd(B)/sqrt(length(A))), las=1, ylim=c(0, 12), main="1.96 x SE")

Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04