Conditional probability from a two-way table ·… | StemPy Lab
Course 3.3·Lesson 1 of 3
Conditional probability from a two-way table
A two-way table counts people by two answers at once. Once you know one answer, you look at only one row or one column, and the share inside it is a conditional probability, written P(A∣B). This lesson reads conditional probabilities from tables and shows why P(A∣B)
Lesson 1 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
read a conditional probability straight from a two-way table;
use P(A∣B)=P(B)P(A∩B) when the table gives shares instead of counts;
explain why P(A∣B) and P(B∣A) are usually different.
A table from a survey
A made-up survey asks 200 students two questions. Do you play an instrument? Are you in the school choir? A two-way table counts the students by both answers at once.
choir
not choir
total
instrument
24
36
60
no instrument
16
124
140
total
40
160
200
Pick a student at random. The chance that the student plays an instrument is 20060=0.3.
Now suppose you know that the student sings in the choir. You can forget everyone outside the choir column. Of the 40 choir students, 24 play an instrument. So the chance is now
P(instrument∣choir)=4024=0.6
The bar is read as given. A probability that uses some known information is a conditional probability. Knowing "choir" doubled the chance of "instrument", from 0.3 to 0.6.
The other way round
What about P(choir∣instrument)? Now the known fact is "instrument", so look only along the instrument row. Of its 60 students, 24 are in the choir:
P(choir∣instrument)=6024=0.4
The top is the same, 24. The bottom is not, because the group you look inside is different. In general P(A∣B) and P(B∣A) are different numbers. Mixing them up is one of the most common mistakes with probability, in the news as well as in class.
Two horizontal bars, each split into two parts. The top bar is the 40 choir students: 24 play an instrument and 16 do not, so the instrument part fills six tenths of the bar. The bottom bar is the 160 students not in the choir: 36 play an instrument and 124 do not. The instrument parts are shaded dark and labelled with their counts and shares.
The rule behind the table
Divide the top and the bottom of 4024 by the total, 200:
P(A∣B)=P(B)P(A∩B)
Here 40/20024/200=0.20.12=0.6. The rule is useful when a report gives shares, not counts. You meet the exam form of this rule, and Bayes' theorem, in the Maths courses on conditional probability.
Try it in Python
A two-way table fits in a list of two lists: one list for each row. The program finds the totals, then the two conditional probabilities.
Your turn
The usual mistakes
Dividing by the grand total.P(A∣B) divides by the count of B, not by everyone.
Reading the wrong line. Given a column, read down that column. Given a row, read along that row.
Swapping the two events. "Instrument given choir" and "choir given instrument" answer different questions.
Confusing "and" with "given".P(A∩B) is a share of everyone. P(A∣B) is a share of B only.
Remember these
P(A∣B): look only at the row or column of B, and find the share of A inside it.
P(A∣B)=P(B)P(A∩B).
P(A∣B) and P(B∣A) have the same top and different bottoms.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
In the choir table, find P(no instrument given choir).
In the same table, find P(instrument given not choir).
A report says that 15% of people are in a club and 6% of people are in the club and are over 60 years old. Find the probability that a club member is over 60.
In a made-up survey, P(reads news∣has a phone)=0.5. Does that tell you P(has a phone∣reads news)?
Why do the conditional probabilities inside one column always add up to 1?
References
OpenStax, Introductory Statistics, Chapter 3, the section on contingency tables.
Enroll free in Two-Way Tables and Fair Games
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.