Today's lesson
A regression asked whether two numbers move together. Today we ask something simpler: two averages are different — is that difference real, or could it just be chance?
1 The idea
A t-test compares averages and asks whether a difference is real or could just be chance.
Why we need it. Two groups almost never have exactly the same average, even when there is no true difference between them. Who happened to land in which group, or who had a bad day, makes averages wobble. The t-test asks whether the gap is bigger than chance alone would usually produce. If the p-value is below .05, we call the difference real.
Only "not chance." A t-test does not tell you why there is a difference. A real difference can still come from something else entirely — and that is a study design question, not something this test answers.
A t-test needs a number outcome — hours, scores, counts. Not a category.
2 First question
Before choosing a test, ask what a single unit is. A person? A ZIP code? Same question as the regression weeks.
Then ask what happens to each unit. That is what picks your test:
Compared to a fixed number
→ one-sample t-test
Split into two separate groups
→ independent-samples t-test
Measured twice — two numbers for the same unit
→ paired-samples t-test
Paired just means the same unit gives both numbers. Before and after is the most common kind, but two conditions counts too.
All three are called Student's t-tests. "Student" was the pen name of the man who invented it, not a reference to you.
3 The three types
One group vs. a number
Do York students sleep less than the recommended 7 hours a night?
One group, compared against a fixed benchmark.
Two separate groups
Do students who work sleep less than students who don't?
Two different sets of people.
The same people, twice
Do students sleep less during finals week than a normal week?
Same students, measured on two occasions.
The same three shapes work on anything. Two classes' exam scores: one class against a passing mark of 70 is one-sample; two different classes is independent; one class before and after a review session is paired.
4 Reading the output
These sleep numbers are made up, for practice. Read only three things in each table: the two means, the difference, and the p-value.
means and differencep-value
20 students reported hours slept last night, compared against the recommended 7.
| Test | Mean 1 | Mean 2 | Difference | p-value |
|---|---|---|---|---|
| One-sample — students vs. 7 hours | 5.99 | 7.00 | −1.01 | 0.000 |
12 students who work, 12 who don't.
| Test | Mean 1 | Mean 2 | Difference | p-value |
|---|---|---|---|---|
| Independent — work vs. don't work | 6.46 | 6.81 | −0.35 | 0.329 |
The same 15 students, reported twice.
| Test | Mean 1 | Mean 2 | Difference | p-value |
|---|---|---|---|---|
| Paired — normal week vs. finals week | 7.26 | 6.25 | 1.01 | 0.000 |
An output of 0.000 is reported as p < .001 — the same rule as regression. A p-value is never exactly zero.
5 Practice
Same routine. For each table: direction, size, belief, then one plain sentence. One result in each theme is not significant — find it.
| Test | Mean 1 | Mean 2 | Difference | p-value |
|---|---|---|---|---|
| One-sample — more than 7 hours a day? (20 students) | 8.39 | 7.00 | 1.39 | 0.000 |
| Independent — sports vs. no sports (12 vs. 12) | 7.67 | 8.03 | −0.36 | 0.509 |
| Paired — weekday vs. weekend (same 15) | 6.91 | 8.26 | −1.35 | 0.000 |
| Test | Mean 1 | Mean 2 | Difference | p-value |
|---|---|---|---|---|
| One-sample — less than 8 glasses? (20 students) | 7.55 | 8.00 | −0.45 | 0.243 |
| Independent — gym vs. no gym (12 vs. 12) | 7.83 | 5.42 | 2.42 | 0.000 |
| Paired — school day vs. weekend (same 15) | 5.60 | 7.27 | −1.67 | 0.000 |
All of these are made up. The point is the reading, not the finding.
6 In groups
In your group, write one question of your own for each of the three tests. Each group shares one with the class and says why it fits that test — one group against a number, two separate groups, or the same people twice.
If you can invent the question, you understand the test. That is the whole check.
7 Live data
Now we make our own data, in this room, and run all three tests on it.
The benchmark
Dr. Jacques writes "I am amazing" as many times as she can in one minute. That count is the number to beat.
Your turn, in groups of three or four
One person keeps time. Everyone else writes "I am amazing" for one minute with their writing hand, then one minute with their other hand. Rotate until everyone has gone.
One yes/no question
The class picks something that might affect writing speed — for example, do you play an instrument?
On the board
Every student's two counts and their yes or no, one row each.
Handedness is an outside variable. Left versus right would mix right-handers and left-handers together, and their differences would cancel out. Writing hand versus other hand controls for it.
And everyone writes the same sentence so that name length does not creep in, and so the benchmark is fair.
| Student | Writing hand | Other hand | Yes / No |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| … |
The test runs on the whole class's rows, not on one person. One person gives one difference, and you cannot test a single number.
Class vs. a number
Can the class beat Dr. Jacques? Class writing-hand average against her count.
Two separate groups
Do the "yes" group write faster than the "no" group? Writing-hand counts only.
Same people, twice
Writing hand against other hand, for each student.
Expect the independent test to come out non-significant. With a class this size it splits into two small groups. That is not proof there is no difference — it may just mean too few people. It is also why studies you read report how many people were in them.
8 Run it
Paste this into an AI chat, then paste the class table underneath it.
Below is a table from my biostatistics class. Each row is one student. The columns show how many times they wrote "I am amazing" in one minute with their writing hand, how many times with their other hand, and their answer to a yes/no question. My professor's writing-hand count is the benchmark, written above the table. Please run three t-tests: 1. A one-sample t-test comparing the class's writing-hand mean to my professor's count. 2. An independent-samples t-test comparing writing-hand counts between the "yes" and "no" groups. 3. A paired-samples t-test comparing each student's writing hand to their other hand. Give me the results as ONE table with one row per test and these columns: Test, Mean 1, Mean 2, Difference, p-value. Only those five columns - no t, no degrees of freedom, no confidence intervals. Put the means, the difference and the p-value in bold. Do not show me code. Do not explain or interpret the results. Here is the table:
The means
The average for each group, or the class average and the benchmark.
The difference
How far apart those averages are.
The p-value
Below .05 means the gap is unlikely to be chance.
9 Your portfolio piece
Every other page in your portfolio is you reading somebody else's numbers. This one is yours — your class, your data, collected in this room today.
If a test came back above .05, it goes on the page with the others. Dropping the result you did not like is the thing this whole course is against.
You designed this study, so you get to say what was weak about it. Things worth naming:
All of it — the method, the three write-ups, the plain-language part and the limitations — before you open any AI. That writing is the assignment.
I am a public health student. I am adding a page to my portfolio website about a small study my class ran. I do not write code. Give me exactly two things, clearly labeled, and nothing else: THING 1 - the file. Start by writing the line: "Save this as: ttest.html" Then give me one complete HTML file in a single code block, from <!DOCTYPE html> to </html>. Do not shorten it or leave anything out. THING 2 - the link. Give me one line of HTML, in its own code block, that I can paste into my homepage so people can reach this page: <a href="ttest.html">MY TITLE HERE</a> Rules for the file: - Use my words below exactly. Do not rewrite my sentences to sound better, do not add an introduction or a conclusion, do not invent any numbers. You may fix spelling, grammar and punctuation. - Lay out my results as a clean table with these columns only: Test, Mean 1, Mean 2, Difference, p-value. - Match a simple professional portfolio page: one column, no wider than about 700px, centered, generous line height, all CSS inside a <style> tag in the same file. No frameworks, no JavaScript. It must read well on a phone. - Put the same navigation I already use on my other pages at the top. - Put a link at the bottom back to my homepage: <a href="index.html">Home</a> - At the very bottom in small text: my name and "PH 320 · Applied Biostatistics in Public Health". Do not explain anything. Do not give me instructions. MY TITLE: [e.g. Does Your Writing Hand Beat Your Other Hand?] WHAT WE DID: [paste your 3-4 sentences here] MY RESULTS: [paste your table of results here] THE THREE WRITE-UPS: [paste direction, size and belief for each of the three tests] IN PLAIN WORDS: [paste your 2-3 plain sentences here] WHAT I WOULD DO DIFFERENTLY: [paste your limitations here]
Create the file
In your repository: Add file → Create new file, name it exactly ttest.html, paste in everything under “Thing 1,” commit.
Add it to your menu
Put the link from “Thing 2” into your navigation, on every page — that is why we built the menu to grow.
Check it from the outside
Open your Vercel address, and click your way to the new page without typing a URL.
10 Leaving with this
A t-test compares two averages and tells you whether the gap is bigger than chance usually produces. It never tells you why the gap is there.