Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 37 ยท Compound Events and Conditional Probability

Conditional Probability

Learn what P(A given B) means, how to compute it from counts and two-way tables, and why knowing extra information changes a probability.

Probabilities are not fixed facts about the world. They depend on what you know. The chance that a random person in a city owns an umbrella is one number; the chance that a person you see walking out of a rain shower owns one is a different, higher number. When you are given extra information, you shrink the set of possibilities, and the probability changes.

That idea is called conditional probability. This lesson defines it, shows how to read it from a two-way table, and gives you code to check your work. Later lessons build on it: the multiplication rule, independence and Bayes' theorem.

The definition

The probability of event A given that event B has happened is written P(A | B) and read "the probability of A given B". The formula is:

Text
P(A | B) = P(A and B) / P(B)        (only when P(B) > 0)

Think of it as a change of universe. Once you know B happened, only outcomes inside B are still possible. Of those, you count the share that also belong to A.

Example with two dice

Roll two fair dice. What is the probability that the sum is 8, given that at least one die shows a 6?

There are 36 equally likely outcomes. The outcomes with at least one 6 number 11 (six outcomes where the first die is 6, plus five more where only the second is 6). Of these, the ones with sum 8 are (6, 2) and (2, 6). So:

Text
P(sum 8 | at least one 6) = 2 / 11

Without the extra information, P(sum 8) = 5/36, because (2,6), (3,5), (4,4), (5,3), (6,2) all work. The two answers differ, which is the whole point.

Python Count conditional probabilities by listing outcomes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that P(A | B) and P(B | A) are usually different numbers. Confusing them is one of the most common mistakes in probability.

Reading conditional probability from a two-way table

A two-way table counts people by two features at once. Here are 100 people classified by age group and phone type:

Android iPhone Total
Under 30 30 20 50
30 or older 18 32 50
Total 48 52 100

To find P(iPhone | 30 or older), restrict yourself to the row "30 or older" (50 people). Of them, 32 have an iPhone:

Text
P(iPhone | 30 or older) = 32 / 50 = 0.64

The reverse question, P(30 or older | iPhone), restricts you to the iPhone column (52 people), of whom 32 are 30 or older: 32/52, about 0.615. Different question, different denominator.

To find which total goes in the denominator, look at the word after "given". That group is your new universe.

Python A conditional probability calculator for two-way tables

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Conditional probability with a diagram

A Venn diagram makes the shrinking universe visible. Event B is the whole circle you are allowed to look at; the overlap with A is the part you want.

flowchart LR
  U["All outcomes"] --> B["Event B happened<br/>(new universe)"]
  B --> AB["Also in A<br/>(A and B)"]
  B --> NB["Not in A"]

Once B is known, P(A | B) is the share of B that lies in A.

Rearranging: the product form

Multiply both sides of the definition by P(B) and you get a useful rule:

Text
P(A and B) = P(B) ร— P(A | B)

This lets you compute the chance of two things happening together. The next lesson uses it to build tree diagrams.

Common mistakes

  • Using the wrong denominator. The denominator is the probability (or count) of the given event.
  • Swapping P(A | B) for P(B | A). "Most smokers who get lung disease..." and "most people with lung disease smoke..." are different claims.
  • Assuming that a conditional probability equals the unconditional one. Sometimes it does (that is independence), but you must check.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a class, 12 of 30 students play chess and 5 of those 12 also play tennis. What is P(tennis | chess)?

    Given chess, the universe is the 12 chess players. Five of them play tennis, so the probability is 5/12.
  2. 2. Which formula defines P(A | B)?

    P(A | B) = P(A and B) / P(B): the part of B that is also in A, divided by all of B.
  3. 3. Two fair dice are rolled. What is P(sum is 8 | at least one 6)?

    Eleven outcomes contain a six. Only (6,2) and (2,6) have sum 8, so the answer is 2/11.
  4. 4. In the phone table, 32 of 52 iPhone owners are 30 or older. Which statement is correct?

    Given iPhone, the universe is the 52 iPhone owners, and 32 of them are 30 or older.

Summary

  • P(A | B) = P(A and B) / P(B): restrict to B, then ask how much of it is A.
  • In a two-way table, the "given" row or column supplies the denominator.
  • P(A | B) and P(B | A) are generally different.
  • Rearranged, the rule gives P(A and B) = P(B) ร— P(A | B).

Next: The Multiplication Rule and Tree Diagrams