← Back to the Introduction to Statistics outline The Course Maker
← Introduction to Statistics outline
Week 4 · Lecture

Lecture: Exploring Relationships Between Two Variables

Introduction to Statistics Free sample edition

Lecture script · about 15–20 minutes spoken · Week 4

Opening

Think about the last time a news story said two things "go together," like hot days and hospital visits, or ad spending and sales. Each of those stories pairs two measurements on the same people, days, or places, and asks whether they move together. A public-health worker, a small-business owner, and a field biologist all face the same question: is there a real pattern here, how strong is it, and what else might be driving it?

So far this course has looked at one variable at a time. In Week 1, you learned where data come from, and you met the difference between an observational study and an experiment. In Week 2, you drew one variable at a time and read your first two-way table. In Week 3, you put numbers on the center and the spread of one variable. Today we put two variables side by side. Next week, in Week 5, Probability Foundations, the same two-way tables turn into probabilities.

We'll take seven ideas in order: the two roles a variable plays, the scatterplot, the correlation and its limits, two readings of a two-way table, and association between categories. Then comes the most important warning in this course: moving together is not cause and effect. Most of our examples come from the penguins you already know, with help from a die, a calendar, and a hot summer day.

1. Name the roles: explanatory and response variables

Picture a coffee cart on a college quad. Every afternoon, the owner writes down two numbers: the day's high temperature and the number of iced drinks sold. The owner suspects the heat helps explain the sales. Temperature is the number doing the explaining. Iced drinks sold is the number the owner wants to understand. Those are two different roles, and naming them is the first thing you do with any two-variable question.

An explanatory variable is, in a two-variable question, the variable that may help explain or predict the other one; it is plotted on the horizontal axis of a scatterplot and written x. A response variable is, in a two-variable question, the variable whose values you want to explain or predict; it is plotted on the vertical axis of a scatterplot and written y.

Now our running question. Do penguins with longer flippers tend to weigh more? The question starts from flipper length and asks about weight. So flipper length, in millimeters, is the explanatory variable, and body mass, in grams, is the response variable. The field log has both measurements for 342 penguins. That gives us 342 pairs, one per bird.

A warning worth hearing early: "explanatory" does not mean "proven cause." It's the variable we start from, and nothing more. Save the word "cause" for the end of this lecture.

Pause and try this. In the coffee cart story, which variable goes on the horizontal axis, and which goes on the vertical axis?

Give yourself a moment before you read on.

Here's the answer. Temperature goes on the horizontal axis, because it's the explanatory variable, and iced drinks sold goes on the vertical axis, because it's the response.

2. Draw the scatterplot: direction, form, strength, and unusual points

Once you know the roles, you can draw the picture. A scatterplot is a graph of two quantitative variables measured on the same individuals, with one point for each individual placed at its pair of values. Each penguin becomes one dot. Its flipper length sets how far right the dot sits, and its body mass sets how high.

Imagine the penguin scatterplot in words. The horizontal axis runs across flipper lengths from 172 to 231 millimeters. The vertical axis runs up body masses from 2,700 grams to 6,300 grams. Now 342 dots land in that space.

Describe every scatterplot with four words, always in the same order: direction, form, strength, and unusual points.

Direction is whether the points on a scatterplot tend to rise from left to right, a positive association, or fall from left to right, a negative association. For the penguins, the dots rise. Birds with short flippers sit low, and birds with long flippers sit high. That's a positive association, a relationship in which larger values of one variable tend to go with larger values of the other.

Form is the overall shape of the pattern, such as a straight-line band, a curve, or separate clusters. The penguin dots fall in a band that follows a straight line rather than bending. That makes it a linear relationship, one whose points cluster around a straight line.

Strength is how tightly the points follow their overall pattern. The penguin band is fairly narrow for its length, so the relationship looks strong.

And unusual points are dots that sit far from the overall pattern. You'll scan for those yourself when you draw this plot in the Data Lab.

One trap catches a lot of people here: judging strength by steepness. But steepness depends on how you stretch the axes. Stretch the vertical axis and the same dots look steeper, without packing any tighter. Strength is about how closely the dots hug the pattern.

Pause and try this. A phone resale site plots each listing's age across and its asking price up, and older phones tend to sell for less. What is the direction of that association?

Think it through before the answer.

Here's the answer. It's a negative association, because larger values of age go with smaller values of price, so the dots fall from left to right.

3. Put one number on a straight line: the correlation coefficient

