Jugami Statistics

Jugami › Statistics and Probability › Correlation and Regression

Statistics · Unit 6

Correlation and Regression

When two things rise and fall together, a scatterplot shows it, r measures it and a least-squares line predicts it. None of them can tell you why.

Countries that eat more chocolate win more Nobel Prizes per person, and the link is strong. Does chocolate make people smarter? To answer that, you need the tools in this unit: a scatterplot to see the pattern, the correlation r to measure it, a least-squares line to predict from it, residuals and r² to check the fit, an eye for single points that pull the line around, and a clear sense of when a correlation can, and can't, show cause and effect.

A made-up scatterplot of eleven points rising from left to right, with a least-squares line through them and squares drawn on three of the residuals. The correlation is r = 0.89. Points, a line and some squares r = 0.89 made-up data

Does chocolate win Nobel Prizes?

In October 2012 the New England Journal of Medicine, one of the world's best-known medical journals, printed a short note by Franz Messerli. For 23 countries he plotted how much chocolate people eat per person each year against how many Nobel laureates the country has per 10 million people. The points rose together strongly: the correlation was r = 0.791, with a p-value below 0.0001. Leaving out one country, Sweden, pushed it up to 0.862.

Messerli even worked out a slope from his line: it would take about 0.4 kg more chocolate per person per year to raise a country's number of Nobel laureates by one.

So should a country hand out chocolate to win prizes? Keep your answer in mind. By the end of this unit you'll be able to say exactly what this graph shows, what it doesn't, and what kind of study could settle the question.

Reading a scatterplot

A scatterplot shows two quantitative variables measured on the same individuals: each individual is one dot. Put the explanatory variable (the one you think may explain or predict the other) on the horizontal x-axis, and the response variable on the vertical y-axis. In the chocolate graph each dot is a country, chocolate is x and Nobel laureates are y.

To describe a scatterplot, say four things, always in context:

Four made-up scatterplots. Strong positive linear, r = 0.97. Weak negative linear, r = -0.48. Curved, rising then falling, r = 0.01 even though the pattern is strong. No association, r = 0.04. Strong positive linear, r = 0.97 Weak negative linear, r = −0.48 Strong but curved r = 0.01 No association r = 0.04
Four made-up data sets. The curved one has a strong pattern but r near 0, because r only measures straight-line association.

Example. “There is a strong, positive, linear association between arm span and height for these students, with no clear outliers. Students with longer arm spans tend to be taller.”

The correlation coefficient r

The correlation coefficient r is a single number that measures the direction and strength of the linear association between two quantitative variables. To find it, turn every x and every y into a z-score, multiply each pair, add up the products and divide by n − 1:

r = (1 ⁄ (n − 1)) · Σ zx · zy where zx = (x − x̄) ⁄ sx and zy = (y − ȳ) ⁄ sy

A point that is above average in both x and y (or below average in both) gives a positive product. A point that is above in one and below in the other gives a negative product. So r is positive when most points sit in the “both above” and “both below” corners.

Worked example. Five students (made-up data) record hours studied, x, and quiz score out of 10, y.

Computing r from z-scores: x̄ = 3, ȳ = 4, sx = sy ≈ 1.581
xyzxzyzx · zy
12−1.265−1.2651.6
23−0.632−0.6320.4
3500.6320
440.63200
561.2651.2651.6

The products add up to 3.6, so r = 3.6 ÷ (5 − 1) = 0.9: a strong positive linear association. In practice a calculator does this, but now you know what it is adding up.

What r does and doesn't do

Guess the correlation

Getting a feel for r takes practice. A cloud has to be quite tight before r reaches 0.9, and a loose cloud with r = 0.5 can look like almost nothing. Play a few rounds to calibrate your eye.

Same r, different stories: Anscombe's quartet

In 1973 the statistician Francis Anscombe published four small data sets to make one point: always graph your data. All four have the same mean of x (9), the same mean of y (7.50), the same correlation (r = 0.816) and the same least-squares line (ŷ = 3.00 + 0.500x). They look nothing alike.

Anscombe's quartet: four data sets of 11 points each, all with mean x 9, mean y 7.50, correlation 0.816 and least-squares line y-hat = 3.00 + 0.500x. Set I is a straight-line cloud, set II is a smooth curve, set III is an exact line with one outlier, and set IV has ten points stacked at x = 8 and one point far to the right at x = 19. Set I a straight-line pattern Set II a smooth curve Set III a line plus one outlier Set IV one far-out point
Anscombe's real data (1973), with the shared least-squares line drawn in red on each set.

Numbers summarize; they don't show. Before you trust r or a regression line, look at the scatterplot.

The least-squares regression line

A regression line describes how the response y changes as x changes, and lets you predict y from x. We write it as

ŷ = a + b·x

