Day 2: Why Do We Care? — A First Look at ANOVA

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 note on AI tools: You may use AI assistants (ChatGPT, Claude, etc.) to help debug your R code — that's a realistic professional skill. You may not use AI to generate your interpretations. Every write-up sentence must reflect your own reading of the output. If you use AI for any part of this assignment, note where at the end.

The question

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.

Step 1: Look before you test

attn <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/attention_study.csv")
Before you scroll (self-check, not submitted): On t-test day you wrote 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.
boxplot(reaction_time ~ attention_condition, data = attn, main = "Reaction Time by Attention Task", ylab = "Reaction time (ms)")

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.

Step 2: Run the test

model <- aov(reaction_time ~ attention_condition, data = attn) summary(model)
Same shape, new function. 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.)
Df Sum Sq Mean Sq F value Pr(>F) attention_condition 3 458634 152878 38.02 <2e-16 *** Residuals 116 466453 4021
tapply(attn$reaction_time, attn$attention_condition, mean) tapply(attn$reaction_time, attn$attention_condition, sd)
divided focused selective sustained 683.8700 555.2467 612.8833 713.8467 divided focused selective sustained 77.47734 59.21646 55.34050 59.26788

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.

Step 3: Pull out what matters

Six numbers this time — one more than t-test day:

WhatValueFor now, just know...
F38.02A bigger F means the group averages differ more, relative to how much scores naturally wiggle within each group.
df3, 116Two 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.
Meansfocused 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 groupsHow spread out reaction times are within each task.
eta² (η²)0.496The 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.
So what's the answer? In plain language: reaction time clearly depends on the type of attention task — focused attention was fastest, sustained and divided attention were noticeably slower — the gap is far too large to chalk up to chance, and it's a large effect, not just a statistically detectable one.
Question 1 — 1 point (answer in your answer document): This dataset also recorded each participant's age group. We're deliberately not touching that yet — but before moving on: name one reason age might complicate a comparison like this, even though we're not testing it here. (We'll come back to this exact question in Chapter 18.)

Step 4: Your turn — two more questions

New dataset, same idea: one file, one URL, no downloading.

df <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/anova_preview.csv") head(df)

Question 2: Pen color and exam score — fill in the blanks (2 points)

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.

Part of Question 2 — record in your answer document: Does pen color affect exam score? Prediction first: do you think pen color will affect exam score here, or not — and why?

The code below has two blanks. Fill them in using the pattern from Step 1–2 before you run it:

boxplot(exam_score ~ ____, data = df, main = "Exam Score by Pen Color", ylab = "Exam score") tapply(df$exam_score, df$pen_color, mean) tapply(df$exam_score, df$pen_color, sd) summary(____(exam_score ~ pen_color, data = df))
Rest of Question 2 — record in your answer document: Write your own one-sentence answer, plain language, no stats jargon: does pen color affect exam score here, or not?

Now find eta² yourself: eta² = Sum Sq(pen_color) / [Sum Sq(pen_color) + Sum Sq(Residuals)]. Pull both Sum Sq values from your own summary() output above and compute it.

Question 3: Class meeting time and quiz score — write it yourself (2 points)

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:

  1. Boxplot quiz_score by class_time
  2. Get the mean and SD of quiz_score for each class_time group
  3. Run the ANOVA testing whether class_time predicts quiz_score
  4. Calculate eta², the same way as Question 2
Question 3 — record in your answer document: Write your own one-sentence answer, plain language, no stats jargon: does class time predict quiz score here, or not?

Step 5: Compare all three

Fill in the rows for Question 2 and Question 3 yourself, then look at the pattern:

QuestionFdfpeta²Verdict
Attention task38.023, 116<2e-160.496Clearly significant
Pen colorFill in this row in your answer document
Class timeFill in this row in your answer document
Part of Step 5 — 2 points (record the completed table and this answer): One of these three lands right around the .05 cutoff from t-test day. When you find it: same question as before — what would make you more confident it's real, one way or the other?

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.

Step 6: Where do F and eta² actually come from?

Same spirit as the SE reveal from t-test day — two formulas, using numbers you already have. F compares two kinds of variability:

F = variance between groups / variance within groups = Mean Sq (attention_condition) / Mean Sq (Residuals) = 152878 / 4021 = 38.02

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":

eta² = Sum Sq (attention_condition) / Sum Sq (Total) = 458634 / (458634 + 466453) = 458634 / 925087 = 0.496

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.

What we skipped (on purpose)

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.

Look ahead: what does Chapter 17 already say?

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.

Question 4 — 3 points (answer in your answer document): Chapter 17 has a table of eta² benchmarks. Using it: is eta² = 0.496 from the attention-task study small, medium, or large?

Chapter 17 also names a specific follow-up test for finding out which groups differ once ANOVA tells you some group does. Name that test and the R function that runs it, and explain in one sentence why running it beats just doing a separate t-test on every pair (think back to the six-t-test problem from the top of this activity).