Today's lesson

T-tests

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

What a t-test is

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.

What "real" means here

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

What is one row?

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:

  1. Compared to a fixed number

    → one-sample t-test

  2. Split into two separate groups

    → independent-samples t-test

  3. 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 theme, three questions: sleep

One group vs. a number

One-sample

Do York students sleep less than the recommended 7 hours a night?

One group, compared against a fixed benchmark.

Two separate groups

Independent

Do students who work sleep less than students who don't?

Two different sets of people.

The same people, twice

Paired

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

Three numbers, then three sentences

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

One-sample — do York students sleep less than 7 hours?

20 students reported hours slept last night, compared against the recommended 7.

TestMean 1Mean 2Differencep-value
One-sample — students vs. 7 hours5.997.00−1.010.000
The three sentences Direction: students slept less than the recommended 7 hours.
Size: just over an hour less on average (5.99 vs. 7.00).
Belief: p < .001, below .05, so the difference is likely real.
In plain words: the students in this sample sleep just over an hour less than recommended, and that gap is very unlikely to be chance.

Independent — do students who work sleep less?

12 students who work, 12 who don't.

TestMean 1Mean 2Differencep-value
Independent — work vs. don't work6.466.81−0.350.329
The three sentences Direction: students who work slept a little less than students who don't.
Size: about a third of an hour less (6.46 vs. 6.81).
Belief: p = .33, above .05, so this difference could easily be chance.
In plain words: working students in this sample slept slightly less, but the gap is small enough that it could be chance. That does not prove there is no difference — with only 12 people per group, a small real difference is hard to see.

Paired — do students sleep less during finals week?

The same 15 students, reported twice.

TestMean 1Mean 2Differencep-value
Paired — normal week vs. finals week7.266.251.010.000
The three sentences Direction: students slept less during finals week than in a normal week.
Size: just over an hour less on average (7.26 vs. 6.25).
Belief: p < .001, below .05, so the difference is likely real.
In plain words: the same students lost just over an hour of sleep a night during finals week, and that drop is very unlikely to be chance.

An output of 0.000 is reported as p < .001 — the same rule as regression. A p-value is never exactly zero.

5 Practice

Two more themes

Same routine. For each table: direction, size, belief, then one plain sentence. One result in each theme is not significant — find it.

Screen time, hours per day

TestMean 1Mean 2Differencep-value
One-sample — more than 7 hours a day? (20 students)8.397.001.390.000
Independent — sports vs. no sports (12 vs. 12)7.678.03−0.360.509
Paired — weekday vs. weekend (same 15)6.918.26−1.350.000

Water, glasses per day

TestMean 1Mean 2Differencep-value
One-sample — less than 8 glasses? (20 students)7.558.00−0.450.243
Independent — gym vs. no gym (12 vs. 12)7.835.422.420.000
Paired — school day vs. weekend (same 15)5.607.27−1.670.000

All of these are made up. The point is the reading, not the finding.

6 In groups

Write your own three

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

"I am amazing"

Now we make our own data, in this room, and run all three tests on it.

  1. The benchmark

    Dr. Jacques writes "I am amazing" as many times as she can in one minute. That count is the number to beat.

  2. 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.

  3. One yes/no question

    The class picks something that might affect writing speed — for example, do you play an instrument?

  4. On the board

    Every student's two counts and their yes or no, one row each.

Why writing hand and other hand, instead of left and right

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.

I am amazing — one minute
Benchmark (Dr. Jacques, writing hand): ______
Yes/no question: ____________________
StudentWriting handOther handYes / No
1
2
3
…
One row per student, and do not add the columns up

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.

All three tests come off that one table

Class vs. a number

One-sample

Can the class beat Dr. Jacques? Class writing-hand average against her count.

Two separate groups

Independent

Do the "yes" group write faster than the "no" group? Writing-hand counts only.

Same people, twice

Paired

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

The prompt

Paste this into an AI chat, then paste the class table underneath it.

Prompt · runs all three t-tests
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:
Today's numbers Our class results are posted here: Class results — Fall 2026. Use those figures for your portfolio page.

Then read it the same way as everything else

  1. The means

    The average for each group, or the class average and the benchmark.

  2. The difference

    How far apart those averages are.

  3. The p-value

    Below .05 means the gap is unlikely to be chance.

Your write-up, for each test Direction: which group is higher.
Size: by how much.
Belief: the p-value against .05.
Then one sentence in plain words — and no causation.

9 Your portfolio piece

ttest.html

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.

What goes on the page

Report all three, including the one that did not work

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.

What you would do differently

You designed this study, so you get to say what was weak about it. Things worth naming:

Write it yourself first

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.

Then build the page

Prompt · builds ttest.html
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]

Publish it

  1. Create the file

    In your repository: Add file → Create new file, name it exactly ttest.html, paste in everything under “Thing 1,” commit.

  2. 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.

  3. 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

One line

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.