Tabellab

Bayes' Theorem: A Diagnostic Test and the Base Rate

Lesson 1 of 20Lab

All lessons

You are not signed in — the lab works, but your progress is not saved. Sign up

Lesson 1 of 20 is free. Unlock all 20 hands-on labs, the final exam and your certificate.

Buy course — $9.90
Loading the spreadsheet…

A positive test is not the same as a positive answer

A quality test flags a batch. A fraud model flags a payment. A spam filter flags an email. A screening test comes back positive. In each case the people involved want to know one thing: given this alarm, how likely is it that something is really wrong? The surprising answer is that it depends heavily on something the test itself does not know: how common the problem was in the first place. Bayes' theorem is the tool that combines the two, and it is the foundation of every Bayesian method, from simple updating to the A/B tests at the end of this course.

This free lesson is for analysts, quality and operations managers, product and marketing people who run experiments, and students meeting conditional probability for the first time. You do not need any statistics background beyond percentages. Everything happens in a small Excel table with four inputs, and the calculation takes four formulas.

We follow Juniper Lane, a fictional online plant shop. Every incoming nursery batch gets a quick root-rot test before the plants go on sale. According to the lab sheet, the test catches 92% of rotten batches and clears 95% of healthy ones. Across all suppliers, 2% of batches are rotten. One supplier with past problems delivers rotten batches 15% of the time. The warehouse team wants to know what a positive test means in each case. The lab above uses exactly these numbers, which are invented for teaching.

The core idea: turning the question around

A test is described by what happens given the truth. Sensitivity is P(+ | rot), the probability of a positive result if the batch really is rotten (here 92%). Specificity is P(− | healthy), the probability of a negative result if the batch is healthy (here 95%). Its complement, 1 − specificity = 5%, is the false-positive rate: one healthy batch in twenty sets off an alarm.

The warehouse, however, sees the test result, not the truth. Its question runs the other way: P(rot | +), the probability that a batch is rotten given that it tested positive. This is called the positive predictive value. Confusing the two directions is one of the most common reasoning errors in statistics, and it has a name: the base-rate fallacy. A 92% sensitive test does not mean that 92% of positives are real.

Bayes' theorem connects the two directions:

P(rot | +) = P(+ | rot) × P(rot) / P(+)

The new ingredient is P(rot), the base rate or prior: what you believe about a batch before you see the test result. The denominator P(+) is the overall probability of a positive test, and it comes from the law of total probability: a positive can come from a rotten batch (true positive) or from a healthy one (false positive).

P(+) = P(+ | rot) × P(rot) + P(+ | healthy) × P(healthy) = sensitivity × base rate + (1 − specificity) × (1 − base rate)

The same reasoning gives the negative predictive value, the probability that a batch with a negative test really is healthy: P(healthy | −) = specificity × (1 − base rate) / (1 − P(+)). Together, the two predictive values answer the questions people actually ask after a test.

Think in natural frequencies first

Probabilities with vertical bars are hard to feel. Research on risk communication has repeatedly found that people reason far better with natural frequencies: counts out of a fixed group. So imagine 1,000 batches arriving at Juniper Lane:

1,000batches tested20 rottenbase rate 2%980 healthy98% of batches18.4 positive92% are caught1.6 negative8% are missed49 positive5% false alarms931 negative95% clearedAll positive tests18.4 + 49 = 67.4Truly rotten18.4 ÷ 67.4= 27.3%
Natural frequency tree for 1,000 batches from all suppliers. Most positive tests (49 of 67.4) come from the large healthy group, so only about one positive in four is really rotten.

Of the 1,000 batches, 2% or 20 are rotten. The test catches 92% of them: 18.4 true positives (on average; fractions are fine for expected counts). The other 980 batches are healthy, and 5% of them, 49 batches, test positive anyway. So there are 18.4 + 49 = 67.4 positives in total, and only 18.4 of them are really rotten: 27.3%. A test that is right 92% and 95% of the time produces mostly false alarms, simply because healthy batches outnumber rotten ones by 49 to 1.

Worked example: two suppliers, one test

The lab sheet puts both situations side by side. Column B uses the base rate across all suppliers (2%); column C uses the supplier with past problems (15%). Sensitivity, specificity and the 1,000 batches per year are the same in both columns.

All suppliers (B)Supplier with past problems (C)Formula in column B
Base rate P(rot), row 22.0%15.0%input
P(+), row 76.74%18.05%=B2*B3+(1-B2)*(1-B4)
P(rot | +), row 827.3%76.5%=B2*B3/B7
P(healthy | −), row 999.83%98.54%=B4*(1-B2)/(1-B7)
False alarms per 1,000, row 1149.042.5=B10*(1-B2)*(1-B4)

