10 points — graded
Same idea as the t-test preview: a real research question, answered start to finish, before we've covered the machinery formally. This time the question needs more than two groups at once, which is exactly the problem ANOVA exists to solve. We'll come back to today's main dataset, formally, in Chapter 18.
A researcher wants to know whether the type of attention a task demands affects how fast people react. 120 participants were each randomly assigned to one of four attention tasks — focused, selective, divided, or sustained — and their reaction time was recorded.
Does the type of attention task affect reaction time?
Four groups. Recall the t-test only ever compares two. You could run six separate t-tests (one for every pair of tasks), but every extra test you run raises the odds that one of them looks "significant" just by chance — even if nothing real is going on. ANOVA answers "do any of these groups differ?" in one shot, at one error rate.
boxplot(y ~ x, data = df). Based on that pattern, what do you
think the boxplot call looks like here, using reaction_time and attention_condition?
Jot down your guess, then check it below.
Four boxes this time, not two. Focused sits visibly lowest; sustained and divided sit visibly highest, with selective in between. The plot is already suggesting an order — we're about to check whether the data backs it up.
aov(reaction_time ~ attention_condition, data = attn)
has the identical structure as t.test(words_recalled ~ study_environment, data = df) from Day
1 — outcome on the left of ~, grouping variable on the right, data = pointing at
your data frame. New function, same pattern. You'll see this outcome ~ predictor shape
everywhere in this course, not just here — recognizing it is worth more than memorizing any one function
name. (Also worth noticing: summary() gave you a t-test readout on Day 1 and an ANOVA
table here — same function name, different output, because it behaves according to what kind of object you
hand it. That's a general R habit, not a one-off.)
tapply(X, INDEX, FUN) reads as "apply FUN to X, split into groups by
INDEX." The line above is: the mean of reaction_time, split by
attention_condition. Same three-argument shape both times — only FUN changes.
Six numbers this time — one more than t-test day:
| What | Value | For now, just know... |
|---|---|---|
| F | 38.02 | A bigger F means the group averages differ more, relative to how much scores naturally wiggle within each group. |
| df | 3, 116 | Two numbers this time: 3 comes from the number of groups, 116 from the sample size. We'll unpack exactly how in a few weeks. |
| p | <2e-16 (effectively zero) | Same idea as before: how implausible it'd be to see group averages this different if attention type made no real difference. |
| Means | focused 555, selective 613, divided 684, sustained 714 (ms) | The four group averages — what the plot was showing you visually. |
| SDs | ~55–77 ms across the four groups | How spread out reaction times are within each task. |
| eta² (η²) | 0.496 | The size of the effect — about 50% of the variation in reaction time is explained by attention condition. p tells you "probably real"; η² tells you "how much it matters." We always report both, not just whichever one looks better. |
New dataset, same idea: one file, one URL, no downloading.
Some students swear the color of pen you write with can affect your grade. Sixty students took the same exam — twenty wrote with black pens, twenty with blue, twenty with red.
The code below has two blanks. Fill them in using the pattern from Step 1–2 before you run it:
summary() output above and compute it.
The same sixty students are split across three sections of the same course — morning, afternoon, or evening — and we have each student's score on a 15-point reading quiz.
Does the time of day a class meets predict quiz performance?
No starter code this time. Using the pattern from Questions 1 and 2, write R code to:
quiz_score by class_timequiz_score for each class_time groupclass_time predicts quiz_scoreFill in the rows for Question 2 and Question 3 yourself, then look at the pattern:
| Question | F | df | p | eta² | Verdict |
|---|---|---|---|---|---|
| Attention task | 38.02 | 3, 116 | <2e-16 | 0.496 | Clearly significant |
| Pen color | Fill in this row in your answer document | ||||
| Class time | Fill in this row in your answer document | ||||
Notice too that p and eta² don't have to tell the same story: a tiny effect can still hit significance with enough data, and a real effect can miss it with too little. That's exactly why we report effect size regardless of whether p is significant — "significant" and "big" are two different questions.
Same spirit as the SE reveal from t-test day — two formulas, using numbers you already have. F compares two kinds of variability:
eta² asks a related but different question — not "how big is between compared to within," but "how much of the total variation does the group variable account for":
Same numbers R gave us, just recombined two different ways. If the group averages barely differ more than people within a single group differ from each other, F stays near 1 and eta² stays near 0 — nothing to see. If the groups differ a lot more than that ordinary noise, both climb — and that's exactly what happened here. Everything we cover about variance, spread, and sums of squares in the coming weeks exists to make "a lot more than ordinary noise" precise.
We didn't check any assumptions before running these tests (normal-ish residuals, similar spread across groups). ANOVA also only tells you that the groups differ somewhere, not which pair — that's a post-hoc test, coming later. All of that is coming.
You haven't read Chapter 17 yet, but it's already sitting in the book, and it covers two things this activity deliberately skipped: how to judge the size of an eta² value, and how to find out which groups differ once ANOVA tells you some group does.