Association in a two way table and segmented bar graphs
People answer two questions, each with a few possible answers. How can you tell whether the answer to one goes with the answer to the other?
Where you are 3 in Two-way tables
Why this exists
A two-way table records two categorical variables for the same people: whether each student has a library card, say, and whether each one reads for fun. The natural question is whether the two go together. Do card holders read for fun more often than everybody else?
Counting cannot answer that: if 150 students have no card and only 50 have one, the no-card group can hold more readers simply because it holds more students. And “has a card” has no place on a number line, so there is no scatter plot to draw. What works is comparing the share of each group giving a particular answer, and a segmented bar graph puts those shares side by side.
Definition
Two categorical variables recorded on the same people (or things) are associated in a set of data when the conditional relative frequencies differ noticeably from one row of the table to the next, or from one column to the next. They are not associated in that data when the conditional relative frequencies are about the same in every row.
A row’s share for an answer is its count for that answer divided by the row total. How big a gap counts as “noticeable” is a judgment at this level (a point or two usually reads as none, tens of points as a clear one), which the test for independence later turns into a calculation.
A segmented bar graph, also called a stacked 100\% bar graph, draws one bar for each group. Every bar is the same height, standing for 100\% of its group, and is cut into pieces whose heights are that group’s conditional shares. The difference between two percentages is measured in percentage points: 70\% and 30\% are 40 percentage points apart.
Intuition
Look only at the line where the shaded piece meets the white one. On the left it sits at 70\% in one bar and 30\% in the other: whether a student has a library card goes with a big change in how likely that student is to read for fun. On the right the line is almost level, at 60\% and 58\%: knowing whether a student plays a team sport tells you almost nothing about whether that student prefers summer or winter.
A group of 50 and a group of 150 get bars of the same full height, so the picture compares shares, never raw counts. Reading a piece is reading a bar graph: its height is its top minus its bottom on the percentage scale.
Results
No association means one common share. If every row has the same share in some column, then that share is also the share of the whole table in that column: the column total divided by the grand total.
Level lines. In a segmented bar graph, the variables are not associated exactly when every boundary between pieces sits at the same height in every bar.
Why it is true
Suppose every row puts the same share, say 40\%, of its people in the first column. That column’s total adds up the rows’ counts, so it is 40\% of the first row plus 40\% of the second, and so on. Taking 40\% of each part and adding is the same as taking 40\% of the whole, so the column total is 40\% of the grand total. Nothing depends on the number 40 or on how many rows there are.
The level lines follow from how the graph is drawn. Each bar is one row scaled to 100\%, so the height of each boundary is that row’s share. Equal shares in every row are the same thing as equal heights in every bar.
Worked examples
Library card and reading for fun
A school asked 200 students whether they have a library card and whether they read for fun most weeks (made-up data).
| Reads for fun | Does not | Total | |
|---|---|---|---|
| Has a library card | 35 | 15 | 50 |
| No library card | 45 | 105 | 150 |
| Total | 80 | 120 | 200 |
Are the two variables associated in this data?
SolutionThe raw counts point the wrong way: 45 students without a card read for fun against only 35 with one. But the no-card group is three times as large, so its counts are bound to be bigger. Comparing groups of different sizes needs the share of each group, the conditional relative frequency of reading for fun within each row:
The shares are 40 percentage points apart, far too big a gap to call “about the same”, so having a library card and reading for fun are associated in this data. The table says nothing about why (Example 5 takes that up).
Team sport and preferring summer or winter
A different group of 140 students was asked whether they play a team sport and whether they prefer summer or winter (made-up data).
| Prefers summer | Prefers winter | Total | |
|---|---|---|---|
| Plays a team sport | 54 | 36 | 90 |
| No team sport | 29 | 21 | 50 |
| Total | 83 | 57 | 140 |
Are the two variables associated?
SolutionCompare the share preferring summer in each row:
The gap is 2 percentage points. To judge whether that is noticeable, ask how much one student moves a share. In the no-sport row each student is \displaystyle \frac{1}{50} = 2\% of the row, so the whole gap is the answer of a single student. Shares wobble by that much from one survey to the next even when nothing links the variables. The shares are about the same, so playing a team sport and preferring summer are not associated in this data. This is the right panel of Figure 1.
Drawing a segmented bar graph
Ondine asked 160 students whether they had eaten breakfast that morning and whether they felt hungry before lunch (made-up data).
| Hungry before lunch | Not hungry | Total | |
|---|---|---|---|
| Ate breakfast | 30 | 90 | 120 |
| Skipped breakfast | 26 | 14 | 40 |
| Total | 56 | 104 | 160 |
Draw a segmented bar graph with one bar for each breakfast group, and say what it shows.
SolutionEach bar stands for one row, so its pieces are that row’s shares, which add to 100\%:
Both bars are drawn to the full 100\%, though the groups hold 120 and 40 students. The shaded piece (hungry) runs from 0\% to 25\% in the first bar and to 65\% in the second.
The boundary jumps from 25\% to 65\%, a gap of 40 percentage points, so eating breakfast and feeling hungry before lunch are associated in this data: students who skipped breakfast felt hungry before lunch far more often. Grouping by breakfast is natural, since it comes earlier in the day, but it is a choice; Example 4 divides a table the other way.
Dividing the other way
Use the library table of Example 1, but divide by columns: among students who read for fun, and among those who do not, what share has a library card?
SolutionNow each column is a group, and the share is taken out of the column total:
These differ from Example 1’s 70\% and 30\% because they answer a different question, so a sentence about them must name the group: “43.75\% of readers have a card” is not “43.75\% of card holders read”. The verdict is the same, an association. In a table with two rows and two columns the two ways of dividing never disagree about whether a gap exists, which a little algebra in a later course shows.
Association is not causation
Peregrine’s town surveyed 400 adults about owning a dog and walking every day (made-up data).
| Walks daily | Does not | Total | |
|---|---|---|---|
| Owns a dog | 114 | 36 | 150 |
| No dog | 95 | 155 | 250 |
| Total | 209 | 191 | 400 |
Are the variables associated? Does the table show that owning a dog makes a person walk daily?
SolutionThe shares walking daily are
a gap of 38 percentage points, so the variables are clearly associated.
The table does not show that the dog causes the walking. At least three stories fit the same counts. A dog needs walking, so owning one may lead to daily walks. People who already love walking may be more likely to get a dog. Or a third variable may push both up: an adult who lives beside a park, or has more free time, may be more likely both to keep a dog and to walk daily. A two-way table records which cell each person fell into, never why. Telling the stories apart needs a study in which the researcher decides who gets the treatment, the difference between an observational study and an experiment.
The count that would mean no association
Quilla-Rose runs the same survey in a neighboring town (made-up data). Of 80 dog owners, 60 walk daily. She also asks 120 adults with no dog.
(a) How many of the 120 would have to walk daily for the variables to be not associated?
(b) In fact 42 of them walk daily. Is there an association?
Solution(a) No association means the same share in both rows. The owners’ share is \displaystyle \frac{60}{80} = 75\%, so the other row needs 75\% of 120:
The table would then have 60 + 90 = 150 daily walkers out of 200 adults, and the whole table’s share is \displaystyle \frac{150}{200} = 75\%, the common share, as the first result promises.
(b) With 42 walkers the share is \displaystyle \frac{42}{120} = 35\% against 75\%, a gap of 40 percentage points. The variables are associated. The 90 from part (a) is the yardstick: 42 is far from it.
Boundaries
“Noticeable” depends on the size of the groups. In a group of 10, one person moves a share by 10 percentage points; in a group of 1000, by a tenth of a point. The same gap is weak evidence in a small survey and strong evidence in a large one.
The shares must be conditional. Joint shares, a cell divided by the grand total, mix in the sizes of the groups. In Example 2, \displaystyle \frac{54}{140} \approx 38.6\% and \displaystyle \frac{29}{140} \approx 20.7\% are far apart only because 90 students play a team sport and 50 do not, while the conditional shares, 60\% and 58\%, show no association.
Association is not causation. It says the categories go together in the data, not which one, if either, causes the other (Example 5).
The verdict is about the data collected. A table describes the people who were asked. Whether the same association holds in a wider group depends on how those people were chosen, which is the subject of populations and samples.
Every group must contain someone. A row with total 0 has no share to compare, and each person must sit in exactly one cell.
Where this goes next
Example 6 is the seed of a formal test. The counts a table would have with no association, worked out from the common share, are called expected counts; the chi-square statistic measures how far the real counts sit from them, and the test for independence asks whether that distance is more than chance would usually produce.
In probability, no association is the data version of independent events in a compound event. For two numerical variables the same question is asked of a scatter plot. Drawing the bars by hand is making a bar graph.
Exercises
Deciding from a table
All data are made up.
- Leocadio asked 60 classmates about library cards and reading for fun. Of the 30 with a card, 18 read for fun and 12 do not. Of the 30 without a card, 9 read for fun and 21 do not. Are the variables associated?
- Of 55 students who play a team sport, 33 prefer summer and 22 prefer winter. Of 45 who do not, 27 prefer summer and 18 prefer winter. Are the variables associated?
- Of 48 students who ate breakfast, 12 were hungry before lunch and 36 were not. Of 12 who skipped it, 9 were hungry and 3 were not. Are the variables associated?
- Of 60 dog owners in a village, 45 walk daily and 15 do not. Of 100 adults with no dog, 70 walk daily and 30 do not. Find both shares and say whether you would call the variables associated.
Segmented bar graphs
- Give the height of every piece in a segmented bar graph of Exercise 1, one bar for each card group, with “reads for fun” at the bottom.
- Give the height of every piece in a segmented bar graph of Exercise 3, one bar for each breakfast group, with “hungry” at the bottom.
Use Figure 3 for Exercises 7 to 10.
- What share of people who often visit a library read for fun? What share of people who never visit do not read for fun?
- Does Figure 3 show an association between visiting a library and reading for fun? Use the shaded pieces.
- The “sometimes” group had 60 people in it. How many of them read for fun?
- Altogether 50\% of the people asked read for fun. Describe how Figure 3 would look if the two variables were not associated at all, and say why.
Missing counts
- Of 50 students who ate breakfast, 10 were hungry before lunch. Another 30 students skipped breakfast. How many of the 30 would have to be hungry for there to be no association?
- Of 40 students with a library card, 28 read for fun. Another 90 have no card. How many of the 90 would have to read for fun for there to be no association? In fact 27 do; is there an association?
- A survey of 200 students found that 120 play a team sport and 130 prefer summer. Fill in the four inner cells of the table so that the two variables are not associated.
Dividing the other way
- For the dog table of Example 5, find the share of daily walkers who own a dog and the share of the other adults who own a dog, each to one decimal place. Is the verdict the same as in Example 5?
- For the table of Exercise 1, find the share of readers who have a card and the share of non-readers who have a card, each to one decimal place. Do they agree with your answer to Exercise 1?
Reasoning
- Morwenna looks at the table of Example 2 and says: “54 of the 140 students play a team sport and prefer summer, but only 29 are non-players who prefer summer, so team sport players like summer much more.” Explain what is wrong, and give the comparison she should make.
- Naveen finds the association in Example 5 and concludes that the town should give people dogs to make them walk more. Explain why the table cannot support that, giving two other ways the association could arise.
- Survey A asked 10 people in each of two groups and found shares of 60\% and 50\%. Survey B asked 500 people in each group and found the same two shares. How many people is the 10-point gap in each survey, and which gap is more convincing?
- A segmented bar graph hides how many people are in each group. Explain why that is a strength when the question is whether two variables are associated, and give one question the graph cannot answer because of it.
- A table has 14 and 21 in its first row and 6 and 9 in its second. Find both row shares in the first column and the whole table’s share in that column. Then explain in words why, whenever every row has the same share, the whole table has that share too.
Answers
- Yes. The shares reading for fun are \displaystyle \frac{18}{30} = 60\% with a card and \displaystyle \frac{9}{30} = 30\% without, 30 percentage points apart.
- No. The shares preferring summer are \displaystyle \frac{33}{55} = 60\% and \displaystyle \frac{27}{45} = 60\%, exactly equal.
- Yes. The shares hungry before lunch are \displaystyle \frac{12}{48} = 25\% and \displaystyle \frac{9}{12} = 75\%, 50 percentage points apart.
- The shares walking daily are \displaystyle \frac{45}{60} = 75\% and \displaystyle \frac{70}{100} = 70\%. The gap is 5 percentage points, and one owner is \displaystyle \frac{1}{60} of the owners’ row, about 1.7 points, so the gap is three owners’ answers. That is a judgment call; it is small enough that little or no association is a fair verdict.
- Card bar: 60\% shaded, 40\% white. No-card bar: 30\% shaded, 70\% white. The pieces of each bar come from its own row: \displaystyle \frac{18}{30}, \displaystyle \frac{12}{30}, \displaystyle \frac{9}{30}, \displaystyle \frac{21}{30}.
- Ate bar: 25\% shaded, 75\% white. Skipped bar: 75\% shaded, 25\% white, from \displaystyle \frac{12}{48}, \displaystyle \frac{36}{48}, \displaystyle \frac{9}{12} and \displaystyle \frac{3}{12}.
- 80\% of those who often visit read for fun. Of those who never visit, 20\% read for fun, so 100\% - 20\% = 80\% do not.
- Yes. The shaded pieces rise from 20\% to 45\% to 80\%, so the boundary is far from level; the more often people visit, the larger the share reading for fun.
- 27 people, since 45\% of 60 is 0.45 \times 60 = 27.
- Every shaded piece would reach exactly 50\%, with the boundary level across all three bars. With no association all three groups share one common share, and that common share is the share of the whole table, 50\%.
- 6. The breakfast eaters’ share is \displaystyle \frac{10}{50} = 20\%, and 0.2 \times 30 = 6.
- 63, since \displaystyle \frac{28}{40} = 70\% and 0.7 \times 90 = 63. With 27 the share is \displaystyle \frac{27}{90} = 30\% against 70\%, so there is an association.
- Players: 78 prefer summer, 42 winter. Non-players: 52 summer, 28 winter. With no association every row has the whole table’s share, \displaystyle \frac{130}{200} = 65\%, and 0.65 \times 120 = 78, 0.65 \times 80 = 52. Check: \displaystyle \frac{78}{120} = 65\% and \displaystyle \frac{52}{80} = 65\%.
- \displaystyle \frac{114}{209} \approx 54.5\% of daily walkers own a dog, and \displaystyle \frac{36}{191} \approx 18.8\% of the others do. The gap is large, so the verdict is the same: associated.
- \displaystyle \frac{18}{27} \approx 66.7\% of readers have a card and \displaystyle \frac{12}{33} \approx 36.4\% of non-readers do. They agree: associated.
- She compares counts out of the whole table, and those mostly reflect that 90 students play a team sport and only 50 do not. The comparison within each group is \displaystyle \frac{54}{90} = 60\% against \displaystyle \frac{29}{50} = 58\%, which shows no association.
- A table records who fell in each cell, not why. People who already enjoy walking may choose to get a dog; or a third variable, such as living near a park, may make people both keep a dog and walk daily. Giving out dogs helps only if the dog causes the walking, which a survey cannot show.
- In Survey A one person is \displaystyle \frac{1}{10} = 10\% of a group, so the gap is 1 person. In Survey B it is 0.1 \times 500 = 50 people. Survey B’s gap is far more convincing: one person answering differently would wipe out Survey A’s gap.
- Association is about shares within groups, and full-height bars make groups of different sizes directly comparable. The graph cannot say which group is largest, or how many gave any answer.
- \displaystyle \frac{14}{35} = 40\% and \displaystyle \frac{6}{15} = 40\%, and the whole table has \displaystyle \frac{20}{50} = 40\%. The first column’s total is made of the first row’s count plus the second row’s count. Each of those is 40\% of its own row, so together they are 40\% of both rows put together, which is 40\% of everyone. The same holds for any common share and any number of rows.