Introduction
ANOVA (Analysis of Variance) tests whether group means are significantly different from each other.
One-Way ANOVA
# Fit model
model <- aov(value ~ group, data = df)
# ANOVA table
anova(model)
# Summary with means
summary(model)
model.tables(model, "means")
Two-Way ANOVA
# Two-way with interaction
model <- aov(value ~ factor1 * factor2, data = df)
# Without interaction
model <- aov(value ~ factor1 + factor2, data = df)
anova(model)
Post-Hoc Tests
# Tukey HSD
TukeyHSD(model)
# Pairwise t-tests
pairwise.t.test(value, group, p.adjust = "bonferroni")
# Other tests
library(agricolae)
HSD.test(model, "group")
Assumptions
# Check normality
shapiro.test(residuals(model))
# Check homogeneity of variance
bartlett.test(value ~ group, data = df)
# Levene's test
library(car)
leveneTest(value ~ group, data = df)
Summary
ANOVA compares multiple group means. Use post-hoc tests to identify which groups differ.