IAT 461 · Data Science for Human-Centered Systems

Where does a p-value actually come from?

You've heard the definitions: sampling distributions, the null hypothesis, p < 0.05. This is the part where they stop being vocabulary and start being something you can see — by shuffling a pile of dots until the idea clicks.

Scroll down. As each idea comes into view, the picture on the left plays itself — then hands you the controls to try.


Each dot is one of our 200 gamers, placed by how many hours they play per day. Most play a little; a few play a lot.
Part 1 · The problem with one number

We never get to measure everyone

Suppose we want to know how much people game. Not these 200 people specifically — people, in general. The trouble is obvious: we can't survey the whole planet. So we grab whoever we can, measure them, and hope our little group reflects the bigger picture.

On the left is a stand-in for “everyone” — 200 gamers and their daily hours. Pretend this is the truth we wish we knew but normally can't.

The blue line is the true average 2.86 hours. In real life this line is invisible. We only ever see a handful of people and have to guess where it sits.

Top (circles): 200 individual people — each dot is one real person. Bottom (purple diamonds): one diamond per sample, placed at that sample's average. These are summaries of samples, not individual people.
Part 1 · Sampling

Let's take a small sample

Taking a sample is like scooping a cup of water from a lake to guess its temperature. Watch the left: we repeatedly grab just 5 people at a time. Each orange line is that scoop's guess at the average.

See how wildly the guesses jump around the true blue line — and how scattered the purple diamonds at the bottom are. With only 5 people, a single sample can be way off.

Now a much larger sample

Same population, same scooping — but this time we grab 120 people each draw. Watch the diamonds pile up again on the left.

The cloud is far tighter now, hugging the true average. The individual people up top haven't changed at all — only the size of each scoop did. Bigger samples give steadier guesses.

The key idea
That contrast is the Central Limit Theorem.The pile of sample means settles into a bell curve centred on the true average — even though our population is lopsided. And its width shrinks as 1 / √n: quadruple the sample size and the wobble halves. Bigger samples don't remove randomness — they make it predictable.
Your turn
Drag the sample size slider on the left down to 5 and click Scoop 25× — watch the diamonds scatter. Then drag it up to 150 and scoop again. The cloud should snap tight around the blue line.
The catch

We only ever get one sample

Here's the quiet trick Part 1 played: to build that cloud of diamonds, we scooped from all 200 people a thousand times. Real research almost never works that way. You usually get a single sample — say 30 players — and a single average. You can't go back and redraw from the population, because you never had the population to begin with.

So the sampling distribution — the thing that tells us how much our number could have wobbled — is exactly what we need and exactly what we can't see. The rest of this page is about a clever way to rebuild it from the one sample we do have.

The core idea
Treat your sample as a stand-in for the population.If your sample is all you know about the world, then resampling from your sample is the next best thing to drawing fresh samples from the population. That move — resampling — is what powers everything in Part 2. It comes in two flavours: shuffling the data to test a hypothesis, and drawing from it with replacement to measure uncertainty. We'll use both.
League players play0.93 hrsmore per day, on average.
Same x-axis for both groups so you can compare directly. The dashed lines mark each group's average.
Part 2 · The real question

Do league players game more?

Now the question we actually care about. We have two groups: 80 casual players and 80 competitive league players. We suspect the league players play more. Let's look.

So league players do play more — about an hour a day more, on average. Case closed? Not quite. Remember the last section: even identical groups would show some gap, just from the luck of who we sampled. The honest question is sharper:

“Is this gap real — or is it the kind of gap luck hands out for free?”

If the labels mean nothing, the two groups are really just one crowd. That single crowd is our 'null world.'
Part 2 · The skeptic

Imagine nothing is going on

To answer that, we play devil's advocate. We assume the boring explanation is true: the two groups are really the same, and the gap we saw is pure coincidence. Statisticians call this the null hypothesis — but you can just call it the skeptic's assumption.

If the skeptic is right, then the labels “casual” and “league” don't mean anything. Everyone is really from one big crowd. Watch on the left: we dump all 160 people into a single pool and forget who was who. That pool is our null world.

A single shuffle of the labels

This shuffle's gap: +0.39 hrs — it drops onto the pile below.

0 gaps collected
Top: one shuffle of the labels (blue = fake A, orange = fake B). Bottom: every shuffle's gap, stacked into a histogram. Build it up one shuffle at a time, then let it rip.
Part 2 · Resampling, flavour one

Deal the labels at random

This is our first resampling move — shuffling. If the labels are meaningless, we can deal them out at random: 80 people get an “A” tag, 80 get a “B” tag, purely by chance.

Watch the left: each shuffle recolours the pool and measures the gap between those fake groups. A few gaps drop onto the pile at the bottom — every one of them is something luck produced on its own.

A thousand shuffles, one verdict

One shuffle proves nothing, so we let it run a thousand times. The histogram filling in on the left is a portrait of what chance alone can do.

Our real gap is the dashed orange line. To get the p-value, we count: of all those luck-only gaps, how many reached the orange line or beyond (the orange bars)? Divide by the number of shuffles — that fraction is the p-value.

The key idea
A small p-value means “luck almost never does this,” which makes the skeptic's “it's just chance” story hard to believe. It is not the probability the skeptic is right, and it says nothing about whether the difference is big enough to care about.

Run it yourself

