1. Home
  2. Explore
  3. Mathematics
  4. Coin Flip Cheaters

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Coin Flip Cheaters

Frequentist Hypothesis Testing: Detecting Cheaters with Coin Flips

This set of notes covers the core concepts of frequentist hypothesis testing, illustrated through the example of detecting players using unfair (biased) coins in a simple game. The ideas apply broadly to scientific studies making decisions with limited data.


The Problem: Detecting Unfair Coins

  • A game involves flipping coins; some players might use trick coins that land heads more than 50% of the time.

  • The goal is to design a test to catch these cheaters using as few coin flips as possible.

  • Due to randomness, it is impossible to be 100% certain whether a player is cheating, but some approaches are better than others.

Goals of the Test

We want three things:

  1. Low false accusation rate – If a player uses a fair coin, we want a low chance of wrongly accusing them.

  2. High detection rate – If a player is cheating, we want a high chance of catching them.

  3. Minimal flips – Use the smallest number of coin flips possible (to save detective resources and avoid bothering players).

Probability Basics: Independence and Multiplication

  • Coin flips are independent – the outcome of one flip does not affect the next.

  • For a fair coin (probability of heads = 0.50.50.5), the probability of a specific sequence of nnn flips is (0.5)n(0.5)^n(0.5)n.

  • Example: The probability of 5 heads in a row with a fair coin is:

    P(5 heads)=(12)5=132=0.03125 (3.125%)P(5 \text{ heads}) = \left(\frac{1}{2}\right)^5 = \frac{1}{32} = 0.03125 \ (3.125\%)P(5 heads)=(21​)5=321​=0.03125 (3.125%)

Setting the False Positive Rate Threshold

  • We must decide how often we are willing to falsely accuse a fair player.

  • Standard choice: 5% (i.e., 1 false accusation out of every 20 fair players). This is often called the significance level (α\alphaα).

  • With 5 flips, accusing only when all 5 are heads gives a false positive rate of 3.125% – below the 5% threshold.

Evaluating the Test: True/False Positives and Negatives

When we apply a test, the result may or may not match reality. The terminology:

  • True Negative (TN): Fair player, test says fair (correct).

  • False Positive (FP): Fair player, test says cheater (incorrect accusation).

  • True Positive (TP): Cheater, test says cheater (correct catch).

  • False Negative (FN): Cheater, test says fair (missed cheater).

False Positive Rate = FPFair players\frac{\text{FP}}{\text{Fair players}}Fair playersFP​ (out of all fair players, how many are wrongly accused). It is not the fraction of positive results that are false.

Goal 1 is to keep the false positive rate low (e.g., below 5%).

Statistical Power (True Positive Rate) and Effect Size

Goal 2: Catch a high fraction of cheaters. A standard target is 80% – called the statistical power of the test.

To calculate the true positive rate, we need to know how much the unfair coin favors heads. This is the effect size – the difference between the fair and unfair coin probabilities. It is an assumption we must make.

  • Example assumption: Cheater coin lands heads 75% of the time.

  • Probability of 5 heads in a row with this coin:

    P(5 heads∣cheater)=0.755≈0.237 (23.7%)P(5 \text{ heads} \mid \text{cheater}) = 0.75^5 \approx 0.237 \ (23.7\%)P(5 heads∣cheater)=0.755≈0.237 (23.7%)
  • With the test “accuse if 5 heads,” we catch only ~24% of cheaters – well below the 80% goal.

The choice of effect size (75% heads) is an assumption. Changing it changes the test’s performance.