The same test result means very different things. For a typical batch, a positive test raises the probability of rot from 2% to 27.3%: worth a closer look, but most of these batches are fine. For the problem supplier, a positive test raises it from 15% to 76.5%: now rot is the likely explanation. Negative results are reassuring in both cases (99.83% and 98.54% healthy), because the test misses only 8% of rotten batches and rotten batches are rare to begin with. Per 1,000 batches you should expect about 49 false alarms from the general flow and 42.5 from the problem supplier, which is useful for planning how many re-checks the warehouse must handle.

Bayes also has a compact odds form that becomes very handy in lesson 2. The prior odds of rot are 2 : 98 = 0.0204. The likelihood ratio of a positive test is sensitivity ÷ false-positive rate = 0.92 ÷ 0.05 = 18.4. Posterior odds = prior odds × likelihood ratio = 0.3755, and converting back gives 0.3755 ÷ (1 + 0.3755) = 27.3%, exactly the same answer.

Prior, likelihood, posterior: the vocabulary of the whole course

The diagnostic test is the simplest possible Bayesian model, and it already contains every idea you need later. The prior is the 2% (or 15%) you believe before the test. The likelihood is how probable the observed evidence is under each possible truth: 92% for a positive result if the batch is rotten, 5% if it is healthy. The posterior is the updated belief after the evidence: 27.3% (or 76.5%). Bayes' theorem is simply the rule that says posterior is proportional to prior times likelihood, divided by a normalising sum so that the probabilities add up to one.

In this lesson there are only two possible truths, rotten or healthy, so the "sum" in the denominator has two terms. In the grid approximation lesson there are ten possible purchase rates and the sum has ten terms. In the Beta-binomial lesson there are infinitely many, and a neat formula replaces the sum. The logic never changes, which is why it pays to understand this small example thoroughly before moving on.

Where do the three inputs come from?

In a real business the inputs are estimates, and it is worth knowing how they are usually obtained. Sensitivity and specificity come from a validation study: someone tests batches whose true state is known from a slower, more reliable method, for example cutting open the root balls, and counts how often the quick test agrees. Test manufacturers often publish these figures, but they may have been measured under conditions that differ from yours.

The base rate comes from your own history: how many batches turned out to be rotten over the last year, ideally split by supplier, season or product. This is where Bayes gets its practical power. The test stays the same, but the prior can be tailored to every situation you can measure, and the predictive value adjusts automatically. If you only have a rough idea of the base rate, calculate the result for a low, a middle and a high value and see whether the decision changes. Often it does not, and then the uncertainty does not matter.

Step by step: build the calculator in Excel

