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

    Only the boxes for your choice appear

    Form progress0 / 1 fields

    💡 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

    1
    Do you have counts of people or items?
    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.
    2
    Do you already know P(A and B) and P(B)?
    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.
    3
    Do you know the reverse probability, P(B | A)?
    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.
    4
    Is it a test with a sensitivity and a specificity?
    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

    1. What do you want to calculate - one of the six modes. Only the boxes for that mode appear.
    2. Table of counts - four whole numbers: A and B, A without B, B without A, and neither. Zeros count; leave no box empty.
    3. P(A and B) and P(B) - for the formula mode, with P(A) as an optional third box.
    4. 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.
    5. 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.
    6. Prevalence, sensitivity, specificity - for the diagnostic test, usually as percentages such as 1%, 99%, 95%.
    7. 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 questionamong sporty people, how many are students?among students, how many play a sport?decide which group you are standing in
    Denominatorall B: 40all A: 50the known event goes below the line
    Result30/40 = 3/430/50 = 3/5same overlap, different base
    In a medical testP(sick | positive), the PPVP(positive | sick), the sensitivitythe patient wants the first, the leaflet prints the second
    Verdictequal only when P(A) = P(B); the bridge between them is Bayes' theoremnever 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

    definition: P(A | B) = P(A and B) / P(B)
    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)
    Flipping a condition. Thirty percent of a store's visitors come from ads, 80% of them add something to the cart, and half of all visitors do. Then P(ad | cart) = 0.8 × 0.3 / 0.5 = 0.48. The same inputs imply that 13/35, about 0.3714, of the other visitors fill a cart.
    Two urns. A coin picks the urn: urn I holds 3 white balls in 10, urn II holds 4 in 10. P(white) = 1/2 × 3/10 + 1/2 × 2/5 = 7/20. A white ball came out, so it came from urn I with probability (3/20) / (7/20) = 3/7 and from urn II with 4/7.
    Three machines. They make 50%, 30% and 20% of the parts, with defect rates of 2%, 3% and 5%. Defects overall: 29/1000, or 2.90%. A defective part came from machine I with probability 10/29, from II with 9/29 and from III with 10/29: the smallest machine shares the blame equally with the largest.

    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%9949516.67%99.99%
    10%, 99%, 95%99045068.75%99.88%
    1%, 99%, 99.9%991090.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

    Mistake: reading the sensitivity as the chance of being sick. Instead: sensitivity is P(positive | sick). In the first screening row that is 99%, while P(sick | positive) is 16.67%.
    Mistake: multiplying P(A) by P(B) to get the overlap. Instead: P(A and B) = P(A) × P(B) only for independent events. In general P(A and B) = P(B) × P(A | B).
    Mistake: priors that do not add up to 1. Instead: the hypotheses have to exclude each other and cover every case. A sum like 0.99996 from typing 33.33% is treated as rounding; a sum of 0.9 is refused, with the advice to leave the last prior empty.
    Mistake: rounding halfway through. Instead: keep fractions until the end. The calculator does, which is why 0.1 / 0.3 comes back as exactly 1/3.
    Mistake: an overlap bigger than one of the events. Instead: P(A and B) = 0.7 with P(B) = 0.5 is a data error, because the overlap lies inside B. The calculator stops and says which number clashes rather than returning a probability above 1.

    Conditional probability questions from homework and screening

    How do you find conditional probability from a two-way table?
    Take the count where both happened and divide it by the total of the condition you know. In the survey above that is 30 / 40 = 3/4. The calculator also returns the three other conditional probabilities from the same table.
    When is it Bayes' theorem rather than the plain definition?
    When you know P(B | A) and want P(A | B). The definition needs the overlap directly; Bayes builds it from P(A) × P(B | A). In the urn problem, total probability gives 7/20 for a white ball, and Bayes turns it around into 3/7 for urn I.
    How can I tell whether two events are independent?
    Compare P(A and B) with P(A) × P(B), or P(A | B) with P(A). On a fair die, "divisible by 3" and "even" give 1/6 = 1/3 × 1/2, so they are independent and P(A | B) = 1/3. In a table of real data exact equality is rare; a small gap there is a job for a significance test.
    What do LR+ and LR- add to sensitivity and specificity?
    They turn a result into a multiplier on the odds. LR+ = sensitivity / (1 - specificity), so 19.80 for 99% and 95%: a positive multiplies the prior odds by about twenty. LR- = (1 - sensitivity) / specificity, about 0.011 here, so a negative cuts the odds roughly ninety-fold.
    Can I type percentages and fractions in the same form?
    Yes. Every probability box reads 25%, 0.25 and 1/4 the same way. Use a dot for decimals; a comma is refused, because 0,25 and 1,000 mean different things in different countries. The table of counts takes whole numbers only.

    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

    Similar calculators from this section