Day 4: Why Do We Care? — A First Look at Chi-Square

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.

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

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.

Step 1: Look before you test

df <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/chisquare_preview.csv") head(df)
Before you scroll (self-check, not submitted): On Days 1–3 you looked with 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.
table(df$background_noise, df$distracted)
No Yes Music 13 27 Silence 33 7

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.

Step 2: Run the test

noise_table <- table(df$background_noise, df$distracted) chisq.test(noise_table)
Notice what's missing. Every test the last three days used 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.
Pearson's Chi-squared test with Yates' continuity correction data: noise_table X-squared = 18.465, df = 1, p-value = 1.73e-05
library(vcd) assocstats(noise_table)
Cramer's V : 0.506

Step 3: Pull out what matters

Four numbers this time — chi-square's version of the last three days' five or six:

WhatValueFor now, just know...
χ²18.47A bigger χ² means the observed counts stray further from what independence would predict.
df1Comes from the table's shape: (rows − 1) × (columns − 1). A 2×2 table always gives df = 1.
p1.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 V0.506The 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.

So what's the answer? In plain language: students who studied with music playing were much more likely to report feeling distracted than students who studied in silence, and that pattern is far too strong to be a coincidence — and it's a strong association, not just a statistically detectable one.
Question 1 — 1 point (answer in your answer document): A chi-square test tells you the two variables aren't independent — it doesn't tell you music causes distraction. Name one other explanation for why "studies with music" and "reports distraction" might travel together, besides music causing it.

Step 4: Your turn — two more questions

New variables, same dataset, same URL — no re-downloading anything.

Question 2: Exam-day shirt color and passing — fill in the blanks (2 points)

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.

Part of Question 2 — record in your answer document: Does shirt color predict passing? Prediction first: do you think shirt color will predict passing 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:

color_table <- table(df$exam_day_color, df$____) color_table chisq.test(____)
Rest of Question 2 — record in your answer document: Write your own one-sentence answer, plain language, no stats jargon: does shirt color predict passing here, or not?

Now find Cramér's V yourself: run library(vcd); assocstats(color_table) and report the value it prints.

Question 3: Note-taking method and recall — write it yourself (2 points)

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:

  1. Build a contingency table of notetaking_method by recall_level
  2. Run the chi-square test on that table
  3. Get Cramér's V with assocstats()
Question 3 — record in your answer document: Write your own one-sentence answer, plain language, no stats jargon: does note-taking method predict recall level here, or not?

Step 5: Compare all three

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

Questionχ²dfpCramér's VVerdict
Noise → distraction18.471<.0010.506Clearly significant
Shirt color → passingFill in this row in your answer document
Note-taking → recallFill 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, same as one did on every previous day. When you find it: same question as before — what would make you more confident it's real, one way or the other?

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.

Step 6: Where does χ² actually come from?

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:

Expected count = (row total × column total) / grand total

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:

No Yes Music 23 17 Silence 23 17

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:

chi-square = sum( (Observed - Expected)^2 / Expected ) = 10^2/23 + 10^2/17 + 10^2/23 + 10^2/17 = 20.46

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:

chi-square (Yates) = (10 - 0.5)^2/23 + (10 - 0.5)^2/17 + (10 - 0.5)^2/23 + (10 - 0.5)^2/17 = 18.47

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.

What we skipped (on purpose)

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.

Look ahead: what does Chapter 21 already say?

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.

Question 4 — 3 points (answer in your answer document): Chapter 21 has a table of Cramér's V benchmarks (0.1 small, 0.3 moderate, 0.5 large). Using it: is V = 0.506 from the noise-and-distraction study small, moderate, or large?

Chapter 21 also shows how to compute standardized residuals for each cell of a table (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?