Words like "strong" leave room to argue, because two people can look at the same dots and disagree. For straight-line patterns, one number settles it.

The correlation coefficient is a unitless number, written r, between negative 1 and positive 1 that measures the direction and strength of the straight-line relationship between two quantitative variables; it does not detect curved patterns.

Read r in two parts. The sign gives the direction: plus for a positive association, minus for a negative one. The size, ignoring the sign, gives the strength. Close to 1 or to negative 1 means the dots hug a line. Close to 0 means no straight-line pattern. Exactly 1 or exactly negative 1 means every dot sits on one line.

For the penguins, the correlation between flipper length and body mass is 0.8712. The sign is positive, which matches the rising dots. The size is close to 1, so the dots hug a straight line closely. In words: the association between flipper length and body mass is strong, positive, and linear.

The letter r belongs to a sample, here the 342 penguins. A whole population's correlation is written with the Greek letter rho, and this week we only compute r.

People often turn 0.8712 into "87 percent of penguins follow the pattern." That's wrong. A correlation is not a percentage of anything. Report it as a plain number, and describe it with direction, form, and strength.

Pause and try this. If someone told you the correlation between two variables was negative 0.8712 instead of positive 0.8712, what would change about the scatterplot, and what would stay the same?

Picture both clouds before you read on.

Here's the answer. The direction would flip, so the dots would fall from left to right instead of rising, but the strength would stay the same, because the size of r is unchanged.

4. Know what r can and cannot do

The correlation is useful, but it has four habits you need to know. It always lands between negative 1 and 1. It has no units. It only sees straight lines. And one unusual point can drag it a long way.

Start with units. Suppose a field team elsewhere records flipper length in centimeters instead of millimeters. Every flipper length gets divided by 10, so the range of 172 to 231 millimeters becomes 17.2 to 23.1 centimeters. The dots get new axis labels, but their pattern is exactly the same. The correlation stays 0.8712. A team using centimeters and a team using millimeters report the same r.

Now the habit that fools people most. A board game scores each roll of a die by how far the face lands from the middle, and the middle of a die is 3.5. The score is the squared distance from 3.5. So face 1 scores 6.25, face 2 scores 2.25, face 3 scores 0.25, face 4 scores 0.25, face 5 scores 2.25, and face 6 scores 6.25. Picture those six dots. They dip down from 6.25 to 0.25 and climb back up to 6.25. That's a perfect U shape. The score is completely decided by the face. And yet the correlation is exactly 0.

How can a perfect pattern have r equal to 0? Because the left half falls and the right half rises by the same amounts, and the two halves cancel. The correlation is looking for one straight line, and a U shape isn't one. So r near 0 means no straight-line relationship. It does not mean no relationship. That's why you always draw the scatterplot before you trust r.

Last habit: r is not resistant. Pair each month's position in the year, 1 through 12, with its number of days. For all 12 months, the correlation is about 0.27, a weak positive association. Now notice February, month 2, with 28 days, while every other month has 30 or 31. Take February out, and the correlation for the other 11 months is about negative 0.13. One unusual month flipped the sign. The calendar didn't change; the summary number did.

Pause and try this. The die scores have a correlation of exactly 0. Does that mean the face you roll has nothing to do with your score?

Hold your answer for a second.

Here's the answer. No, the face decides the score completely; the relationship is a perfect curve, and the correlation can only measure straight-line patterns.

5. Read a two-way table two ways: marginal and conditional distributions

Now we switch from numbers to categories. You met the species-by-island table in Week 2. Let me describe it in words. Adelie penguins appear on all three islands: 44 on Biscoe, 56 on Dream, and 52 on Torgersen, for 152 in all. All 68 Chinstrap penguins are on Dream. All 124 Gentoo penguins are on Biscoe. The island totals are 168 on Biscoe, 124 on Dream, and 52 on Torgersen, and the grand total is 344.

A grocery manager with a table of shoppers by aisle and time of day can look at the whole store, or look inside one aisle. A two-way table holds both of those stories.

A marginal distribution is the distribution of one variable in a two-way table on its own, read from the row totals or the column totals and divided by the grand total. For species, that's Adelie at about 44.2 percent, Chinstrap at about 19.8 percent, and Gentoo at about 36.0 percent. For islands, it's Biscoe at about 48.8 percent, Dream at about 36.0 percent, and Torgersen at about 15.1 percent. Those three add to 99.9 percent, and the missing tenth is rounding, not a lost bird.