Using More Flips: The Binomial Distribution

  • With only 5 flips, we cannot simultaneously achieve a 5% false positive rate and 80% power because the two distributions (fair vs. cheater) overlap heavily.

  • To get a test that allows a mixture of heads and tails, we need more flips and the binomial distribution to calculate probabilities for any number of heads.

  • The binomial distribution gives the probability of observing exactly kkk heads in nnn independent flips, each with probability ppp of heads:

    P(k heads)=(nk)pk(1−p)n−kP(k \text{ heads}) = \binom{n}{k} p^k (1-p)^{n-k}P(k heads)=(kn​)pk(1−p)n−k

    (A full derivation is outside the scope; the key is that this formula allows us to compute the bars in the graphs shown.)

  • By increasing nnn, the two distributions (fair vs. cheater) become more separated, making it easier to find a threshold that satisfies both goals.

Designing the Test: Finding the Right Threshold and Sample Size

  • Starting with 5 flips, we can try increasing the number of flips and adjusting the threshold until both goals are met.

  • The smallest test that achieves <5% false positive rate and >80% power (assuming cheater coin p=0.75p=0.75p=0.75) is:

Test: Flip the coin 23 times. Accuse the player of cheating if they get 16 or more heads. Otherwise, call them fair.

  • False positive rate with this test: ~4.56% (below 5%).

  • True positive rate (power): ~81.5% (above 80%).

Understanding P-values

  • P-value: Assuming the player is innocent (fair coin), the probability of observing a result as extreme or more extreme than the one obtained.

  • For 17 heads out of 23 with a fair coin:

    P(17 or more heads∣fair)≈0.017 (1.7%)P(17 \text{ or more heads} \mid \text{fair}) \approx 0.017 \ (1.7\%)P(17 or more heads∣fair)≈0.017 (1.7%)
  • For 13 heads out of 23:

    P(13 or more heads∣fair)≈0.34 (34%)P(13 \text{ or more heads} \mid \text{fair}) \approx 0.34 \ (34\%)P(13 or more heads∣fair)≈0.34 (34%)

The P-value is a measure of evidence against the assumption of innocence. A small P-value (below the threshold) leads to a positive test result.

Trade-offs: Adjusting the Goals

The thresholds (5% false positive, 80% power) are not fixed – we can adjust them based on the situation. Changing one affects the others.

  • Example: Lower the false positive rate to 1%. With 23 flips, the heads threshold must rise to 18 heads. Power drops to about 47%.

  • To maintain 80% power with a 1% false positive rate, we would need more flips (e.g., 80 flips for a 99% power and 1% false positive? Actually the text says 80 flips to get 99% true positive and 1% false positive – but the concept is the same: more flips allow tighter separation).

We can always set two of the three goals (false positive rate, power, number of flips) but the third is determined by the trade-off.

The Danger of Incorrect Assumptions

  • In the earlier design, we assumed cheaters use a coin with 75% heads. But what if real cheaters use a coin with only 60% heads?

  • With the same test (23 flips, threshold 16 heads), the test still falsely accuses fewer than 5% of fair players.

  • However, the true positive rate drops dramatically – only about 25% of cheaters are caught (because the effect size is smaller).

  • To achieve 80% power for a 60% heads coin, we would need 158 flips and a threshold of 90 heads – much more data.

Key lesson: Assumptions about effect size are critical. Forgetting that an assumption is just an assumption can lead to a test that fails in practice.

Summary: Frequentist Hypothesis Testing Framework

This entire process is called frequentist hypothesis testing. The steps:

  1. Ask a yes/no question (e.g., “Is this player using a biased coin?”).

  2. Build a model for what results to expect if the answer is “yes” (cheater) and if the answer is “no” (fair).

  3. Design a test that can distinguish between the two models, with a preset maximum acceptable false positive rate (significance level) and a desired minimum true positive rate (power).

  4. Collect data and compute the P-value.

  5. Make a decision: If the P-value is less than the significance level, declare a positive result (reject the null hypothesis of innocence). Otherwise, declare a negative result.

This framework is the foundation of most scientific studies. There is an alternative approach called Bayesian hypothesis testing which is covered in a subsequent lesson.

Frequentist hypothesis testing does not give certainty – it controls the long-run error rates. The test’s performance depends on correctly specifying the models (especially the effect size).

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent