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 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.
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.
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.
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.
Six numbers this time, regression's version of t-test day's five and ANOVA day's six:
| What | Value | For now, just know... |
|---|---|---|
| Intercept | 2.66 | The line's predicted quiz score at 0 hours of sleep — mathematical, not something anyone actually experienced (nobody in this dataset slept 0 hours). |
| Slope | 0.76 | For 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. |
| F | 25.37 | Same idea as ANOVA day's F — a bigger F means the line explains more than you'd expect from noise alone. |
| df | 1, 48 | 1 comes from having one predictor; 48 from the sample size. Same logic as ANOVA's df, just simpler with only one predictor. |
| p | 7.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.346 | The 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." |
New variables, same dataset, same URL — no re-downloading anything.
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.
The code below has two blanks. Fill them in using the pattern from Step 1–2 before you run it:
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.
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:
morning_alertness by travel_timemorning_alertness from travel_timeFill in the rows for Question 2 and Question 3 yourself, then look at the pattern:
| Question | Slope | F | df | p | R² | Verdict |
|---|---|---|---|---|---|---|
| Sleep → quiz score | 0.76 | 25.37 | 1, 48 | <.001 | .346 | Clearly significant |
| Shoe size → GPA | Fill in this row in your answer document | |||||
| Travel time → alertness | Fill in this row in your answer document | |||||
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.
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.
R² has an even shorter version, unique to simple regression — it's just the correlation, squared:
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.
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.
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.
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?