The board is cleared. Build the pile by hand and watch the p-value emerge.

Your turn
Click Shuffle once three or four times — watch each single gap land on the pile. Then hit Run 1000 shuffles and read off the p-value in the box below the chart. Does luck often beat our real gap?
Raw difference
0.92 hrs
Cohen's d
0.46 (small)
Groups overlap
82%
Two groups drawn with the same spread as our real data, separated by the effect size you choose. The grey overlap is how often the two groups look the same.
Part 2 · Significant ≠ big

First, a tiny effect

A p-value only answers “is it real?” It says nothing about “is it big?” To feel the difference, watch two groups with the same spread as our data slide apart on the left.

Right now the separation is tiny — the two bells almost completely overlap. A person from one group is nearly indistinguishable from the other. This is a negligible effect.

Now a large effect

Watch the curves pull apart on the left. The grey overlap shrinks: the groups are now clearly distinct, though — notice — even a “large” effect keeps a surprising amount of overlap.

The number driving this is Cohen's d: the raw gap divided by the data's own spread, so it's comparable across any study. Roughly, 0.2 is small, 0.5 medium, 0.8+ large.

And our actual data

The curves have now settled on the effect size measured in our real groups. That's the honest picture of how far apart casual and league players actually sit.

The key idea
Two numbers, two jobs. The p-value tells you whether a difference is likely real. Cohen's d tells you whether it's big enough to care about. A result can be significant and practically tiny — always report both.
Your turn
Drag the Cohen's d slider on the left, or tap the presets (Small → Large). Watch the overlap % at the bottom change as the curves move. How large does d need to be before the groups barely overlap?

The original bag (8 values, in hours)

1
2
2
3
4
5
7
9
A bag of 8 values. A resample is the same size — but every pick is independent, so some values get grabbed twice and others not at all.
Part 2 · Resampling, flavour two

Drawing with replacement

Shuffling answered “is it real?”. The second flavour answers “how big, and how sure?” — and it leans on drawing with replacement. Watch the small bag on the left: we draw 8 picks, but every pick is independent, so some values get grabbed twice and others not at all.

Why allow repeats? Because we only have one sample, but we want to know how much our answer would bounce around if we could collect fresh samples over and over. Treating our data as a stand-in “population” and drawing from it with replacement manufactures that wobble. That's the bootstrap.

Your turn
Click Draw a resample on the left a few times. Watch the ×2 badges appear on tokens that got picked twice, and faded tokens that weren't picked at all — and notice the resample's average shift each time.

One resample of both groups

This resample's gap: +0.73 hrs (faint dashed lines mark the original group averages). It drops onto the pile below.

0 gaps collected
Top: one bootstrap resample of each group (drawn with replacement), with each group's resampled average and the gap between them. Bottom: every resample's gap, stacked into a histogram. The shaded band is the middle 95%.
Part 2 · The confidence interval

Bootstrap both groups

Now we bootstrap both groups at once. Watch the left: each resample draws a fresh Group A and Group B from our data (with replacement), recomputes each average, and measures the gap.

See the two mean lines jitter and the gap change every time? Each gap drops onto the pile below — that bounce is exactly the uncertainty we want to capture.

A thousand resamples

Let it run a thousand times and the gaps stack into a histogram. The shaded band on the left is the middle 95% — a 95% confidence interval for the true difference.

It tells a richer story than p alone: not just “there's a difference,” but roughly how big, and how sure we are. If the whole band sits above zero, “no difference” looks unlikely.

Build the interval yourself

The pile is cleared — your turn to fill it.

Your turn
Click Resample once a few times to feel the bounce, then Run 1000 resamples. Read the 95% CI that appears below the chart. Does the interval clear zero?
The blue bars are our 1000 shuffles. The orange curve is the smooth bell shape a t-test assumes. They line up — which is why the formula works when its assumptions hold.
Zooming out

This is one recipe, not the only one

Everything here computed a p-value by simulation — shuffling and resampling until the answer appeared. That's the bootstrap / permutation approach, and it's wonderfully literal: you can watch it happen. But it's not the only way, and historically it's not even the usual one.

Long before computers could shuffle a thousand times in a blink, statisticians derived formulas for the null distribution by assuming it had a particular shape — usually a bell curve. The famous t-test does exactly that: it skips the shuffling and reads the p-value off a formula. See how our shuffled histogram and the smooth curve trace the same shape?

That's the punchline: the formula is a shortcut for the simulation we just ran by hand. Each named test you'll meet — the t-test for two means, the chi-square for counts, Mann–Whitney for ranks, an ANOVA for several groups — is just a different recipe for the same question: how surprising is my data if nothing is going on?

Simulation makes few assumptions and you can see it work. Formulas offer speed and a century of practice. Now that you've watched the machinery turn, those formulas should feel less like magic and more like a convenient shortcut.

Wrapping up

The whole idea, step by step

  1. 1A sample only gives a wobbly guess at the truth — and the wobble is predictable.
  2. 2To test a difference, first assume the skeptic is right: nothing is going on.
  3. 3Pool everyone, then reshuffle the labels over and over to see what gaps pure luck creates.
  4. 4The p-value is how often luck matches or beats what you actually saw.
  5. 5Then answer what luck can't: how big is the effect (Cohen's d) and what's the plausible range (a confidence interval).
  6. 6Formula-based tests like the t-test are just fast shortcuts for the same simulation.