PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabsLessons
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry📊Statistics & Probability
ENRUESPTFRDE

Related simulators

Continue with similar topics in this category — or all 10 in Statistics & Probability.

View category →
NewFeaturedKids

Central Limit Theorem

Launch Simulator

Pick a parent (uniform, exponential, binomial, die), draw samples of size n = 1, 5, 30; the histogram of means turns normal and its spread shrinks as σ/√n.

NewFeaturedKids

Galton Board (Bean Machine)

Launch Simulator

Balls bounce left/right through rows of pegs; the bins fill a binomial that turns into a bell curve. Few rows vs many rows.

NewKids

Law of Large Numbers

Launch Simulator

Coin or die: running mean x̄ₙ for several runs converges to μ; the ±σ/√n envelope shows how slowly.

NewSchool

p-Value Explained

Launch Simulator

Test statistic on the null density; shaded one- or two-sided tail is the p-value. Why it is not the probability that H₀ is true.

NewKids

Binomial Distribution

Launch Simulator

P(K = k) bars for n trials with success p; mean np, variance np(1−p); coin and rare-event presets; normal overlay at large n.

NewKids

Normal Distribution & z-Scores

Launch Simulator

Bell curve with μ and σ; shaded tails, the 68–95–99.7 rule, and a built-in z-score converter x → z = (x − μ)/σ.

PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry
  • Statistics & Probability

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Statistics & Probability/Bayes' Theorem: Medical Test Paradox

Bayes' Theorem: Medical Test Paradox

Sensitivity, specificity and prevalence on a 2×2 population grid; why a positive test can still mean a low chance of disease.

Disease and test

1%
99 %
95 %

Presets

Population grid

Population size

The grid is a natural-frequency picture (Gigerenzer): each square is one person, and the expected numbers in the four cells are N·prev·sens, N·prev·(1−sens), N·(1−prev)·(1−spec) and N·(1−prev)·spec, rounded to whole people by the largest-remainder rule so that they add up to N. It is not a random draw — sampling scatter is deliberately left out so that the counts match the probabilities exactly up to rounding. P(D | +) is read directly as true positives divided by all positives: Bayes’ theorem without the formula.

Shortcuts

  • •Space / Enter — show only positives on / off
  • •R — reset

Measured values

Prevalence P(D)1%
Sensitivity P(+ | D)99%
Specificity P(− | ¬D)95%
False-positive rate 1 − spec5%
True positives TP99
False positives FP495
False negatives FN1
True negatives TN9 405
Share testing positive P(+)5.94%
PPV = P(D | +)16.7%
NPV = P(¬D | −)99.989%

P(D|+) = 0.99·0.01 / (0.99·0.01 + 0.05·0.99) = 0.0099 / 0.0594 = 0.1667

Counts in brackets are the exact expected values before rounding to whole people.

About this model

The simulator models a diagnostic test applied to every member of a population of N people (1 000 or 10 000). Three numbers describe the situation: the prevalence P(D), the fraction of the population that has the disease; the sensitivity P(+ | D), the probability that a sick person tests positive; and the specificity P(− | ¬D), the probability that a healthy person tests negative. From these the four cells of the 2×2 table follow directly: true positives N·P(D)·sens, false negatives N·P(D)·(1 − sens), false positives N·(1 − P(D))·(1 − spec) and true negatives N·(1 − P(D))·spec. The grid draws each person as one square in one of these four classes. It is a natural-frequency representation in the sense of Gigerenzer and Hoffrage: instead of multiplying conditional probabilities, the pupil counts people, and the quantity that matters to a patient, the positive predictive value P(D | +), is read off as TP / (TP + FP). This is Bayes' theorem without the formula; written out it is P(D | +) = sens·P(D) / [sens·P(D) + (1 − spec)·(1 − P(D))], and the readout prints exactly this line with the current numbers substituted. The negative predictive value P(¬D | −) = TN / (TN + FN) is shown as well. The central lesson is that P(D | +) depends on the prevalence as much as on the accuracy of the test: with the default values (1 %, 99 %, 95 %) 99 of 100 sick people test positive, but so do 495 of the 9 900 healthy ones, so only about one positive in six is actually sick. The 'Second test' option retests the first-round positives with the same test, treating the first posterior as the new prior, and shows P(D | ++) under the assumption that the two results are conditionally independent given the disease status. Simplifications: the counts are expected values rounded to whole people by the largest-remainder rule (the exact values are listed beside them), not a random sample, so sampling scatter is absent; sensitivity and specificity are treated as exact and constant across the population; repeated tests are assumed independent, which real tests often are not. Companion simulators: math/bayesian-updating-conjugate-priors continues the same idea with continuous parameters and repeated evidence; statistics/binomial-distribution and statistics/p-value show the frequentist side of the same conditional probabilities; statistics/type-i-ii-errors-power treats the false-positive rate as the significance level α and the sensitivity as power.