where ŷ (“y-hat”) is the predicted y, b is the slope and a is the y-intercept. For each data point, the residual is the gap between what happened and what the line predicted:

residual = y − ŷ (actual − predicted)

Many lines could go through a cloud of points. The least-squares regression line (LSRL) is the one that makes the sum of the squared residuals as small as possible. Squaring makes every residual count as positive and punishes big misses much more than small ones.

Finding the line from summary statistics

You don't have to search for the line. From the means, the standard deviations and r:

b = r · sy ⁄ sx a = ȳ − b·x̄

The second formula says the LSRL always passes through the point (x̄, ȳ). The first says the slope has the same sign as r.

Worked example. For a class of students (made-up data), arm span x has mean x̄ = 165 cm and SD sx = 9 cm; height y has mean ȳ = 166 cm and SD sy = 8 cm; and r = 0.9.

  1. Slope. b = 0.9 × 8 ⁄ 9 = 0.8
  2. Intercept. a = 166 − 0.8 × 165 = 166 − 132 = 34
  3. Line. predicted height = 34 + 0.8 × (arm span), both in cm.
  4. Predict. For an arm span of 170 cm: ŷ = 34 + 0.8 × 170 = 170 cm.
  5. Residual. A student with that arm span who is actually 173 cm tall has residual 173 − 170 = +3 cm: the line under-predicted by 3 cm, and the point lies above the line.

Why “regression”? Put the slope formula in z-scores and it reads ẑy = r · zx. Because r is between −1 and 1, a predicted y is always fewer SDs from its mean than x is from its mean. Francis Galton saw this in 1886 with parents' and children's heights: children of very tall parents were tall, but on average less extreme than their parents. He called it regression toward the mean, and the name stuck to the whole method.

Interpreting the line, and extrapolation

Extrapolation

Extrapolation means using the line to predict far outside the range of x-values in the data. The line only describes the data you have; nothing guarantees that the pattern continues.

For children aged 2 to 10, a made-up growth line might be predicted height = 80 + 6 × (age), in cm. It works well at age 8 (128 cm). At age 40 it predicts 80 + 240 = 320 cm, more than 3 m tall. People stop growing; the line doesn't know that.

Residuals and residual plots

A residual plot graphs each residual (y − ŷ) against x, with a horizontal line at 0. For the least-squares line, the residuals always add up to 0, so the plot is centred on that line. It magnifies anything the line is missing.

r²: how much does the line explain?

The coefficient of determination, r², is the fraction of the variation in y that is explained by the least-squares line on x. It compares the squared residuals around the line with the squared deviations around the plain mean ȳ:

r² = 1 − Σ(y − ŷ)² ⁄ Σ(y − ȳ)²

For the five study-hours students above, the squared deviations from ȳ = 4 add up to 10, and the squared residuals from the line ŷ = 1.3 + 0.9x add up to 1.9. So r² = 1 − 1.9 ⁄ 10 = 0.81, which is 0.9² as it should be.

Say it in context: “About 81% of the variation in quiz scores is explained by the linear relationship with hours studied.” The other 19% is left over in the residuals: other influences, and chance.

r² loses the sign: r = 0.9 and r = −0.9 both give r² = 0.81. And a high r² is not proof that a line is the right model. Anscombe's sets I to IV all have r² ≈ 0.67.

Outliers and influential points

Notice the middle outlier: it has a huge residual and hurts r badly, yet the slope barely moves, because its x is right at x̄. Far-right points have the most leverage. Whether they are influential depends on whether they agree with the rest.

Don't just delete points you don't like. Check whether an unusual point is a mistake; if it is real, report results with and without it.

Correlation is not causation

A strong correlation says two variables move together. It does not say that one causes the other. There are several other explanations to rule out first:

Two variables are confounded when their effects on the response can't be told apart. If richer countries eat more chocolate and spend more on universities and research, then chocolate and wealth are confounded, and the chocolate graph can't separate them.

Diagram: a lurking variable, national wealth, has arrows to both chocolate eaten per person and Nobel prizes per person. A dashed line with a question mark joins chocolate and Nobel prizes: the two are correlated, but the arrow from chocolate to prizes is not shown by the data. National wealth the lurking variable Chocolate eaten per person Nobel prizes per 10 million people ? a possible common cause
One possible explanation of the chocolate correlation: a common cause. The data alone can't tell which story is true.

Messerli's data are also country-level averages. Even a real link between countries would not show that the individual people who eat more chocolate are the ones who win prizes.

A real case: hormone therapy and heart disease

By the 1990s, many observational studies had found that women who took hormone therapy after menopause had less heart disease than women who did not. In 1996 the US Preventive Services Task Force recommended (grade “B”) that doctors counsel women about hormone therapy's possible benefits, which observational studies suggested included less heart disease. But the women in those studies had chosen hormone therapy, and observational data can't separate the effect of the hormones from the other ways those women differed from women who didn't take them.

