Statistics ยท hard

What is p-hacking and how do you avoid it?

Asked in Data Scientist interviews, in the Statistics round.

Short answer

Pre-register hypotheses, correct for multiple comparisons, fix sample size in advance.

How to answer it

Definition

Searching, consciously or not, until something crosses p < 0.05, then reporting that result as if it had been the plan all along. The individual steps all look reasonable; the problem is that the search itself is never declared.

What it looks like

Why it works so well

1 test at alpha 0.05           5% chance of a false positive
20 independent tests           1 - 0.95^20  =  64%

Twenty honest tests on twenty useless metrics gives about a coin flip's chance of at least one significant result. Nobody lied; the search space did the work.

Peeking is the same problem

Checking a test daily and stopping at significance is multiple comparisons spread over time. A fixed-horizon test checked ten times can carry a real false-positive rate several times the nominal 5%.

How to avoid it

Key points

FAQ

The 30-second answer

P-hacking is searching until something crosses the significance threshold and then presenting it as though it had been the plan. Usually nobody is cheating: they peek at a running test and stop when it turns green, or check twenty metrics and report the one that moved.
The arithmetic is what makes it dangerous. Twenty independent tests at five percent give about a sixty-four percent chance of at least one false positive, so the search itself manufactures the result.
I avoid it by writing down the primary metric, the sample size and the stopping rule before the test runs, correcting for multiplicity when I really am testing many things, and treating anything found by slicing as a hypothesis to confirm on fresh data rather than as a finding.

In the interview

Practice this for real