These steps rebuild the lab sheet from scratch, so you can reuse it for any test, alert or screening rule.

  1. Create an input block: labels in A2:A4 (base rate, sensitivity, specificity) and values in B2:B4. Type 2%, 92% and 95% directly; Excel stores them as 0.02, 0.92 and 0.95. Format them with Ctrl+Shift+% (Mac: Cmd+Shift+%).
  2. For a second scenario, put the other base rate in C2 (15%) and link the test properties with C3 =B3 and C4 =B4, so a change to the test updates both columns.
  3. In B7 calculate the probability of a positive test: =B2*B3+(1-B2)*(1-B4). The first product is the true positives, the second the false positives.
  4. In B8 apply Bayes' theorem: =B2*B3/B7. If you prefer one self-contained formula, use =B2*B3/(B2*B3+(1-B2)*(1-B4)).
  5. In B9 calculate the negative predictive value: =B4*(1-B2)/(1-B7).
  6. Put the yearly volume in B10 (1,000) and the expected false alarms in B11: =B10*(1-B2)*(1-B4).
  7. Select B7:C11 and press Ctrl+R (Mac: Cmd+R) to copy the formulas from column B to column C. Relative references make every formula in C point to its own base rate in C2.
  8. Format rows 7 to 9 as percentages with one or two decimals (Home › Number › Percent, then Increase Decimal) and row 11 as a number with one decimal.
  9. Audit with Ctrl+`: every formula in column C should refer to column C. Then sanity-check the result with natural frequencies, as in the tree above.
Turn the calculator into a quick sensitivity table: list base rates from 1% to 50% in a column and use =$B$3*A20/($B$3*A20+(1-$B$4)*(1-A20)) next to each one. A column chart of the result shows at a glance how strongly the base rate drives the answer, as in the chart below.

P(rot | positive) depends on the base rateSame test every time: sensitivity 92%, specificity 95%0%25%50%75%100%15.7%1%27.3%2%49.2%5%67.2%10%76.5%15%86.0%25%94.8%50%Base rate: share of batches that are rotten before testing
With sensitivity and specificity held constant, the probability that a positive batch is really rotten rises from 15.7% at a 1% base rate to 94.8% at 50%. Peach: all suppliers (2%). Lavender: the problem supplier (15%).

Bayesian statistics in Excel: priors, posteriors and Bayesian A/B tests
Bayesian statistics in Excel: from Bayes' theorem to posteriors, credible intervals and Bayesian A/B tests.

Common mistakes and how to spot them

  • Reading sensitivity as the answer. "The test is 92% accurate, so the batch is 92% likely to be rotten." Spot it: ask whether the number was measured on rotten batches (sensitivity) or on positive tests (predictive value).
  • Using specificity as the false-positive rate. The false-positive rate is 1 − specificity, here 5%, not 95%. Spot it: P(+) comes out larger than 90% even though rot is rare.
  • Forgetting the false positives in P(+). Using only B2*B3 as the denominator makes P(rot | +) equal to 100%. Spot it: a predictive value of exactly 1.
  • Ignoring the base rate. Applying one supplier's predictive value to another with a very different rot rate. Spot it: always keep the base rate visible next to the result.
  • Mixing percent and whole numbers. Typing 92 instead of 92% makes probabilities larger than 1. Spot it: any probability above 100% or a negative complement.
  • Absolute references in the wrong place. If B2 is locked as $B$2, column C repeats column B's answer. Spot it: identical results in B and C despite different base rates.

Quick reference: formulas and shortcuts used

Function, formula or shortcutWhat it does hereExample
Total probabilityP(+) from both groups that can test positive=B2*B3+(1-B2)*(1-B4)
Bayes' theoremTurns P(+ | rot) into P(rot | +)=B2*B3/B7
Complement 1 − xFalse-positive rate from specificity, P(healthy) from P(rot)=1-B4
Odds formPrior odds × likelihood ratio = posterior odds=B2/(1-B2)*B3/(1-B4)
Odds to probabilityConverts odds back to a probability=odds/(1+odds)
ROUNDRounds natural frequencies for a report=ROUND(B11,0)
Ctrl+Shift+%Percent format with no decimals (Mac: Cmd+Shift+%)Select B7:C9
Ctrl+RFills the formula of the left cell to the right (Mac: Cmd+R)Select B7:C11, press Ctrl+R
Ctrl+`Shows all formulas to audit both columns at onceCompare B8 with C8

Real-world uses

  • Quality control. Incoming-goods checks, machine sensors and visual inspections all have false alarms. Bayes tells you how many re-checks to staff and which suppliers deserve stricter testing.
  • Fraud and risk alerts. When genuine fraud is rare, even a good model flags far more legitimate transactions than fraudulent ones. The predictive value tells the review team what share of alerts are worth their time.
  • Email and content filters. Classic spam filters are built on Bayesian updating: each word in a message shifts the probability that it is spam, just like the several pieces of evidence in lesson 2.
  • Medical and health screening. Screening a broad population with a low prevalence produces many false positives, which is why follow-up tests exist. The same four-line calculation explains why. (This lesson is not medical advice.)
  • Lead scoring and churn prediction. A model that flags "likely to buy" or "likely to cancel" is only useful if you know how many of the flagged customers really convert or churn, given how common that outcome is.

What you will build in the rest of this course

Bayes' theorem with one test is the first step. The remaining 19 lessons are part of the paid course ($9.90 one-time). Each has its own interactive lab, and together they take you from a single update to a complete Bayesian A/B test with a decision rule, all in plain Excel without add-ins.

Updating Step by Step: Several Pieces of Evidence. You follow one suspicious batch through three pieces of evidence, using each posterior as the next prior, and then do it in one go with odds and likelihood ratios. It shows why Bayesian thinking is a process, not a one-off formula.

Grid Approximation: Prior × Likelihood ÷ Sum. You turn a team's guess about the add-on purchase rate into a posterior on a grid of 10 rates, with BINOM.DIST as the likelihood, and read off the posterior mean, the mode and the probability that the rate is at least 20%.

Beta-Binomial: The Conjugate Update and a Credible Interval. You update a Beta prior for the 90-day reorder rate with launch data by simply adding successes and failures to its two parameters, then compute the posterior mean, the standard deviation and a 95% credible interval.