A conditional distribution is the distribution of one variable among only the individuals in one category of the other variable, read from a single row or column of a two-way table and divided by that row's or column's total. So you look inside one island and divide by that island's total, not by 344. On Biscoe, with 168 birds, Adelie are about 26.2 percent and Gentoo about 73.8 percent. On Dream, with 124 birds, Adelie are about 45.2 percent and Chinstrap about 54.8 percent. On Torgersen, every bird in the log is Adelie, so Adelie are 100 percent.

The most common slip here is dividing by the wrong total. Before you divide, say the group out loud. "Of the Biscoe penguins" means you divide by 168.

Pause and try this. What share of the Biscoe penguins are Gentoo, and which total do you divide by to find it?

Say the group out loud before you answer.

Here's the answer. About 73.8 percent, because you divide the 124 Gentoo by Biscoe's total of 168, not by the 344 birds in the whole log.

6. Compare conditional distributions to spot an association

Imagine a hiking club that sorts members by favorite trail and home neighborhood. If every neighborhood chose trails in the same proportions, knowing someone's neighborhood would tell you nothing about their trail. If the proportions differ, the two variables are linked.

An association is a relationship between two variables in which knowing the value of one changes what you expect for the other; for categorical variables, the conditional distributions differ from one another.

Now the penguins. Across the whole log, Gentoo are about 36.0 percent of the birds. On Biscoe, they're about 73.8 percent. That's roughly twice the share. So knowing the island changes your best guess about the species. Tell me a bird came from Biscoe, and I'd bet on Gentoo. Tell me Torgersen, and I'd bet on Adelie. Species and island are associated.

Notice what we didn't use: no correlation. Species and island are labels, not numbers, and you can't compute r for labels. For two categorical variables, comparing conditional distributions does the job that r does for two quantitative ones.

Pause and try this. If you saw only the island totals of 168, 124, and 52, could you tell whether species and island are associated?

Think about which numbers you'd need.

Here's the answer. No, the totals alone say nothing about the link; you need the conditional distributions inside each island to compare.

7. Separate association from causation: lurking and confounding variables

Here's a pattern that shows up wherever summers are hot. On days when ice-cream sales are high, more people drown. Should a town ban ice cream to protect swimmers? No. Hot weather sends people to buy ice cream, and hot weather sends people into the water. The heat drives both.

Causation is a relationship in which changing one variable actually produces a change in the other; only a well-designed randomized experiment can establish it. A lurking variable is a variable that is not among the variables being studied but that influences them, and can create or hide an association between them. In the ice-cream story, temperature is the lurking variable.

Another one. Children with bigger feet tend to read at a higher level. Bigger shoes don't teach reading. Older children have bigger feet and more years of school. The lurking variable is age.

Back to the penguins. Every Gentoo lives on Biscoe, and Gentoo average about 5,076.02 grams against about 3,700.66 grams for Adelie. So if you compared body mass by island, species would be mixed right in. A confounding variable is a variable whose effect on the response cannot be separated from the effect of the explanatory variable, because the two are tangled together in the data. Here, species is a confounding variable for any island comparison.

And our flipper question? The correlation of 0.8712 is strong. But the penguin log is an observational study: researchers measured the birds; they didn't assign flipper lengths. Bigger birds overall tend to have both longer flippers and more mass, and the species differ in size too. The data show a strong association. They can't show causation, because no experiment was run.

Pause and try this. A friend says the flipper correlation is so strong that longer flippers must cause heavier penguins. What two questions should you ask?

Give yourself a moment.

Here's the answer. Ask whether there was a randomized experiment, and ask what third variable, such as overall body size or species, could drive both measurements.

Closing

Let's pull the week together in the order we built it. Name the roles first: the explanatory variable goes across, and the response goes up. Describe every scatterplot by direction, form, strength, and unusual points. The correlation r puts one number on a straight-line pattern, and for the penguins it's 0.8712: strong, positive, and linear. Changing units never changes r, but a curve can hide from it, and one unusual point can flip it. A marginal distribution divides by the grand total, and a conditional distribution divides by one group's total. When conditional distributions differ, two categorical variables are associated. And association is not causation: look for the lurking variable, and ask whether anyone ran an experiment.

Next in this module come the Readings & Resources page, the lecture tutorial, the practice set, and the quiz, where you read scatterplots and tables yourself. Then come the discussion and the Data Lab. Next week, in Week 5, Probability Foundations, those conditional distributions become the rules of chance.


Built with The Course Maker · samples.thecoursemaker.com