Day 3: Why Do We Care? — A First Look at Regression

10 points — graded

Same idea as the t-test and ANOVA previews: a real research question, answered start to finish, before we've covered the machinery formally. This time both variables are continuous — not "which group are you in," but "how much of something do you have." We'll come back to today's main dataset, formally, in Chapter 22.

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 how much sleep a student gets the night before predicts how well they do on a quiz the next morning. Fifty students reported their hours of sleep and then took the same 12-point quiz.

Does more sleep predict a better quiz score?

t-test day and ANOVA day both compared groups — silence vs. chatter, four attention tasks. This question is different: sleep hours isn't a category, it's a number that can be anything from 4 to 9. When both your predictor and your outcome are numbers like this, you're not comparing groups anymore — you're asking whether one number tracks the other. That's regression.

Step 1: Look before you test

df <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/regression_preview.csv") head(df)
Before you scroll (self-check, not submitted): On t-test day and ANOVA day you wrote boxplot(y ~ x, data = df) because x was a category (a grouping variable). Here sleep_hours is a number, not a category — a box for every possible value doesn't make sense. What kind of plot shows the relationship between two continuous variables instead? Jot your guess, then check below.
plot(quiz_score ~ sleep_hours, data = df, main = "Quiz Score by Hours of Sleep", ylab = "Quiz score", xlab = "Hours of sleep")

Same outcome ~ predictor, data = formula as boxplot() — R just draws a scatterplot instead of boxes, because it can see sleep_hours is numeric, not categorical. One dot per student, and the cloud of dots drifts upward left-to-right: more sleep, higher scores, roughly. That's the pattern we're about to test.

Step 2: Run the test

model <- lm(quiz_score ~ sleep_hours, data = df) summary(model)
Same shape, new function — the third time now. lm(quiz_score ~ sleep_hours, data = df) — outcome, ~, predictor, data =. Identical structure to t.test(words_recalled ~ study_environment, data = df) on Day 1 and aov(reaction_time ~ attention_condition, data = attn) on Day 2. Three different questions, three different functions, one formula shape. lm() stands for "linear model" — it fits the straight line that best tracks the cloud of dots you just plotted.
Call: lm(formula = quiz_score ~ sleep_hours, data = df) Residuals: Min 1Q Median 3Q Max -1.9149 -0.8409 -0.1372 0.7966 3.2998 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.6614 1.0851 2.453 0.0179 * sleep_hours 0.7592 0.1508 5.036 7.12e-06 *** --- Residual standard error: 1.259 on 48 degrees of freedom Multiple R-squared: 0.3457, Adjusted R-squared: 0.3321 F-statistic: 25.37 on 1 and 48 DF, p-value: 7.122e-06

Step 3: Pull out what matters

Six numbers this time, regression's version of t-test day's five and ANOVA day's six:

WhatValueFor now, just know...
Intercept2.66The line's predicted quiz score at 0 hours of sleep — mathematical, not something anyone actually experienced (nobody in this dataset slept 0 hours).
Slope0.76For every extra hour of sleep, predicted quiz score goes up by about 0.76 points. This is the headline number — it says how much, not just whether.
F25.37Same idea as ANOVA day's F — a bigger F means the line explains more than you'd expect from noise alone.
df1, 481 comes from having one predictor; 48 from the sample size. Same logic as ANOVA's df, just simpler with only one predictor.
p7.12e-06 (report as p < .001)How implausible it'd be to see a slope this steep if sleep and quiz score were actually unrelated.
R²0.346The size of the relationship — about 35% of the variation in quiz scores is explained by hours of sleep. Same job as ANOVA day's eta², different name, same idea: p says "probably real," R² says "how much it matters."
So what's the answer? In plain language: students who slept more tended to score higher on the quiz — about three-quarters of a point higher per extra hour of sleep — and that pattern is far too strong to be a coincidence, though sleep alone only accounts for about a third of why scores differed.
Question 1 — 1 point (answer in your answer document): A regression line doesn't know why two things move together — only that they do. Name one reason a well-rested student might also score higher on a quiz for reasons that have nothing to do with sleep itself. (We'll come back to correlation-vs-causation formally in Chapter 22.)

Step 4: Your turn — two more questions

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

Question 2: Shoe size and GPA — fill in the blanks (2 points)

Some people swear that people with bigger feet do better in school. Every student in df also has a shoe size and a GPA on file.

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

plot(gpa ~ ____, data = df, main = "GPA by Shoe Size", xlab = "Shoe size", ylab = "GPA") summary(lm(gpa ~ ____, data = df))
Rest of Question 2 — record in your answer document: Write your own one-sentence answer, plain language, no stats jargon: does shoe size predict GPA here, or not?

Now find R² yourself: it's printed directly in your summary() output as "Multiple R-squared" — you don't need to calculate anything this time. Just report the number and say what it means in one sentence.

Question 3: Commute time and morning alertness — write it yourself (2 points)

The same fifty students reported how many minutes it takes them to travel to campus, and rated their own morning alertness on a 1–10 scale.

Does travel time predict how alert students feel in the morning?

No starter code this time. Using the pattern from Questions 1 and 2, write R code to:

  1. Plot morning_alertness by travel_time
  2. Fit the regression predicting morning_alertness from travel_time
  3. Read off the slope, R², F, and p from your output
Question 3 — record in your answer document: Write your own one-sentence answer, plain language, no stats jargon: does travel time predict morning alertness here, or not?

Step 5: Compare all three

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

QuestionSlopeFdfpR²Verdict
Sleep → quiz score0.7625.371, 48<.001.346Clearly significant
Shoe size → GPAFill in this row in your answer document
Travel time → alertnessFill 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 t-test day and ANOVA 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 R² 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 do the slope and R² actually come from?

Same spirit as the SE reveal on Day 1 and the F/eta² reveal on Day 2 — this time, both numbers come straight from something you already know how to calculate: the correlation, r, and the two variables' standard deviations.

slope = r × (SD of quiz_score / SD of sleep_hours) = 0.588 × (1.541 / 1.193) = 0.759

R² has an even shorter version, unique to simple regression — it's just the correlation, squared:

R² = r² = 0.588² = 0.346

Same numbers R gave us, just recombined. A stronger correlation (r closer to ±1) means a steeper slope relative to the two variables' spread, and a bigger R² — the two are the same relationship viewed two ways. Everything Chapter 20 (correlation) covers about r is the foundation this chapter builds on.

What we skipped (on purpose)

We didn't check any assumptions before running these tests (linearity, normally distributed residuals, constant spread). We also didn't ask why sleep and quiz score move together — a regression line describes a pattern, it doesn't explain it, and "sleep causes better quiz performance" is a bigger claim than this data alone can support. Both are coming: residual diagnostics in Chapter 25, and the causation question gets a full treatment in Chapter 22.

Look ahead: what does Chapter 22 already say?

You haven't read Chapter 22 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 R² value, and how to put a margin of error around the slope itself.

Question 4 — 3 points (answer in your answer document): Chapter 22 has a table of R² benchmarks (.01 small, .09 medium, .25 large). Using it: is R² = 0.346 from the sleep-and-quiz-score study small, medium, or large?

Chapter 22 also shows how to get a confidence interval on the slope with confint(model). In one sentence, what would a confidence interval on the sleep_hours slope tell you that the single number 0.76 alone does not?