Analysis of Variance (ANOVA) in R

ANOVA is a method used to determine if there are significant differences between the means of three or more groups. In optometry, this helps compare treatment effects like visual acuity or reading speed across different interventions.

Use Cases in Vision Science

Types of ANOVA

Type Use Case R Function
One-Way ANOVA One factor (e.g., Aid Type) aov()
Two-Way ANOVA Two factors (e.g., Aid Type and Lighting) aov(), lm()
Repeated Measures Same subject, different conditions aov() with Error(), ezANOVA()
Mixed Models Fixed + Random effects (e.g., subject ID) lmer() from lme4

Example in R

Compare contrast sensitivity (CS) across three lens brands:

# Simulated Data
lens_data <- data.frame(
  CS = c(1.8, 1.7, 1.9, 2.1, 2.2, 2.3, 1.6, 1.5, 1.7),
  Brand = factor(rep(c("BrandA", "BrandB", "BrandC"), each = 3))
)

# Run ANOVA
model <- aov(CS ~ Brand, data = lens_data)
summary(model)

Post-Hoc Test (Tukey's HSD)

TukeyHSD(model)

Assumption Checks

Visualization

library(ggplot2)
ggplot(lens_data, aes(x = Brand, y = CS)) +
  geom_boxplot() +
  labs(title = "Contrast Sensitivity by Lens Brand")

Homework Assignment

Goal: Test if reading speeds differ between three types of low vision aids.

Download the Data

Click here to download reading_speeds.csv

Tasks:

  1. Run a one-way ANOVA to test for speed differences between aid types.
  2. Check assumptions (normality and variance equality).
  3. If significant, use TukeyHSD to identify differences.
  4. Create a boxplot of reading speed by aid type.
# Load data
data <- read.csv("reading_speeds.csv")

# One-way ANOVA
model <- aov(ReadingSpeed ~ AidType, data = data)
summary(model)

# Post-hoc test
TukeyHSD(model)

# Assumptions
shapiro.test(residuals(model))
bartlett.test(ReadingSpeed ~ AidType, data = data)

# Plot
library(ggplot2)
ggplot(data, aes(x = AidType, y = ReadingSpeed)) +
  geom_boxplot() +
  labs(title = "Reading Speed by Low Vision Aid")

Analyze responsibly. Trust your model, not your gut.