Multi-group Comparisons

Anova

n <- 1000

set.seed(123)

x <- rnorm(n, 1)
y <- rnorm(n, 1.2)
z <- rnorm(n, 1.1)

dat <- data.frame(outcome = c(x,y,z),
                  group = rep(c("X","Y","Z"), each = n))

fit <- aov(outcome ~ group, data = dat)

summary(fit)
##               Df Sum Sq Mean Sq F value   Pr(>F)    
## group          2   27.2  13.621    13.8 1.08e-06 ***
## Residuals   2997 2957.1   0.987                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

PostHoc Test

TukeyHSD(fit, ordered = TRUE)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
##     factor levels have been ordered
## 
## Fit: aov(formula = outcome ~ group, data = dat)
## 
## $group
##           diff         lwr       upr     p adj
## Z-X 0.06375961 -0.04040611 0.1679253 0.3228639
## Y-X 0.22633739  0.12217168 0.3305031 0.0000011
## Y-Z 0.16257778  0.05841207 0.2667435 0.0007505