What is P(A | B) when you only know P(B | A)? Six modes cover two-way tables, the definition, Bayes' theorem, two or three hypotheses and diagnostic tests, all in exact fractions.
Conditional Probability Calculator - Bayes' Theorem and PPV
What is P(A | B) when you only know P(B | A)? Six modes cover two-way tables, the definition, Bayes' theorem, two or three hypotheses and diagnostic tests, all in exact fractions.
Parameters
Enter data for calculations
💡 Fill in all required fields to unlock the calculate button
Conditional probability, Bayes' theorem and test accuracy, in exact fractions
A screening test that catches 99% of cases and clears 95% of healthy people sounds close to certain. Run it on a group where 1% have the condition and only 16.67% of the positive results are real. That gap between P(positive | sick) and P(sick | positive) is what this conditional probability calculator is built around. It takes a 2 × 2 table of counts, the definition P(A and B) / P(B), Bayes' theorem with P(B | A), total probability over two or three hypotheses, or a test's sensitivity and specificity. You can type 1/3, 0.25 or 25%, and the answer comes back as a reduced fraction next to its decimal, because the arithmetic is done on exact fractions and rounded only at the end.
Which of the six modes fits your problem
A survey, a class list, a crosstab from a spreadsheet. Pick the table of counts and type the four cells. Everything else, the margins included, is filled in for you.
That is the textbook definition, and the formula mode divides one by the other. Add P(A) if you also want P(B | A), P(A or B) and an independence check.
Then you need Bayes' theorem. With two outcomes use the Bayes' theorem mode; with two or three competing explanations (urns, machines, suppliers) use a hypotheses mode.
Medical screening, a spam filter, a fraud rule. The diagnostic test mode adds the prevalence and returns PPV, NPV, both likelihood ratios and the effect of a second positive result.
Entering the numbers, mode by mode
- What do you want to calculate - one of the six modes. Only the boxes for that mode appear.
- Table of counts - four whole numbers: A and B, A without B, B without A, and neither. Zeros count; leave no box empty.
- P(A and B) and P(B) - for the formula mode, with P(A) as an optional third box.
- P(A) and P(B | A) - for Bayes' theorem, plus one of P(B | not A) or P(B). If you fill in both, they are checked against each other.
- P(H) and P(E | H) for each hypothesis - the prior and the chance of the evidence under it. The last prior may stay empty and is then taken as 1 minus the others.
- Prevalence, sensitivity, specificity - for the diagnostic test, usually as percentages such as 1%, 99%, 95%.
- Read the result: the headline probability, the tiles with the related probabilities, and the table with every intermediate step.
P(A | B) or P(B | A): the swap behind most wrong answers
Take a survey of 100 people: 30 are students who play a sport (A and B), 20 are students who do not, 10 play a sport but are not students, 40 are neither. The two conditional probabilities come out far apart, and the table shows why.
| Parameter | P(A | B) | P(B | A) | Who needs it |
|---|---|---|---|
| The question | among sporty people, how many are students? | among students, how many play a sport? | decide which group you are standing in |
| Denominator | all B: 40 | all A: 50 | the known event goes below the line |
| Result | 30/40 = 3/4 | 30/50 = 3/5 | same overlap, different base |
| In a medical test | P(sick | positive), the PPV | P(positive | sick), the sensitivity | the patient wants the first, the leaflet prints the second |
| Verdict | equal only when P(A) = P(B); the bridge between them is Bayes' theorem | never swap them silently | |
Without any condition, P(A) = 1/2. With B known it rises to 3/4, and without B it falls to 1/3, so the two events are dependent in this survey. Whether a gap like that would survive in a new sample is a separate question, which Fisher's exact test or a chi-square test answers.
Three formulas and the textbook problems they solve
total probability: P(E) = P(H1) P(E | H1) + P(H2) P(E | H2) + ...
Bayes: P(H1 | E) = P(H1) P(E | H1) / P(E), and in two-event form P(A | B) = P(B | A) P(A) / P(B)
One test, three screening settings
The same arithmetic, per 10,000 people tested. Sensitivity and specificity describe the test; the positive predictive value also depends on how common the condition is in the group being tested. These are illustrative numbers, not the figures of any particular product.
| Prevalence, sensitivity, specificity | True positives | False positives | PPV | NPV |
|---|---|---|---|---|
| 1%, 99%, 95% | 99 | 495 | 16.67% | 99.99% |
| 10%, 99%, 95% | 990 | 450 | 68.75% | 99.88% |
| 1%, 99%, 99.9% | 99 | 10 | 90.91% | 99.99% |
In the first row the test produces 594 positives, and 99 of them are real. Raising the specificity from 95% to 99.9% cuts the false alarms from 495 to 10, which moves the PPV more than any improvement in sensitivity could. For the first row the likelihood ratio LR+ is 0.99 / 0.05 = 19.80, and if a second, independent test also comes back positive the chance rises to 79.84%. That second figure assumes the two tests make their mistakes independently, which a repeat of the same test on the same sample often does not.
Five mistakes that flip the answer
Conditional probability questions from homework and screening
Related tools
Modulo Calculator
Remainders and divisibility, the arithmetic behind counting outcomes in cycles - See calculator
Binomial Expansion Calculator
C(n, k) and the binomial coefficients behind repeated-trial probabilities, exact at any size - See calculator
Probability Calculator
Single events, independent events, the union of two events and repeated trials - See calculator
Fisher's Exact Test Calculator
Whether the association in a small 2 × 2 table is more than chance - See calculator
Chi-Square Calculator
Independence tests for larger tables of counts and goodness of fit - See calculator
Confidence Interval Calculator
The uncertainty around a sensitivity or a prevalence measured on a sample - See calculator
Combinations & Permutations Calculator
Counting the outcomes behind a classical probability - See calculator
Z-Test Calculator
Comparing two rates, such as the positive share in two groups - See calculator