Conditional Probability Calculator
Work out the chance of one thing, given that you already know another. Use a table of any size, or probabilities you've been given. Check whether two events are independent, and try the Monty Hall problem, the two-children puzzle and Simpson's paradox. Every answer shows the working.
What are you working with?
Your table (type the names and counts)
This is what you already know. Only that row or column counts.
Made-up numbers for learning, not medical data.
Optional. Adds the full diagram and an independence check.
Type chances as 40%, 0.4 or 2/5.
One car, goats behind the rest. After you pick, the host opens all but one of the other doors.
Assumes boys and girls are equally likely and every day of the week is equally likely.
Successes out of total
Results update as you type. Press Calculate or Enter to save one to your recent list.
Your recent calculations
Practice questions
Five fresh questions each time, with worked answers. Teachers can print them as a worksheet with an answer key, or save it as a PDF from the print window.
What "given" means
P(A | B) is read "the probability of A, given B". It asks: once you know B has happened, how likely is A? Knowing B shrinks the group you're looking at to just the cases where B is true. The answer is the share of that smaller group where A is also true.
Take a survey of 100 people. 30 own a dog, and 18 of those dog owners also own a cat. Given that someone owns a dog, the chance they own a cat is 18 out of 30, which is 60%. The other 70 people don't come into it at all.
| Owns a cat | No cat | Total | |
|---|---|---|---|
| Owns a dog | 18 | 12 | 30 |
| No dog | 22 | 48 | 70 |
| Total | 40 | 60 | 100 |
Now reverse the question. Given that someone owns a cat, the chance they own a dog is 18 out of 40, which is 45%. Same 18 people, different bottom number, different answer. And the chance that someone owns both, out of everyone, is 18 out of 100: 18%. Three different questions, three different answers.
The rules, in plain words
Conditional probability
P(A | B) = P(A and B) / P(B)
The chance both happen, divided by the chance of what you're given. It only works if B can happen at all, so P(B) must be above 0.
The multiplication rule
P(A and B) = P(B) × P(A | B)
The same rule rearranged. If 40% of days are cloudy and it rains on 37.5% of cloudy days, it's cloudy and rainy on 0.4 × 0.375 = 15% of days.
The addition rule
P(A or B) = P(A) + P(B) − P(A and B)
Useful when you're given "or". Rearranged, it gives you the chance of both, and from there the conditional chance.
Independence
A and B are independent if P(A | B) = P(A)
Knowing B tells you nothing about A. In a deck of cards, 12 of 52 cards are face cards (3/13). Among the 26 red cards, 6 are face cards, which is also 3/13. So being red and being a face card are independent.
Does knowing B change anything?
In a shop, 60 of 500 customers bought a pastry: 12%. But of the 150 who bought coffee, 45 bought a pastry: 30%. Knowing someone bought coffee more than doubles the chance they bought a pastry, so the two aren't independent. Comparing the conditional chance with the overall chance is the quickest independence check there is. For a whole table, Advanced mode adds a chi-square test.
Three famous puzzles
The Monty Hall problem
A car is behind one of three doors. You pick one. The host, who knows where the car is, opens another door to show a goat, and offers you the chance to switch. You should: switching wins 2 times in 3. Steve Selvin posed the problem in The American Statistician in 1975. When Marilyn vos Savant gave the answer in her Parade magazine column in 1990, she received thousands of letters telling her she was wrong, many from readers with PhDs.
The key is that the host's choice isn't random. If he opened doors at random and happened to show a goat, switching would only win half the time. You can play both versions above.
The two-children problem
A family has two children and at least one is a boy. The chance both are boys is 1/3, not 1/2, because the families that fit are boy-boy, boy-girl and girl-boy. If you're told the older child is a boy, the answer becomes 1/2. Martin Gardner wrote about the puzzle in Scientific American in 1959. In 2010, Gary Foshee added a twist: if at least one is a boy born on a Tuesday, the answer is 13/27, about 48.1%.
Simpson's paradox
A 1986 study in the BMJ compared two kidney stone treatments. Treatment A was more successful for small stones (93% against 87%) and for large stones (73% against 69%). Yet Treatment B looked better overall (83% against 78%). The reason: A was mostly used on large stones, which are harder to treat. In 1975, a study of graduate admissions at the University of California, Berkeley found the same pattern, where the overall figures and the department-by-department figures pointed in different directions. Conditional rates can reverse when groups are combined.
Mistakes that give the wrong answer
Dividing by the grand total. In the pet table, 18 out of 100 is the chance of owning both, not the chance of owning a cat given a dog. Divide by the total for what you're given: 30.
Mixing up P(A | B) and P(B | A). 60% of dog owners have a cat, but only 45% of cat owners have a dog. Confusing the two in court is called the prosecutor's fallacy, and it's covered on the Bayes' theorem page.
Assuming events are independent. Multiplying P(A) × P(B) only works for independent events. For the shop example it would give 3.6% for coffee and pastry together, but the real figure is 9%.
Trusting combined figures. As Simpson's paradox shows, an overall rate can hide, or even reverse, what's happening in each group.
Where it's used
Medical testing asks for the chance of a condition given a positive result, which is worked through on the Bayes' theorem calculator. Shops estimate the chance you'll buy something given what's already in your basket. Spam filters work out the chance an email is spam given the words it contains. Insurers price risk given what they know about you.
How we calculate
Table answers are exact fractions of your counts, turned into percentages only at the last step. Answers from probabilities follow the rules above, and the calculator checks that your numbers fit together, for example that the chance of both is never bigger than the chance of either one. The chi-square test compares your table with what independence would predict, and warns you if any expected count is below 5, when the test is less reliable.
The Monty Hall and two-children simulations run thousands of random games or families in your browser. Every number in the examples on this page was checked against an independent calculation in Python. If you spot a mistake, let us know and we'll correct it and note the change here.
References
- Sheldon Ross, A First Course in Probability, 10th edition, Pearson, 2019. Chapter 3 covers conditional probability and independence.
- Charles Grinstead and J. Laurie Snell, Introduction to Probability, 2nd edition, American Mathematical Society, 1997. Chapter 4 covers conditional probability, including the Monty Hall problem.
- Steve Selvin, "A Problem in Probability", letter to the editor, The American Statistician, 29(1), 1975.
- C. R. Charig and colleagues, "Comparison of Treatment of Renal Calculi by Open Surgery, Percutaneous Nephrolithotomy, and Extracorporeal Shockwave Lithotripsy", BMJ, 292, 1986.
- P. J. Bickel, E. A. Hammel and J. W. O'Connell, "Sex Bias in Graduate Admissions: Data from Berkeley", Science, 187, 1975.
Related calculators
- Bayes' Theorem Calculator, the next step: reversing a conditional probability with new evidence
- Card Probability Calculator, where every draw is conditional on the ones before
- Binomial Probability Calculator, for repeated independent tries
- Combinations and Permutations Calculator, for counting outcomes
- Coin Flip and Dice probability calculators
- Probability Calculator, the full set of tools
Questions people ask
How do I find P(A | B) from a table?
Find the row or column for B and its total. Take the count where A and B overlap and divide it by that total, not by the grand total. In the pet table, 18 of the 30 dog owners have a cat, so P(cat | dog) = 18/30 = 60%.
Is P(A | B) the same as P(B | A)?
No. They share the same top number but divide by different totals. In the pet table, P(cat | dog) is 60% but P(dog | cat) is 45%. They're only equal when A and B are equally likely.
Is P(A | B) the same as P(A and B)?
No. P(A and B) is out of everyone. P(A | B) is out of just the cases where B happened, so it's always at least as large, and equal only when B is certain.
How can I tell if two events are independent?
Check whether P(A | B) equals P(A). If it does, knowing B changes nothing. Equivalently, check whether P(A and B) equals P(A) × P(B).
What happens if P(B) is 0?
P(A | B) isn't defined. You can't condition on something that never happens, because there are no cases to look inside.
Why should you switch in the Monty Hall problem?
Your first pick is right only 1 time in 3, and the host's reveal doesn't change that, because he always shows a goat. The remaining 2 in 3 all ends up on the other closed door.
What is Simpson's paradox?
It's when a comparison points one way in every subgroup but the other way when the groups are combined. It happens when the groups have very different mixes of easy and hard cases.