The Women's Health Initiative tested it with a randomized experiment. In one trial, 16,608 women aged 50 to 79 were randomly assigned to take estrogen plus progestin or a placebo. The trial was stopped early, after an average of 5.2 years, and the results were published in July 2002. Hormone therapy had not protected the heart: the hazard ratio for coronary heart disease was 1.29 (95% CI 1.02 to 1.63), and there was more breast cancer and stroke as well, though fewer hip fractures. In 2002 the Task Force gave a “D” grade, a recommendation against using hormone therapy to prevent chronic conditions, and it reaffirmed that in 2017 and 2022.

How to get evidence of cause and effect: a well-designed randomized experiment. Random assignment makes the groups alike on average in every lurking variable, measured or not, so a clear difference in the response can be put down to the treatment (Unit 7 shows how to design one). When an experiment is impossible or unethical (no one may assign people to smoke), causal claims need many studies that agree, a plausible mechanism and a dose-response pattern.

Back to chocolate: the graph shows a strong country-level association, nothing more. To test whether chocolate helps, you would have to randomly assign people to eat it, and Nobel Prizes would be a slow outcome to wait for.

Common mistakes

Saying “correlation” for any relationship. r describes straight-line association between two quantitative variables. There is no r for eye colour and favourite sport.

Reading r near 0 as “no relationship”. There may be a strong curve. Look at the graph.

Forgetting the hat. The line gives ŷ, a prediction, not y. Write “predicted height = 34 + 0.8 (arm span)”.

Getting the residual backwards. Residual = actual − predicted = y − ŷ. A positive residual means the point is above the line.

Using b = r · sx ⁄ sy. The SD of y goes on top: b = r · sy ⁄ sx.

Extrapolating. Predictions far outside the observed x-values are guesses about a pattern you never saw.

Calling r² a percentage of points. r² = 0.81 means 81% of the variation in y is explained by the line, not that 81% of points are on it or that predictions are 81% right.

Treating correlation as cause. Ask what lurking variables could explain it, and whether the data came from an experiment.

Practice

People behind the ideas

1805 Adrien-Marie Legendre publishes the first clear explanation of the method of least squares, in a work on the orbits of comets. Robert Adrain in America finds it independently in 1808.

1809 Carl Friedrich Gauss publishes least squares too, connects it with the normal distribution, and claims he had used it since 1795, which starts a famous dispute with Legendre. Gauss had used his methods to predict where the newly found dwarf planet Ceres, discovered by Giuseppe Piazzi on 1 January 1801, would reappear.

1844 Auguste Bravais presents a formula equivalent to the correlation coefficient (his memoir is printed in 1846), decades before it gets Pearson's name. Pearson credited him in 1896, but in 1920 called that credit “hopelessly incorrect”: Bravais was studying errors in locating a point, not the link between two variables.

1886 Francis Galton publishes “Regression towards mediocrity in hereditary stature”. Children's heights deviate from the average less than their parents' do, and his word “regression” is now the name of the whole method. Galton also used these ideas to promote eugenics, a movement now rejected as scientifically wrong and harmful.

1895 Building on Galton's idea, Karl Pearson develops the correlation coefficient in the form we use today, in his paper “Notes on regression and inheritance in the case of two parents”. It is still called Pearson's r.

1973 Francis Anscombe publishes “Graphs in Statistical Analysis” with his quartet of data sets, a lasting argument for drawing the graph before trusting the numbers.

Quiz

Ten questions. Pick an answer for each, then check.

1. A scatterplot of hours of sleep against reaction time shows points falling from upper left to lower right, close to a straight line. Which value of r fits best?

2. Which statement about the correlation coefficient r is true?

3. Heights of the same plants are recorded in centimetres and then converted to inches. What happens to the correlation between height and age?

4. For a class, x̄ = 20, sx = 5, ȳ = 70, sy = 10 and r = 0.6. What is the slope of the least-squares line for predicting y from x?

5. Continuing the last question (slope b = 1.2, x̄ = 20, ȳ = 70), what is the intercept?

6. A line predicting a used car's price (in dollars) from its age (in years) is ŷ = 18,000 − 1,500x. What does −1,500 mean?

7. Using ŷ = 18,000 − 1,500x, a 4-year-old car sells for $13,500. What is its residual?

8. A residual plot shows residuals that are positive for small and large x and negative in the middle. What should you conclude?

9. A regression of exam score on study hours has r = 0.7. What fraction of the variation in exam scores is explained by the line?

10. Across countries, chocolate eaten per person is strongly correlated with Nobel prizes per person. Which conclusion is justified?

Talk about it

Sources