Conditional probability asks how likely A is once you already know that B happened. Practice below with random problems that check your answer and show the steps. Further down, an interactive tree updates every probability as you move the sliders.
Practice generator: conditional probability
Answer as a fraction, a decimal or a percent. A fraction must be exact. A rounded decimal or percent counts if it is within half a percentage point and its last digit is rounded correctly.
Contents
- The formula: shrink the world to B
- Play with the tree
- How to read a tree diagram
- Worked examples
- Common mistakes
- Frequently asked questions
- Related calculators
- See also
The formula: shrink the world to B
Once you know that B happened, only the outcomes inside B are still possible. Conditional probability asks what share of that smaller world also belongs to A:
$$P(A\mid B)=\frac{P(A\cap B)}{P(B)}$$
Read it as "the probability of A given B". Write the same formula for P(B | A) and multiply both sides by P(A), and you get the multiplication rule you apply along a tree diagram:
$$P(A\cap B)=P(A)\cdot P(B\mid A)$$
If learning that B happened does not change the chance of A, so that $latex P(A\mid B)=P(A)$, the two events are independent. Two coin flips are independent. Two cards drawn without replacement are not, because the first card changes what is left. The basics (sample space, "or", independent events) are in Basic Probability: Sample Space, Events and Examples.
Play with the tree
A tree diagram lays out a situation that happens in two steps. You control three numbers: the chance of A, the chance of B when A happens, and the chance of B when A does not happen. The page computes everything else. The yellow leaves are the smaller world. Use the "Given" buttons to switch it between B and its opposite, and watch the conditional probabilities change.
Interactive tree diagram
Drag the sliders. Every number below is computed from them.
How to read a tree diagram
- The branches leaving one node always add up to 100%.
- The first split carries ordinary probabilities. The second split carries conditional ones: the top pair belongs to "A happened" and the bottom pair to "A did not happen".
- Multiply along a path to get an "and" probability.
- Add the leaves that end in the event you want. That gives the total probability of B.
- To reverse the question, divide the path through A and B by the total of all the paths that end in B. This is Bayes' theorem, and it is only the first formula in disguise.
Worked examples
Example 1: a two-way table
A class of 50 students: 15 play a sport and an instrument, 10 play only a sport, 5 play only an instrument and 20 play neither.
| Instrument | No instrument | Total | |
|---|---|---|---|
| Sport | 15 | 10 | 25 |
| No sport | 5 | 20 | 25 |
| Total | 20 | 30 | 50 |
A student plays a sport. What is the probability that the student plays an instrument? Only the 25 sport players count:
$$P(\text{instrument}\mid\text{sport})=\frac{15}{25}=\frac{3}{5}=60\%$$
Reverse the question: given that a student plays an instrument, the chance of playing a sport is $latex \frac{15}{20}=75\%$. The answers differ because each one divides by a different group (25 and 20). Also, $latex P(\text{instrument})=\frac{20}{50}=40\%$ is lower than 60%, so the two activities are not independent.
Example 2: two marbles without replacement
A bag holds 5 red and 3 blue marbles. Two are drawn one after the other without putting the first back. If the first is red, 4 red marbles remain among 7:
$$P(\text{2nd red}\mid\text{1st red})=\frac{4}{7}\approx 57.14\%$$
The chance that both are red multiplies along the path:
$$P(\text{both red})=\frac{5}{8}\cdot\frac{4}{7}=\frac{20}{56}=\frac{5}{14}\approx 35.71\%$$
Example 3: rain and being late (total probability)
It rains on 30% of the days. When it rains you are late 40% of the time, and when it is dry 10%. How likely is it that you are late on a random day? Two paths end in "late":
$$0.30\cdot 0.40=0.12 \qquad 0.70\cdot 0.10=0.07$$
Add them: $latex 0.12+0.07=0.19$, so you are late on 19% of the days.
Example 4: reversing the tree
You are late. How likely is it that it rained? Divide the rainy path by the total:
$$P(\text{rain}\mid\text{late})=\frac{0.12}{0.19}=\frac{12}{19}\approx 63.16\%$$
Natural frequencies show the same thing. Out of 1,000 days, 300 are rainy and 120 of those are late. Of the 700 dry days, 70 are late. That makes 190 late days, and 120 of them were rainy: $latex \frac{120}{190}=\frac{12}{19}$. Rain happens on only 30% of days, yet it explains most late arrivals.
Common mistakes
- Swapping P(A | B) and P(B | A). Example 1 gives 60% and 75%. Likewise, "95% of sick people test positive" does not mean "95% of positive tests are sick people".
- Ignoring the base rate. When a condition is rare, most positive tests can still be false alarms. Choose the "Medical test" example in the tree and read the last two lines.
- Not updating the second branch. Without replacement, the denominator drops by one, and so does the numerator if the first item was of the same kind.
- Adding along a path. Along a path you multiply. You add only across different paths that end in the same event.
- Dividing by the whole. A conditional probability divides by P(B), the size of the smaller world, not by 1.
- Branches that do not add to 100%. Check each pair. It catches most arithmetic slips before they spread.
Frequently asked questions
What is the difference between P(A | B) and P(A and B)?
P(A and B) measures the overlap against everything. P(A | B) measures the same overlap against B only, so it is never smaller than P(A and B). It is larger whenever P(B) is below 1, unless A and B never happen together.
How do I check whether two events are independent?
Compare P(A | B) with P(A). If they are equal, B tells you nothing about A. Equivalently, check whether P(A and B) equals P(A) times P(B). In Example 1, 60% is not 40%, so sport and instrument are linked.
Can P(A | B) be larger than P(A)?
Yes. It is larger when B makes A more likely, as in Example 4, where being late raises the chance of rain from 30% to about 63%. It is smaller when B makes A less likely.
In Example 2 the second marble is red with probability 5/8, the same as the first. Why?
Add the two paths: $latex \frac{5}{8}\cdot\frac{4}{7}+\frac{3}{8}\cdot\frac{5}{7}=\frac{35}{56}=\frac{5}{8}$. If you have not looked at the first marble, the second one is as likely to be any given marble as the first was. The probability changes only when you learn what the first marble was.
Related calculators
- Dice and Coin Probability Simulator
- Combinations Calculator (nCr)
- Simplify Fractions Calculator
- Percentage Calculator
Counting who belongs to which group is the first step in many conditional probability problems, and the Venn diagram practice trains it: Venn Diagram Word Problems: Practice Generator and Interactive Diagram.