Skip to content

Unit 2: Probability, Random Variables, and Probability Distributions

Summary Statistics for Two Categorical Variables

Calculate joint, marginal and conditional relative frequencies from a two-way table, pick the one a question asks for, and use them to justify a claim of association.

Topic 2.2 · 9 min read

A school district surveys 400 juniors: do you have a part-time job, and how much do you usually sleep on a school night? Ask "what proportion of students with jobs sleep less than 7 hours?" and "what proportion of students who sleep less than 7 hours have jobs?" and you get two different numbers from the same cell of the same table. Every proportion from a two-way table is a count divided by some total, and the whole topic comes down to choosing the right total.

Part-time jobLess than 7 hours7 to 8 hoursMore than 8 hoursTotal
Yes726424160
No6012060240
Total13218484400

Joint relative frequency: one cell out of everyone

A joint relative frequency is a cell count divided by the grand total. It describes individuals who are in a particular category of both variables, as a share of the whole table:

joint relative frequency=cell counttable total\text{joint relative frequency} = \frac{\text{cell count}}{\text{table total}}

The proportion of all 400 juniors who have a job and sleep less than 7 hours is 72400=0.18\frac{72}{400} = 0.18. The word "and" (or a phrase that pins down both variables, like "working students who sleep less than 7 hours, out of all juniors surveyed") is the signal.

Divide every cell by 400 and you get a table of joint relative frequencies. Its six cells add to 1, because each of the 400 students sits in exactly one cell:

Part-time jobLess than 7 hours7 to 8 hoursMore than 8 hoursTotal
Yes0.180.160.060.40
No0.150.300.150.60
Total0.330.460.211.00

Marginal relative frequency: one variable, ignoring the other

A marginal relative frequency is a row total or a column total divided by the grand total. The name comes from where those totals sit: in the margins of the table. It describes one variable alone, as if the other had never been recorded:

marginal relative frequency=row total or column totaltable total\text{marginal relative frequency} = \frac{\text{row total or column total}}{\text{table total}}

Of all 400 juniors, 160400=0.40\frac{160}{400} = 0.40 have a part-time job, and 132400=0.33\frac{132}{400} = 0.33 sleep less than 7 hours. The marginal relative frequencies for one variable form that variable's distribution (0.40 and 0.60 for job; 0.33, 0.46 and 0.21 for sleep), and they appear as the totals row and column of the joint table above.

Conditional relative frequency: restrict to one group first

A conditional relative frequency is computed inside one row or one column only. You first restrict attention to a single category of one variable (the condition), then ask what share of that group falls in a category of the other:

conditional relative frequency=cell counttotal of that cell’s roworcell counttotal of that cell’s column\text{conditional relative frequency} = \frac{\text{cell count}}{\text{total of that cell's row}} \quad\text{or}\quad \frac{\text{cell count}}{\text{total of that cell's column}}

Both of the opening questions are conditional, but they restrict to different groups:

  • "Of the students with a job, what proportion sleep less than 7 hours?" The group is the Yes row, 160 students: 72160=0.45\frac{72}{160} = 0.45.
  • "Of the students who sleep less than 7 hours, what proportion have a job?" The group is the first column, 132 students: 72132≈0.545\frac{72}{132} \approx 0.545.

The numerator is the same 72 students. The denominators differ because the questions are about different groups. The words that set the condition ("of the," "among," "out of those who," "what percent of ... are") name the denominator. Read them, say the group out loud, and divide by its total. Topic 2.6 turns this same idea into conditional probability, P(A∣B)P(A \mid B).

Using conditional relative frequencies to judge association

Topic 2.1 compared groups by the proportions within each group. Those are conditional relative frequencies, and the full set for one group is a conditional distribution. For the juniors, condition on having a job:

Part-time jobLess than 7 hours7 to 8 hoursMore than 8 hours
Yes (out of 160)0.450.400.15
No (out of 240)0.250.500.25