Weak vs Strong Priors: How Much Does the Prior Matter? You feed the same 40 visitors into a flat and a strong prior, compare the posterior means and P(p > 20%), and chart both curves, so you can answer the "isn't the prior subjective?" question with numbers.

Bayesian A/B Test: The Probability That B Beats A. You turn a checkout test (A: 120 of 2,500, B: 150 of 2,500) into two Beta posteriors and estimate P(B > A), once with a normal approximation and once by counting posterior draws.

Expected Loss: A Decision Rule for Shipping B. You compute how much conversion you expect to lose by shipping B or by keeping A, and let an IF formula make the call against a threshold, the way many experimentation platforms decide.

Bayesian vs Frequentist: Same Data, Different Questions. You put a confidence interval and a one-sided p-value next to P(B > A) for the same test and learn which statement may honestly be read as "95% probability", a distinction that comes up in almost every stakeholder meeting.

Summary

Sensitivity and specificity describe a test given the truth. Decisions need the reverse, the probability of the truth given the test, and Bayes' theorem provides it by combining the test with the base rate. In Excel that is four formulas: P(+) by total probability, P(rot | +) by Bayes, P(healthy | −) by the same logic, and expected false alarms as a count. For Juniper Lane the identical test means a 27.3% chance of rot for a typical batch and 76.5% for the problem supplier.

Now scroll up to the lab and calculate P(+), both predictive values and the false alarms for both columns. The Coach checks every cell and tells you if a complement or a false-positive term is missing.

Frequently asked questions

How do I calculate Bayes' theorem in Excel?

Put the base rate, sensitivity and specificity in cells, calculate P(+) with =B2*B3+(1-B2)*(1-B4), then P(condition | +) with =B2*B3/B7. Format the results as percentages.

What is the difference between sensitivity and positive predictive value?

Sensitivity is the share of true cases that test positive, P(+ | condition). Positive predictive value is the share of positive tests that are true cases, P(condition | +), and it depends on the base rate.

Why does a rare condition produce so many false positives?

Because the healthy group is much larger. Even a small false-positive rate applied to a large group creates more false alarms than there are true cases, so most positives can be false.

What is the base rate fallacy?

It is the error of ignoring how common something is before the evidence, and judging only by how well the evidence fits. It leads people to overestimate the meaning of a positive test for rare conditions.

What is a prior in Bayesian statistics?

The prior is what you believe about a quantity before seeing new data, expressed as a probability or distribution. Bayes' theorem combines it with the likelihood of the data to give the posterior.

Can I use the odds form of Bayes' theorem in Excel?

Yes. Multiply the prior odds, =p/(1-p), by the likelihood ratio, =sensitivity/(1-specificity), and convert back with =odds/(1+odds). It gives the same result and makes several updates easy to chain.

Keep going: Bayesian Statistics in Excel: Priors, Posteriors & Bayesian A/B Tests

This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time $9.90.

  1. Updating Step by Step: Several Pieces of Evidence
  2. Grid Approximation: Prior × Likelihood ÷ Sum
  3. Beta-Binomial: The Conjugate Update and a Credible Interval
  4. Weak vs Strong Priors: How Much Does the Prior Matter?
  5. Bayesian A/B Test: The Probability That B Beats A
  6. Expected Loss: A Decision Rule for Shipping B
  7. Bayesian vs Frequentist: Same Data, Different Questions
  8. Exact Credible Intervals & Tail Probabilities with BETA.INV and BETA.DIST
  9. From an Expert's Guess to a Beta Prior: Moment Matching & a Prior Check
  10. Posterior Predictive: How Many of the Next 20 Buyers Will Reorder?
  11. Several Hypotheses at Once: Which Supplier Sent the Cracked Pot?
  12. Bayes Factors: Testing a Supplier's "Only 2% Cracked" Claim
  13. Gamma-Poisson: Updating a Rate of Damaged Deliveries per Day
  14. Updating an Average: Normal Prior, Normal Data & Precision Weights
  15. Empirical Bayes: Borrowing Strength Across 12 Plant Categories
  16. Watching the Posterior Day by Day: Cumulative Updates & a Credible Band
  17. Three Variants: Probability to Be Best & Expected Loss for Each
  18. Robust Priors: Mixing Past Campaigns with a Flat Prior
  19. Final Project: Bayesian Launch Dashboard for the Herb Garden Kit

Buy course — $9.90 See the full course