I have a data, including two groups. I need to calculate the difference of these two groups, then calculate the confident level of 0.9. Also, I need to identify if these two groups are significantly different using ANOVA. However, I find something weird when calculating confident level. Here is my data
Sample <- data.frame(a=runif(100,0,1000),b=runif(100,0,1000))
The real data is too many, so I generate some random data.
First of all, I use the definition of confident level to calculate:
Diff <- (Sample$b-Sample$a) Sd <- sd(Diff) Mean <- mean(Diff) Me <- qnorm(.9)*Sd/sqrt(length(Diff)) Lower <- Mean-Me Upper <- Mean+Me
The result is:
> Lower  -61.48252 > Upper  54.21919
Second of all, I use aov to do ANOVA analysis, then TukeyHSD is used to show the confident level:
Sample1 <- Sample %>% gather(Group,Score) Aov <- aov(Score~Group,Sample1) TukeyHSD(Aov,conf.level = .9) > TukeyHSD(Aov,conf.level = .9) Tukey multiple comparisons of means 90% family-wise confidence level Fit: aov(formula = Score ~ Group, data = Sample1) $Group diff lwr upr p adj b-a -3.631661 -76.10958 68.84626 0.9340892
Third of all, I use t.test to calculate the confident level of the difference of two groups:
> t.test(Diff,conf.level = .9) One Sample t-test data: Diff t = -0.080451, df = 99, p-value = 0.936 alternative hypothesis: true mean is not equal to 0 90 percent confidence interval: -78.58381 71.32049 sample estimates: mean of x -3.631661
Because of randomly generating data, you probably have the different sample. But anyway, the confident level from three methods are different. S, am I doing wrong? And what is the right way?