The two conditional distributions differ: 45% of working juniors sleep less than 7 hours, compared with 25% of non-working juniors, and working juniors are less likely to sleep more than 8 hours (0.15 against 0.25). Having a job and sleep amount are associated in this sample. You can state the size of the difference too: the proportion sleeping less than 7 hours is 0.45−0.25=0.200.45 - 0.25 = 0.20 higher for working students, or 0.450.25=1.8\frac{0.45}{0.25} = 1.8 times as large.

There is a reason the marginal proportion 0.33 sits between 0.45 and 0.25. The marginal is a weighted average of the conditionals, weighted by group size:

0.40(0.45)+0.60(0.25)=0.18+0.15=0.330.40(0.45) + 0.60(0.25) = 0.18 + 0.15 = 0.33

(The two products are the joint relative frequencies 0.18 and 0.15 from the joint table.) This gives a clean description of no association: if every group's conditional proportion is the same, the weighted average equals that common value, so each conditional distribution matches the marginal distribution. When the conditional distributions differ from each other, and so from the marginal, the variables are associated.

This survey shows that job and sleep go together, not why: working may cut into sleep, or students who stay up late anyway may be the ones who take evening shifts.

Worked examples

Worked exampleExample 1: all three kinds from one table

A museum surveys 500 visitors on the way out, recording whether each is a member and how they rate their visit.

VisitorExcellentGoodFairTotal
Member664212120
Nonmember13317176380
Total19921388500

Find (a) the proportion of all visitors who are members and rated the visit Excellent, (b) the proportion of all visitors who rated it Fair, (c) the proportion of members who rated it Excellent, and (d) the proportion of visitors rating it Excellent who are members. Name each kind of relative frequency.

Show solution

(a) Both conditions, out of everyone: a joint relative frequency. 66500=0.132\frac{66}{500} = 0.132.

(b) One variable, out of everyone: a marginal relative frequency, from the Fair column total. 88500=0.176\frac{88}{500} = 0.176.

(c) The group is members, so divide by the member row total: a conditional relative frequency. 66120=0.55\frac{66}{120} = 0.55.

(d) The group is visitors who rated Excellent, so divide by the Excellent column total: also conditional, in the other direction. 66199≈0.332\frac{66}{199} \approx 0.332.

Parts (a), (c) and (d) all have 66 on top. What changes is the group named in the question, and so the denominator: everyone (500), members (120), or Excellent raters (199).

Worked exampleExample 2: building the table from percentages

A gym has 250 members. 40% of them attend at least one group class a month. Of the members who attend classes, 70% renewed their membership this year; of those who don't, 30% renewed. What proportion of the members who renewed attend classes?

Show solution

Turn each percentage into a count, using the group it describes. Class attenders: 0.40(250)=1000.40(250) = 100, so non-attenders number 250−100=150250 - 100 = 150. Renewed among attenders: 0.70(100)=700.70(100) = 70. Renewed among non-attenders: 0.30(150)=450.30(150) = 45. Fill in the table and its totals.

MemberRenewedDid not renewTotal
Attends classes7030100
Does not45105150
Total115135250

The question restricts to members who renewed, so divide by the Renewed column total: 70115≈0.609\frac{70}{115} \approx 0.609. About 60.9% of the members who renewed attend group classes.

Why build the table: the 70% and 30% are conditional on class attendance (row totals), but the question conditions on renewal (a column total). The counts let you switch directions. Note that 0.609 is not 0.70; mixing up the two directions is exactly the mistake the table prevents. As a check, the overall renewal rate 115250=0.46\frac{115}{250} = 0.46 equals the weighted average 0.40(0.70)+0.60(0.30)=0.460.40(0.70) + 0.60(0.30) = 0.46.

Worked exampleExample 3: exam-style free response

A high school offered a free test-prep course before students retook a college entrance exam. Of 600 students who retook the exam, the school recorded whether each took the course and whether their score went up by at least 50 points.

Improved by 50 or moreDid notTotal
Took the course9060150
Did not take it135315450
Total225375600

(a) What proportion of the students who improved by at least 50 points took the course?

(b) The principal says, "Only 40% of the students who improved took the course, so the course is not associated with improvement." Do you agree? Justify your answer with appropriate relative frequencies.

(c) Can the school conclude that the course caused scores to improve? Explain.

Show solution

