calculator.onl
Categories50

Bayes’ theorem calculator

Update a binary hypothesis after a positive observation using a prior, sensitivity and specificity, then explore how changing the prior changes the posterior.

A worked example

Increase the detector’s specificity. What share of flagged parcels are false positives?

Posterior P(H | E) (%)30.7692Evidence P(E) (%)26Joint P(H ∩ E) (%)8Joint P(¬H ∩ E) (%)18
%
Prior P(H) (%) · 0 … 100

%
P(E | H) (%) · 0 … 100

%
Specificity P(¬E | ¬H) (%) · 0 … 100

Updates as you type

Use a dot or comma for decimals. No thousands separators.

YOUR RESULT

Posterior P(H | E) (%)

30.7692

Calculated from your inputs

Evidence P(E) (%)26
Joint P(H ∩ E) (%)8
Joint P(¬H ∩ E) (%)18
The numbers, at a glance

Calculations run in your browser.
UNDERSTAND THE RESULT

A little context. A clearer answer.

↑ Back to calculator

When this calculator is useful

Two groups with different starting probabilities can get different updated probabilities from the same test characteristics. Change “Prior P(H)” from 10% to 1% and keep the other inputs from the worked example. The value for “Posterior P(H | E) (%)” goes from 30.7692 to 3.8835. For a related calculation, try Two-event probability calculator.

A parcel bears a printed mark. You know how often each production line prints this mark and what fraction of all parcels its line supplies. To infer the source of the parcel, imagine collecting every marked parcel in one basket. The question is what share of that basket came from the line you are investigating. This also explains why a mark can be characteristic of a line yet many marked parcels can come from somewhere else.

Call the proposed source H and the observed mark E. The first field gives P(H), the share from that source before looking at the mark. The next field measures sensitivity, the frequency of E within H. The last field gives specificity, the frequency of an absent mark outside H. Subtract specificity from one hundred percent to obtain the mark rate in that second group. The first group contains parcels from H and the second contains every other parcel. Both rates must describe the same observation, measured in the same way. A mark missing from a torn label may need a separate category if missing labels were excluded when the rates were measured.

Multiply the prior by the evidence rate inside H to get the fraction of all parcels that both satisfy H and carry the mark. Multiply the complementary prior by the other evidence rate to get the fraction from elsewhere that also carry the mark. Their sum is the share marked in the entire population. Dividing the first contribution by the sum gives the requested conditional probability. The two joint outputs retain the original population as their denominator, which makes them useful for checking the arithmetic.

An easy way to test your inputs is to work with a batch of one thousand. With a ten percent prior there are one hundred items from H. At an eighty percent mark rate, eighty enter the basket. Of the other nine hundred items, a twenty percent rate supplies another one hundred and eighty. The mark has raised the chance of H from ten percent to a little over thirty percent. Even though it is four times as frequent within H, the larger second group supplies more marked items in total.

Use the curve to investigate uncertainty in the prior while holding both evidence rates fixed. Each horizontal position represents a different population mix. Reading vertically gives the share from H among items showing the mark in that mix. A point above its corresponding prior value indicates that observing E raises the chance of H. If the two evidence rates agree and are positive, the curve follows the diagonal. A starting probability near zero can produce a small posterior even with quite informative evidence.

When moving between populations, check whether the observed evidence rates transfer along with the prior. A change of inspection equipment could affect both rates. If you have several competing suppliers, the input for the group outside H must average their rates using their relative volumes. It can change as their mix changes, even when each supplier behaves consistently. Keep records of which observation and population supplied each number when comparing runs. The result describes your stated combination of assumptions and can be recomputed directly from the two joint contributions.

What to enter

InputWhat it meansExample value
Prior P(H)Prior P(H) (%) · 0 … 10010 %
P(E | H)P(E | H) (%) · 0 … 10080 %
Specificity P(¬E | ¬H)Specificity P(¬E | ¬H) (%) · 0 … 10080 %

How the calculation works

  1. Update a binary hypothesis after a positive observation using a prior, sensitivity and specificity, then explore how changing the prior changes the posterior.
  2. P(H|+) = p·Se / [p·Se + (1−p)·(1−Sp)]
  3. In a batch of 1,000 parcels, 100 come from line H. A mark appears on 80 of those parcels and on 180 of the other 900. Among all 260 marked parcels, the share from line H is 80/260, or about 30.77%.
The formulaP(H|+) = p·Se / [p·Se + (1−p)·(1−Sp)]

A worked example

In a batch of 1,000 parcels, 100 come from line H. A mark appears on 80 of those parcels and on 180 of the other 900. Among all 260 marked parcels, the share from line H is 80/260, or about 30.77%.

Example you can load

What to enter
Result for this example · Posterior P(H | E) (%)30.7692

This is a fixed example; changing the form above does not change these numbers.

Worked comparisons

Start with these reference inputs — Prior P(H) = 10 %, P(E | H) = 80 %, Specificity P(¬E | ¬H) = 80 %. The corresponding results, in the order shown on the form, are — Posterior P(H | E) (%) = 30.76923, Evidence P(E) (%) = 26, Joint P(H ∩ E) (%) = 8, Joint P(¬H ∩ E) (%) = 18. Each example starts again from the reference inputs. The arrows show exactly which entries to change. All other entries keep their original values.

Case 1. Change one setting or the indicated combination to reproduce this case — Prior P(H) 10 % → 1 %, P(E | H) 80 % → 80 %, Specificity P(¬E | ¬H) 80 % → 80 %. Read the following results — Posterior P(H | E) (%) = 3.883495, Evidence P(E) (%) = 20.6, Joint P(H ∩ E) (%) = 0.8, Joint P(¬H ∩ E) (%) = 19.8.

Case 2. For the second comparison, restore the reference settings first, then enter — Prior P(H) 10 % → 50 %, P(E | H) 80 % → 80 %, Specificity P(¬E | ¬H) 80 % → 80 %. Compare the new answers with the reference result above — Posterior P(H | E) (%) = 80, Evidence P(E) (%) = 50, Joint P(H ∩ E) (%) = 40, Joint P(¬H ∩ E) (%) = 10.

Case 3. For a third check use the following changes — Prior P(H) 10 % → 10 %, P(E | H) 80 % → 20 %, Specificity P(¬E | ¬H) 80 % → 80 %. The calculation now gives — Posterior P(H | E) (%) = 10, Evidence P(E) (%) = 20, Joint P(H ∩ E) (%) = 2, Joint P(¬H ∩ E) (%) = 18.

Case 4. For the last case enter — Prior P(H) 10 % → 10 %, P(E | H) 80 % → 80 %, Specificity P(¬E | ¬H) 80 % → 100 %. Read across the outputs to see which quantities changed and which stayed fixed — Posterior P(H | E) (%) = 100, Evidence P(E) (%) = 8, Joint P(H ∩ E) (%) = 8, Joint P(¬H ∩ E) (%) = 0.

Assumptions & limits

Use rates measured in the relevant population.

Reference ·

Frequently asked questions

What specificity belongs in the last field?

Enter the chance that the mark is absent when H is false. Specificity of 95% corresponds to a mark rate of 5% in that group.

What if both groups show the evidence equally often?

Equal positive evidence rates leave the prior unchanged. If both rates are zero, conditioning on that evidence is undefined.

May I enter a posterior as a new prior?

Yes, if the new likelihoods describe the next observation conditional on the earlier evidence as well. Reusing the first observation would count it twice.