10 points — graded
Same idea as the t-test, ANOVA, and regression previews: a real research question, answered start to finish, before we've covered the machinery formally. This time neither variable is a number at all — both are categories. We'll come back to today's main dataset, formally, in Chapter 21.
Remember Day 1's question — does studying with background chatter hurt recall? Eighty students were asked a related but different question: while studying, did they have background noise playing (music) or study in silence — and afterward, did they report feeling distracted?
Is feeling distracted while studying associated with whether music was playing?
Day 1–3 all had a number to predict — words recalled, reaction time, quiz score. Here, "distracted" is Yes or No, and "noise" is Music or Silence. Two categories, not two numbers. When both your variables are categories like this, you're not comparing means or fitting a line — you're asking whether the categories line up more than chance would produce. That's chi-square.
boxplot() or plot() — both built for a number
on the y-axis. There's no number here. What R object would you build instead to "look" at how two
categorical variables relate? Jot your guess, then check below.
This is a contingency table — counts, not a plot. Read it like a grid: of the 40 students who studied with music, 27 reported feeling distracted; of the 40 who studied in silence, only 7 did. The pattern is already visible in the raw counts — we're about to check whether it's too strong to be chance.
outcome ~ predictor, data
= df. chisq.test() doesn't. That's not an accident: a t-test, ANOVA, and
regression all ask "does this predictor explain that outcome" — one variable plays outcome, the other
plays predictor. Chi-square asks a more symmetric question — "are these two categorical variables
associated at all" — neither one is privileged as the outcome, so there's no formula to write. You hand it
a table instead.
Four numbers this time — chi-square's version of the last three days' five or six:
| What | Value | For now, just know... |
|---|---|---|
| χ² | 18.47 | A bigger χ² means the observed counts stray further from what independence would predict. |
| df | 1 | Comes from the table's shape: (rows − 1) × (columns − 1). A 2×2 table always gives df = 1. |
| p | 1.73e-05 (report as p < .001) | How implausible it'd be to see a split this lopsided if noise and distraction were actually unrelated. |
| Cramér's V | 0.506 | The size of the association — same job as ANOVA day's eta² and regression day's R², different formula. p says "probably real"; V says "how strong." We always report both. |
One more thing sitting in that output: R applied "Yates' continuity correction" automatically, because this is a 2×2 table. It makes χ² a little more conservative (smaller) than the raw formula would give. Chapter 21 explains exactly why — for now, just know it's the default, not something you turned on.
New variables, same dataset, same URL — no re-downloading anything.
Some students swear that wearing a "lucky color" on exam day helps. Every student in df
reported whether they wore red or blue on exam day, and whether they passed.
The code below has two blanks. Fill them in using the pattern from Step 1–2 before you run it:
library(vcd); assocstats(color_table) and report
the value it prints.
The same eighty students reported whether they usually take notes on a laptop or by hand, and whether they scored High or Low on a follow-up recall quiz.
Does note-taking method predict recall level?
No starter code this time. Using the pattern from Questions 1 and 2, write R code to:
notetaking_method by recall_levelassocstats()Fill in the rows for Question 2 and Question 3 yourself, then look at the pattern:
| Question | χ² | df | p | Cramér's V | Verdict |
|---|---|---|---|---|---|
| Noise → distraction | 18.47 | 1 | <.001 | 0.506 | Clearly significant |
| Shirt color → passing | Fill in this row in your answer document | ||||
| Note-taking → recall | Fill in this row in your answer document | ||||
Notice again that p and Cramér's V don't have to agree on how impressive a result looks — that's exactly why we report effect size regardless of whether p is significant.
Same spirit as every previous reveal — one formula, using numbers you already have. Chi-square compares the counts you observed to the counts you'd expect if the two variables were truly independent:
For the noise/distraction table, both row totals are 40 and both column totals are 40, out of N = 80 — which works out to an expected count of 23 or 17 in every cell:
Compare that to what we actually saw — 13/27 and 33/7 — and every cell is off by exactly 10. The formula adds up how far off, cell by cell, relative to what was expected:
That 20.46 is the uncorrected value — the one assocstats() used to build Cramér's
V. Yates' correction (Step 3) shaves 0.5 off each difference before squaring, which is why
chisq.test() reported 18.47 instead:
Same counts, two slightly different numbers depending on which correction you use — which is exactly why Chapter 21 insists you name which one you're citing.
We didn't check the expected-count assumption (every expected count should be at least 5 — ours all were, but we didn't verify it first). We also didn't ask which cells drove the association — a significant χ² says some cell has more or fewer people than expected, not which one — and we didn't touch the goodness-of-fit version of this test at all (one categorical variable against a hypothesized distribution, rather than two variables against each other). All of that is coming in Chapter 21.
You haven't read Chapter 21 yet, but it's already sitting in the book, and it covers two things this activity deliberately skipped: how to judge the size of a Cramér's V value, and how to find out which cells are driving a significant result.
chisq.test(table)$stdres) to find out which cells are driving a significant association.
For the noise/distraction table, every cell had a standardized residual of ±4.52. In one sentence,
what does a residual that large tell you about that particular cell, compared to a small one near 0?