(a) Restrict to the 225 students who improved: 90225=0.40\frac{90}{225} = 0.40.

(b) No. The principal used the wrong conditional relative frequency. To see whether improving is associated with taking the course, compare the proportion who improved within each course group. Of the 150 students who took the course, 90150=0.60\frac{90}{150} = 0.60 improved by at least 50 points. Of the 450 who did not, 135450=0.30\frac{135}{450} = 0.30 improved. Students who took the course were twice as likely to improve (0.60 compared with 0.30), so these data show an association between taking the course and improving by at least 50 points. The 40% describes who the improvers were, not how likely each group was to improve, and it depends on the group sizes as well as the rates. Course-takers are only 150 of the 600 students, so even improving at twice the rate (0.60 against 0.30) they supply 90 improvers to the other group's 135. Read correctly, it even points toward association: course-takers are 150600=0.25\frac{150}{600} = 0.25 of all 600 students but 0.40 of the improvers.

(c) No. Students chose whether to take the course; it was not randomly assigned. Students who signed up may have been more motivated or studied more on their own, and those differences, not the course, could explain the higher improvement rate. Only a randomized experiment could support a cause-and-effect conclusion.

Why these moves: part (b) earns credit by comparing the two conditional proportions within each course group (the explanatory variable), stating both values, giving a direction, and concluding in context. Part (c) names the specific reason (self-selection, no random assignment) and a plausible alternative explanation.

Where students lose points

Check yourself

  1. Question 1

    A survey of 300 pet owners records pet type (dog or cat) and whether the owner bought pet insurance. 60 owners have a dog and bought insurance. There are 180 dog owners and 75 owners who bought insurance in all. Which value is a conditional relative frequency?

    1. A

      60300\dfrac{60}{300}

    2. B

      75300\dfrac{75}{300}

    3. C

      60180\dfrac{60}{180}

    4. D

      180300\dfrac{180}{300}

    Show answer

    C

    60180≈0.333\frac{60}{180} \approx 0.333 restricts to dog owners (a row total) and asks what share of them bought insurance. 60300=0.20\frac{60}{300} = 0.20 is joint (a cell out of everyone); 75300=0.25\frac{75}{300} = 0.25 and 180300=0.60\frac{180}{300} = 0.60 are marginal (a total out of everyone).

  2. Question 2

    Using the pet survey in the previous check, what proportion of owners who bought insurance own a dog?

    Show answer

    6075=0.80\dfrac{60}{75} = 0.80. Of the 75 owners who bought pet insurance, 80% own a dog.

    The phrase "of owners who bought insurance" restricts to the 75 insurance buyers, so the denominator is that column total, not the 180 dog owners.

  3. Question 3

    In a two-way table of 1,000 voters, 30% of all voters favor a ballot measure. Among voters under 40, the proportion who favor it is also 0.30. Among voters 40 and over, which must be true if there are voters in both age groups?

    1. A

      The proportion who favor it is 0.30.

    2. B

      The proportion who favor it is 0.70.

    3. C

      The proportion who favor it is less than 0.30.

    4. D

      It cannot be determined without the number of voters under 40.

    Show answer

    A

    The overall proportion is a weighted average of the two age groups' proportions: 0.30=w(0.30)+(1−w)q0.30 = w(0.30) + (1-w)q forces q=0.30q = 0.30 for any weight ww between 0 and 1. So the group sizes do not matter. Choice D is tempting, but the weighted-average fact makes the sizes irrelevant here.

  4. Question 4

    Of 200 drivers, 80 drive electric cars. 56 electric-car drivers and 36 gas-car drivers say they charge or fuel up at work. Calculate the relevant conditional relative frequencies and say whether car type and fueling at work appear to be associated.

    Show answer

    Electric: 5680=0.70\dfrac{56}{80} = 0.70. Gas: 36120=0.30\dfrac{36}{120} = 0.30. Electric-car drivers in this sample were much more likely to charge or fuel at work (0.70 compared with 0.30), so car type and fueling at work appear to be associated.

    There are 200−80=120200 - 80 = 120 gas-car drivers. The two conditional proportions differ substantially, which is what association between categorical variables means.

Go deeper