33 Case Study: Student Exam Scores
By the end of this chapter you will be able to:
- Demonstrate that ANOVA and regression with a dummy-coded predictor are the same test — same F, same p.
- Run the full normality-check-then-test workflow on a small dataset.
- Explain what fictional data can and cannot teach you.
- Connect one-way ANOVA and the pooled-variance (Student’s) t-test to the general linear model.
The Student Exam Scores dataset is the smallest case study in the course and the one most directly aimed at a single conceptual point: regression with a categorical predictor is the same test as ANOVA. A small fictional intervention study with three groups makes this equivalence concrete.
33.1 The dataset
A fictional study of three teaching interventions:
| Variable | Description | Type |
|---|---|---|
studyhours |
Hours studied per week | Numeric (continuous) |
examscore |
Exam score out of 100 | Numeric (continuous) |
group |
Intervention condition: A, B, or C | Factor (3 levels) |
30 students, 10 per group. The groups represent different study-skill interventions.
The Student Exam Scores dataset is constructed — not collected from real students. This makes it useful for demonstrating statistical equivalence cleanly, without the complications of real data. The “findings” should not be treated as evidence about teaching interventions.
Real educational intervention studies raise additional ethical questions: if one intervention is expected to be more effective, is it fair to withhold it from a control group? How should students be informed they are participating in a study? How should academic performance data be anonymized and protected? These questions matter when you move from this fictional demonstration to actual educational research. Treat the findings here as statistical illustrations, not as evidence about pedagogy.
33.2 Question 1: Are exam scores normal?
data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/exam_scores.csv")
str(data)
hist(data$examscore)
shapiro.test(data$examscore)
boxplot(examscore ~ group, data = data)With only 30 students, the CLT offers less protection, so run the normality check carefully; the histogram is the better diagnostic. Here Shapiro-Wilk gives p = .113.
33.3 Question 2: Does study time predict exam score?
A simple regression.
model_lm <- lm(examscore ~ studyhours, data = data)
summary(model_lm)
library(ggplot2)
ggplot(data, aes(x = studyhours, y = examscore)) +
geom_point() +
geom_smooth(method = "lm")The slope is strong and positive: each extra weekly study hour goes with about 2.3 more points (b = 2.30, p < .001). A clean simple-regression example.
33.4 Question 3: Do intervention groups differ?
A one-way ANOVA.
data$group <- as.factor(data$group)
model_aov <- aov(examscore ~ group, data = data)
summary(model_aov)
TukeyHSD(model_aov)
aggregate(examscore ~ group, data = data, FUN = mean)The groups differ significantly, F(2, 27) = 60.25, p < .001, and Tukey HSD shows every pair differs: C (M = 92.9) > B (M = 83.6) > A (M = 71.9).
33.5 Question 4: The same analysis as a regression
Here’s the conceptual punchline. The one-way ANOVA in Question 3 is mathematically identical to a regression with group as a categorical predictor.
# Regression on the categorical predictor
model_reg <- lm(examscore ~ group, data = data)
summary(model_reg)
anova(model_reg)Compare to the ANOVA output. The F-test, the df, the p-value, the residual SE — all identical. The regression summary() adds something the ANOVA doesn’t: it shows each group’s contrast against the reference group (group A) as a t-test with a coefficient and an SE.
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 71.900 1.356 53.037 < 2e-16 ***
groupB 11.700 1.917 6.103 1.61e-06 ***
groupC 21.000 1.917 10.954 1.94e-11 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.287 on 27 degrees of freedom
Multiple R-squared: 0.817, Adjusted R-squared: 0.8034
F-statistic: 60.25 on 2 and 27 DF, p-value: 1.108e-10
Reading this:
- Intercept = group A mean (71.9).
groupB= group B vs. A difference (B is 11.7 points higher).groupC= group C vs. A difference (C is 21.0 points higher).
This is the dummy-coding logic from Chapter 23 made concrete.
33.6 Question 5: Predictors together
What if you include both studyhours and group in a multiple regression?
model_both <- lm(examscore ~ studyhours + group, data = data)
summary(model_both)Here studyhours stays strongly significant (b = 2.29, p < .001), but the group differences shrink: B’s advantage over A falls from 11.7 to 2.8 points (p = .010), and C’s falls from 21.0 to 0.4 points (p = .820). Group C students studied about 19 hours a week, against about 10 in group A, so most of C’s higher scores went with studying more. Only B keeps a small advantage once study time is held constant.
This is the kind of finding that only a multi-predictor regression can show — neither the ANOVA nor the simple regression alone tells this story.
33.7 Question 6: What if you check normality of residuals?
shapiro.test(residuals(model_both))
par(mfrow = c(2, 2)); plot(model_both); par(mfrow = c(1, 1))Here the residuals look fine: Shapiro-Wilk p = .311, and the four panels show no clear pattern.
33.8 Bringing it back to the linear model
Once a student works through this case study, the conceptual claim from Chapter 23 stops being abstract:
- Student’s (pooled-variance) t-test → regression with one dichotomous predictor
- One-way ANOVA → regression with one categorical predictor (3+ levels)
- Two-way ANOVA → regression with two categorical predictors
These ordinary group-comparison tests are special cases of lm(). Welch’s t-test, repeated-measures designs, and chi-square tests need different variance assumptions or model structures. The “many tests” view of statistics is a teaching scaffold; the linear model is what’s actually doing the work underneath.
- EDA and normality check.
- Simple regression of
examscore ~ studyhours. - ANOVA of
examscore ~ group. - Run the same as
lm(examscore ~ group)and compare. Verify that the F-tests match. - Multiple regression of
examscore ~ studyhours + group. Note how the group differences change. - Write up the multiple-regression result.
This concludes Part VII. The appendices that follow contain an example final project, quick-reference cards, a catalog of the interactive modules, an R workflow reference, a power-analysis guide, and a glossary.
Core idea: ANOVA and regression with a dummy-coded predictor are the same test — same F, same p. This small fictional dataset exists to let you verify that equivalence with your own hands, and to connect ordinary ANOVA and Student’s t-test to the linear model.
You should understand:
- Why
aov(examscore ~ group)andlm(examscore ~ group)give matching F-tests - How the dummy-coded coefficients map onto group mean differences
- What fictional data can demonstrate (statistical structure) and cannot (anything about real teaching interventions)
You should be able to do in R:
- Run the same comparison as ANOVA and as regression, and confirm the F statistics match
- Add a continuous predictor alongside the categorical one and interpret the change
- Check normality of residuals rather than raw scores
Plain-language check: A classmate asks why the regression output shows two coefficients for a three-group predictor. What happened to the third group?
The one mistake to avoid: Citing this dataset’s “findings” as evidence about study interventions. It is constructed data; the lesson is the method, not the result.
Practice: Change the reference level of group with relevel() and re-run the regression. Which numbers change, and which stay the same? Why?
Key terms from this chapter are defined in the Glossary.