Checking independence in a table · Statistics & Data… | StemPy Lab
Course 3.3·Lesson 2 of 3
Checking independence in a table
Two answers in a table are independent when the share of one answer is the same in every row or column of the other. Then every count equals row total times column total divided by the grand total. This lesson checks tables for independence and explains why a real sample is never exactly independent.
about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
check independence in a table by comparing conditional probabilities;
work out the counts a table would have if two answers were independent;
explain why small differences in a real sample may be just chance.
Does knowing one answer change the other?
In the choir table, P(instrument∣choir)=0.6, but P(instrument∣not choir)=16036=0.225. Knowing a student's choir answer changes the chance of the instrument answer by a lot. So the two answers are not independent. We say they are associated.
Here is a different made-up survey of 300 adults: are you left-handed, and do you drink coffee every day?
coffee
no coffee
total
left-handed
12
18
30
right-handed
108
162
270
total
120
180
300
P(coffee∣left)=3012=0.4 and P(coffee∣right)=270108=0.4. Both are equal to P(coffee)=300120=0.4. Knowing the hand tells you nothing about coffee. These two answers are independent.
Three tests that agree
For two answers A and B in a table, each of these says the same thing:
P(A∣B)=P(A∣not B): the share of A is the same in both groups;
P(A∣B)=P(A): the share of A in the group equals the share overall;
P(A∩B)=P(A)×P(B): the product rule of the course on independence.
For the coffee table, P(left and coffee)=30012=0.04, and 0.1×0.4=0.04. The product rule holds.
The expected counts
If two answers were independent, what would each count be? The left-handed adults are 30 of the 300. If they drank coffee at the same rate as everyone, 0.4 of them would drink coffee, which is 12 adults. In general,
expected count=grand totalrow total×column total
For the choir table, the expected count of instrument and choir is 20060×40=12. The survey found 24, twice as many. That is a sign of association.
Try it in Python
The program works out the expected counts for the choir table and compares them with the counts that were observed.
Real samples are never exact
Real data almost never give exactly equal shares, even when two answers are truly independent. A sample is a little lucky or unlucky, as in the coin simulations of the first course. A share of 0.42 in one group and 0.39 in the other may be just chance. A share of 0.6 against 0.225 in groups this size is very unlikely to be chance. The last chapter of this book shows how to decide.
One more warning. Association is not cause. Choir and instrument go together, but neither has to cause the other. The chapter on study design looks at this.
Your turn
The usual mistakes
Comparing counts instead of shares. Groups of different sizes need shares: 12 of 30 and 108 of 270 are the same share.
Calling a tiny difference proof. In a sample, small differences can come from chance alone.
Mixing up independent and mutually exclusive. "Left-handed" and "coffee" overlap a lot and are still independent.
Reading association as cause. A link in a table does not say which answer, if either, causes the other.
Remember these
Independent in a table: the share of one answer is the same in every group of the other.
Equivalent tests: P(A∣B)=P(A), or P(A∩B)=P(A)P(B).
Expected count if independent: row total times column total, divided by the grand total.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
In the coffee table, find P(left-handed given coffee) and P(left-handed). Are they equal?
A made-up table of 400 people has 100 who walk to work and 160 who own a dog. If these were independent, how many dog owners would walk to work?
In a made-up club, 30% of the members swim, 30% of the adults swim and 30% of the children swim. Is swimming independent of being an adult?
For two answers, P(A)=0.5, P(B)=0.2 and P(A∩B)=0.1. Are they independent?
A made-up sample finds that 52% of one group and 49% of another say yes. Does this prove that the answer depends on the group?
References
OpenStax, Introductory Statistics, Chapter 3, the sections on independent events and 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.