Skip to content
BayesLab.Open the app →

Probability foundations

Bayes’ theorem, without the mystery

A detector flags a parcel. How likely is it that the parcel is actually faulty? The answer depends on more than the detector’s accuracy. Let’s calculate it, then build the model.

By the BayesLab team · Updated 18 September 2026 · 6 min read

The question behind the formula

Imagine a fictional packing line where 2% of parcels have a fault. A detector flags 90% of faulty parcels, but also flags 5% of sound ones. These are invented teaching values, not measurements from a real factory. We want the probability of a fault after seeing a flag—not the probability of a flag when a fault is already known.

That distinction matters. “The detector catches 90% of faults” describes its behaviour among faulty parcels. It does not say that 90% of flagged parcels are faulty. To answer the second question, we need to count both ways a flag can happen.

Count first, calculate second

Picture 10,000 parcels. At a 2% fault rate, 200 are faulty and 9,800 are sound. The detector flags 180 of the faulty parcels and 490 of the sound parcels. Of the 670 flags, only 180 correspond to a fault.

Expected counts in 10,000 fictional parcels
Actual conditionFlaggedNot flaggedTotal
Faulty18020200
Sound4909,3109,800
Total6709,33010,000

P(Fault | Flag) = 180 / 670 ≈ 26.87%

The detector has provided useful evidence: the chance rose from 2% to nearly 27%. But the large number of sound parcels still generates many false flags. This is the base-rate effect, not a contradiction.

Now give each part a name

The prior is P(Fault) = 0.02. The likelihood of this evidence under a fault is P(Flag | Fault) = 0.90. The total probability of a flag is 0.90 × 0.02 + 0.05 × 0.98 = 0.067. Dividing the joint probability of fault and flag by that total gives the posterior.

P(Fault | Flag) = (0.90 × 0.02) / (0.90 × 0.02 + 0.05 × 0.98)

Build the two-node network

In BayesLab, start a blank network. Use Chance node (C) to add variables and the States tab to name their outcomes. Use Connect (A) to link parent to child, then select each node’s Table tab to enter its probabilities. The tables below use percentages: enter values such as 20% explicitly. Match the state labels, not just the order of the rows. Set observations in the Evidence tab and clear them between experiments.

  1. Create Fault with states Faulty and Sound. Its prior is 2% / 98%.
  2. Create Detector with states Flag and Clear, and connect Fault → Detector.
  3. In Detector’s table, enter Flag/Clear = 90%/10% when Faulty and 5%/95% when Sound.
  4. Observe Detector = Flag. Faulty should show approximately 26.87%.
  5. Clear that evidence and observe Clear instead. Faulty should fall to about 0.214%: 20 of the 9,330 clear parcels.

What to write in your explanation

Describe the update in words before quoting the percentage: a flag is more likely under a fault, so it raises our belief in a fault, but flags also occur in sound parcels. Avoid saying that the observation changed the parcel. What changed is our information about it.

Next: learn how to organise larger tables in our CPT walkthrough.