Who it's for: Upper secondary school (grades 10–12) probability units and introductory statistics or health-science courses; no calculus required.

Key terms

  • prevalence (base rate)
  • sensitivity P(+ | D)
  • specificity P(− | ¬D)
  • false-positive rate 1 − spec
  • positive predictive value P(D | +)
  • negative predictive value P(¬D | −)
  • natural frequencies
  • Bayes' theorem

How it works

A population of N people is split by prevalence into sick and healthy, and each group is split again by the test: the sick test positive with probability equal to the sensitivity, the healthy test negative with probability equal to the specificity. The grid shows the four resulting groups as natural frequencies (Gigerenzer): counting squares replaces the formula, because the probability of disease given a positive test, P(D | +), is simply the true positives divided by all positives. That ratio depends on the prevalence as much as on the accuracy of the test — at 1 % prevalence a test with 99 % sensitivity and 95 % specificity leaves only about one positive in six actually sick, since the 5 % false-positive rate acts on the much larger healthy group. This is Bayes’ theorem without the formula; the second test shows how the posterior becomes the new prior and the probability climbs. Counts are expected values rounded to whole people, not a random sample.

Key equations

P(D|+) = P(+|D)·P(D) / [P(+|D)·P(D) + P(+|¬D)·P(¬D)] = sens·prev / (sens·prev + (1−spec)·(1−prev))
P(D|+) = TP / (TP + FP), P(¬D|−) = TN / (TN + FN)
P(+|¬D) = 1 − specificity, P(−|D) = 1 − sensitivity
P(D|++) = sens·P(D|+) / [sens·P(D|+) + (1−spec)·(1−P(D|+))] (independent repeat test)

Frequently asked questions

The test is 99 % accurate, so why is my chance of being sick after a positive result only about 17 %?
Because the two kinds of error act on groups of very different size. With 1 % prevalence in 10 000 people there are 100 sick and 9 900 healthy. The test catches 99 of the 100 sick (true positives) but also mislabels 5 % of the healthy, which is 495 people (false positives). Among the 594 positives only 99 are sick, so P(D | +) = 99/594 ≈ 0.167. The '99 % accurate' figure describes the test on sick people; it says nothing about how many healthy people there are to generate false alarms, and that number is set by the prevalence.
Which matters more for P(D | +): raising the sensitivity or raising the specificity?
For a rare disease the specificity matters far more. Sensitivity multiplies the small sick group, so going from 99 % to 100 % adds at most one true positive per hundred sick people. Specificity controls the false-positive rate 1 − spec, which multiplies the large healthy group: moving from 95 % to 99 % cuts the false positives in the default example from 495 to 99, and P(D | +) rises from about 17 % to 50 %. With perfect specificity there are no false positives at all and every positive is a true positive, whatever the prevalence. For a common condition (30 % prevalence) the two groups are comparable in size and sensitivity regains its importance.
Why does a second positive test change the probability so much?
After the first positive the prior is no longer 1 % but 16.7 %, and Bayes' theorem is applied again with this new prior. Among the 594 first-round positives there are 99 sick and 495 healthy; a second independent test flags about 98 of the sick and only about 25 of the healthy, so P(D | ++) ≈ 98/123 ≈ 0.80. In odds form each positive result multiplies the odds of disease by the same likelihood ratio sens/(1 − spec) = 0.99/0.05 ≈ 20: the odds go from 1 : 99 to about 1 : 5 and then to about 4 : 1. This assumes the second result is independent of the first given the disease status; if the same cause produces a false positive both times, the gain is smaller.
Is a negative result as misleading as a positive one?
Usually not, for the same reason in reverse. The negative predictive value P(¬D | −) = TN / (TN + FN) compares the healthy people who test negative (9 405 in the default example) with the sick who are missed (1). That gives 99.99 %, so a negative result is very reassuring when the disease is rare and the sensitivity is high. The picture changes for a common condition: with 30 % prevalence and 90 % sensitivity, 300 of the 3 000 sick people in a group of 10 000 test negative and sit among 6 300 true negatives, so P(¬D | −) drops to about 95.5 % and a negative result no longer rules the disease out.