Data science spotlight · Lesson 5B

When Is It Just Luck?

Pip is back, with a new job and a new question: when does something stop looking like luck? No maths needed to follow it. The maths sits underneath, for anyone who wants to look.

Pip joins the hospital data team

Pip used to sort junk email. Now Pip helps a hospital decide when a patient’s readings are worth worrying about, and when they are just the everyday wobble of real life.

Every day Pip faces the same puzzle: “Is this a real change, or could it easily be luck?” Answer too jumpily and the wards drown in false alarms. Answer too calmly and real problems slip by.

Follow Pip through six everyday situations. Anything marked Try it is a toy you can play with.

1

The friend with the lucky coin

Try it

Data scientists say: “the coin is fair” is the null hypothesis (H0), and “how often luck alone does this” is the P-value.

Pip’s friend flips a coin six times and gets six heads. “It’s a lucky coin!” Pip thinks like a court: innocent until proven guilty. Assume the coin is perfectly fair, then ask how often a fair coin would do something this extreme anyway.

Six tails would be just as suspicious, so Pip counts both. Flip a fair coin six times, or let Pip do it a thousand times.

0 of 0
tries landed six of the same face.

A fair coin does this about 3 times in every 100 tries. Rare, but not impossible.
2

How rare is rare enough?

Try it

Data scientists call the “beyond reasonable doubt” line the significance level, α, usually 0.05. Below it they reject H0; above it they fail to reject H0.

A court needs evidence beyond reasonable doubt. Pip’s version: if luck alone would do this fewer than 5 times in 100 (0.05), Pip stops believing it is luck. Slide to change how many of the same face came up in a row.

2 in a row10 in a row

Luck alone does this of the time.

  • Two in a row is the coin example from the session: P = 0.50. Half of all pairs of tosses do that, so it says nothing.
  • “Fail to reject” is not “proved fair”. A court that finds someone not guilty has not proved them innocent. It just lacked the evidence.
For the curious: where the numbers come from
P=P(all heads)+P(all tails)+P(anything rarer)

The three parts of a P-value: what you saw, the equally rare outcome in the other tail, and anything more extreme still.

=(12)k+(12)k+0=2×(12)k

With k = 6: 2 × 1/64 = 2/64 ≈ 0.031, below 0.05. With k = 2: 2 × 1/4 = 0.50.

3

Did the holiday change anyone’s weight?

Try it

Data scientists call the same people measured twice a paired t-test, and two separate groups an unpaired (independent) t-test.

Eight friends weigh themselves before and after a fortnight away. They are all different sizes, more than 35 kg apart. Did the holiday change anything? Look at the same numbers two ways.

For the curious: degrees of freedom
paired: df=n−1=8−1=7

One difference per person, so a paired test works on 8 numbers.

unpaired: df=n1+n2−2

For two genuinely separate groups, such as people in two different towns.

4

The sat nav is never quite right

Try it

Data scientists call the minutes early or late the prediction error or noise. Early as often as late is a mean of 0; the typical size of a miss is the standard deviation, σ.

The sat nav says 14:20. Pip logs how many minutes early or late each journey really is. This sat nav’s typical miss is about 4 minutes. Drive some journeys and watch the pattern appear.

Journeys0
Within 4 minutes–
Within 8 minutes–

Keep driving: the middle settles near 68% and the wider band near 95%, the empirical rule from Part A. The patient risk model’s noise is exactly this, with a standard deviation of 4 units instead of 4 minutes.

5

Turn minutes into a chance

Try it

Data scientists call “how many typical misses away” a Z-score, and the shaded area the upper tail.

How often is Pip more than x minutes late? First, count how many typical misses that is: x divided by 4. Then read off the area beyond it under the curve.

012
Typical misses away (Z)
Chance of being later than that
For the curious: the session’s worked example, line by line
Z=x−μσ=4−04=1.0
P(0≤Z≤1.0)=0.3413

From the standard normal table: the area between the middle and Z = 1.

P(Z>1.0)=0.5000−0.3413=0.1587

The whole upper half is 0.5000, so take away the table area: about 15.9%.

6

The car alarm that cries wolf

Try it

Data scientists call an alarm with nothing wrong a false alarm (false positive), staff tuning them out alarm fatigue, and the line itself the alert threshold.

A car alarm set too sensitive goes off for every passing cat, and soon nobody looks up. Pip has to set the line for a ward monitor that checks a perfectly stable patient 24 times a day. Every reading outside the line sounds the alarm.

JumpyVery calm
Readings that sound the alarm
False alarms a day, for one stable patient

Set the line too far out, though, and a patient who really is getting worse can stay inside it for longer. Choosing the line is a trade-off, and explaining that trade-off is what strong work does.

The jargon, translated

Everything above has a proper name. Here is the dictionary, with the symbol where there is one.

If you can explain to a friend why six heads in a row makes you suspicious but two does not, you understand hypothesis testing. The formulas just make “suspicious” precise.