Advanced Statistics 201-337 • CEGEP, Montreal

Revision sheet: correlation and linear regression (201-337)

Regression is the chapter where the calculator always gives an answer, even when the question makes no sense. It fits a line to a curved scatter plot, it computes a coefficient on eleven points of which a single one decides everything, and it flags nothing.

This sheet gathers what the machine does not do: look at the scatter plot before, read the residuals after, refuse to extrapolate, and tell an association from a cause. These are exactly the questions that earn marks on the 201-337 exam. It is written for CEGEP students; once it is read, the corrected exercise set on the same chapter puts every reflex to the test.

Mark this sheet as read or add it to your favourites: a free account, no password, keeps your read sheets and favourites from one visit to the next, tells you which chapter to tackle next and lets you ask for the method or exercise you are missing. Create your space, an email is enough.

The thread of the chapter

A correlation coefficient is never read on its own: you need the scatter plot BEFORE computing it, the residuals AFTER computing it, and the question of causation remains wide open in every case.

This chapter is part of 201-337, Advanced Statistics

The essentials

The scatter plot first, the calculation second

  • • Always look at the SHAPE of the scatter plot before computing: linearity, curvature, isolated values, constant spread or not.
  • • A coefficient computed on a nonlinear scatter plot has no meaning, even when it is high.
  • • Two scatter plots of completely different shapes can give exactly the same rr and the same line.
linear scatter plotcurved scatter plotr = 0.82r = 0.82
Two scatter plots with the same coefficient r=0.82r=0.82 and the same line: on the left the relationship is linear, on the right it is clearly curved and the model does not fit.

This is the one rule of the chapter that cannot be sidestepped: the calculator returns a number in every case, including where linear regression is out of place.

The working sums and the line

  • • Sxy=∑xy−(∑x)(∑y)nS_{xy}=\sum xy-\dfrac{(\sum x)(\sum y)}{n}, Sxx=∑x2−(∑x)2nS_{xx}=\sum x^{2}-\dfrac{(\sum x)^{2}}{n}, Syy=∑y2−(∑y)2nS_{yy}=\sum y^{2}-\dfrac{(\sum y)^{2}}{n}.
  • • r=SxySxxSyyr=\dfrac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}, always between −1-1 and 11: the SIGN gives the direction, the ABSOLUTE VALUE the strength.
  • • Least-squares line y=a+bxy=a+bx: b=SxySxxb=\dfrac{S_{xy}}{S_{xx}}, then a=y‾−bx‾a=\overline{y}-b\overline{x}.
  • • It ALWAYS passes through the mean point (x‾,y‾)(\overline{x}, \overline{y}), which gives a free check.
1234567246810mean pointŷ = a + bx
The orange segments are the VERTICAL deviations yi−yi^y_{i}-\hat{y_{i}} that least squares makes as small as possible; the line passes through the mean point (3.5,5.5)(3.5, 5.5) (green).

“Least squares” refers to the sum of the squares of the VERTICAL deviations. That is why the line of yy on xx is not the line of xx on yy: the deviations minimized are not the same.

r, r squared, and what each one measures

  • • r2r^{2} is the proportion of the variation in yy explained by the linear relationship with xx, expressed as a percentage.
  • • r=0.80r=0.80 gives r2=0.64r^{2}=0.64: 64%64\% of the variation explained, not 80%80\%.
  • • Residuals ei=yi−yi^e_{i}=y_{i}-\hat{y_{i}}: their sum is zero by construction, so it proves nothing. It is their PLOT that informs.
  • • Standard error of the estimate: se=∑ei2n−2s_{e}=\sqrt{\dfrac{\sum e_{i}^{2}}{n-2}}, with ∑ei2=Syy(1−r2)\sum e_{i}^{2}=S_{yy}(1-r^{2}).
r = 0.96r² = 0.92r = 0.64r² = 0.41r = 0.07r² = 0r = −0.93r² = 0.87
The sign of rr gives the direction, its absolute value the strength; r2r^{2} tells the share of the variation in yy explained. A scatter plot with no slope gives rr close to 00.

The significance of rr is tested with t=rn−21−r2t=\dfrac{r\sqrt{n-2}}{\sqrt{1-r^{2}}} on n−2n-2 degrees of freedom. The same r=0.50r=0.50 is not significant for 1010 individuals and is significant for 3030.

The four explanations of a correlation

  • • xx causes yy; or yy causes xx; or a third, CONFOUNDING variable causes both; or it is chance on a small sample.
  • • None of these four is ruled out by the calculation: only an experiment with random assignment makes it possible to conclude that there is a cause.
  • • EXTRAPOLATING, that is, predicting outside the range of the observed xx values, is never justified by the model.
xyx causes yxyy causes xxyzz causes bothxychance
The same correlation between xx and yy admits four readings; the calculation does not decide between them, only an experiment with random assignment can.

The causation question is often worth as many marks as the whole regression. Naming a plausible, concrete confounding variable earns more than a general sentence about caution.

The mistakes that cost marks

These are the errors I correct most often in session. Each one costs marks on a paper, even when the reasoning behind it is right.

1. Computing a coefficient without having looked at the scatter plot

3 points, the whole question rests on this diagnosis

What not to write

“r=0.82r=0.82, so the relationship between the two variables is strong and linear.”

What to write

“The scatter plot is clearly curved: the coefficient 0.820.82 does not describe the relationship; the data must be linearized or another model chosen.”

-4-3-2-11234-112345678910r = 0y = x²
Seven points exactly on y=x2y=x^{2}: the link is total, and yet r=0r=0. The coefficient measures ALIGNMENT, not the existence of a relationship.

Why: The coefficient measures alignment, not the existence of a relationship. A perfect parabola can give a zero rr even though the link is total.

2. Reading r as a percentage

1.5 points, every time an interpretation is asked for

What not to write

“r=0.80r=0.80, so 80%80\% of the variation in yy is explained by xx.”

What to write

“It is r2=0.64r^{2}=0.64 that is read as a percentage: 64%64\% of the variation in yy is explained.”

explained: r² = 64%36%r = 0.80: not 80%0100% of the variation in y
With r=0.80r=0.80, the share explained is r2=0.64r^{2}=0.64: the blue band stops at 64%64\%, not at the red mark at 80%80\%.

Why: Only the square of the coefficient can be read as a proportion of variance. The gap is all the larger when rr is middling: 0.50.5 explains only 25%25\%.

3. Predicting outside the observed range

1.5 points, and it is often the last question of the problem

What not to write

“The line gives y^=2x\hat{y}=2x, so for x=50x=50 we predict 100100.”

What to write

“The observed xx values run from 11 to 66: beyond that, the model has nothing to say, and the prediction is not justified.”

1234567891011122468101214161820222426observed rangeoutside the range?
The line y^=2x\hat{y}=2x describes the observed range [1,6][1, 6] (green); extended in red, it rests on no data at all.

Why: Nothing guarantees that the relationship continues: fitted lines describe a domain, they do not predict the world. Linear growth always ends up hitting a physical limit.

4. Drawing a cause from a correlation

2 points, and it is the most heavily weighted question of the chapter

What not to write

“Ice cream sales and drownings are correlated, so ice cream promotes drowning.”

What to write

“A third variable, temperature, explains both: it is a confounding variable, and the correlation establishes no cause.”

temperatureice creamdrowningscorrelated, no cause
Temperature pushes both up (green arrows); between ice cream and drownings there is only a correlation (red), no arrow.

Why: Four explanations remain possible after the calculation, and the regression does not decide between them. Only an experiment with random assignment could.

5. Deleting the inconvenient point

2 points for method, and the whole answer loses its credibility

What not to write

“This point makes r2r^{2} drop from 0.990.99 to 0.650.65: I remove it and recompute.”

What to write

“I investigate where it comes from, then I publish the analysis WITH and WITHOUT this point, pointing out the difference.”

2468101214161820222468101214leverageslope 0.98slope 0.51
The eight aligned points give a slope close to 11; the single point far away in xx cuts it by half, although the central cloud has not changed.

Why: A point far away in xx, called a leverage point, can halve the slope while leaving rr high. It may be a data-entry error just as well as the most informative observation in the data set.

6. Swapping the roles of x and y

1.5 points, and a wrong prediction in the reverse direction

What not to write

“The line of yy on xx is y=2xy=2x, so the line of xx on yy is x=y2x=\dfrac{y}{2}.”

What to write

“These are two different regressions: the first minimizes the vertical deviations, the second the horizontal deviations, and their slopes are reciprocals only if r2=1r^{2}=1.”

123456789123456789y on xx on y
The line of yy on xx (blue) minimizes the vertical deviations, the line of xx on yy (orange) the horizontal deviations: two distinct lines, crossing at the mean point.

Why: The response variable is the one whose deviations are minimized. Choosing which one goes on the xx axis is therefore not a writing convention, it is a modelling decision.

7. Trusting the coefficient without looking at the residuals

2 points, and the model proposed is the wrong one

What not to write

“r2=0.92r^{2}=0.92, so the linear model is good.”

What to write

“The residual plot forms a clear curve: the relationship is not linear, despite a high r2r^{2}.”

residuals against x: a clear curve
The residuals form a parabola instead of a shapeless cloud: the linear model systematically misses the ends and the centre, in opposite directions.

Why: A residual cloud must have no structure. A curvature signals a nonlinear relationship, a funnel a spread that changes with xx: two defects that no coefficient reveals.

8. Forgetting that the line passes through the mean point

2 points when the error slips through, none when the check is made

What not to write

“b=2b=2 and a=1.5a=1.5, on to the next question.”

What to write

“Check: y^(x‾)=a+bx‾\hat{y}(\overline{x})=a+b\overline{x} must equal y‾\overline{y}. Here 1.5+2×3.5=8.5≠71.5+2\times 3.5=8.5\neq 7, so aa is wrong.”

1234567246810121416(3.5, 7)8.5y = 2xa = 1.5
The correct line y^=2x\hat{y}=2x passes through (3.5,7)(3.5, 7); with a=1.5a=1.5, it passes at 8.58.5, above the mean point (red): the error shows up in one line.

Why: The intercept is derived from the mean point: the check is therefore exactly the reverse of its calculation, and it catches every sign error.

9. Confusing the strength of a relationship with how solid the evidence is

2 points on the test question

What not to write

“r=0.50r=0.50 for 1010 individuals: the relationship is significant, it is moderate.”

What to write

“For 1010 individuals, t=0.5080.75≈1.63t=\dfrac{0.50\sqrt{8}}{\sqrt{0.75}}\approx 1.63: not significant. For 3030, the same rr becomes significant.”

Why: Significance depends on nn as much as on rr. It tells whether the relationship is established, never whether it is strong, and even less whether it is useful.

Which method to choose

What to do depending on the shape of the scatter plot

Describe the scatter plot in one sentence before touching the calculator.

linearexponentialpowerisolated point
The scatter plots the tree decides between: alignment, growth that accelerates (exponential), a curve that bends over (power), an isolated point far away in xx (red).
  • If the points line up with no residual structure → ordinary linear regression, then rr, r2r^{2} and the residuals

    Example: y^=2x\hat{y}=2x with r2=0.95r^{2}=0.95

  • If the growth accelerates and the gaps widen as yy grows → exponential model y=aebxy=ae^{bx}: regress ln⁡y\ln y on xx, on a semi-logarithmic scale

    Example: population, invested capital, radioactive decay

  • If the relationship looks like a power law, with no preferred scale → model y=axby=ax^{b}: regress ln⁡y\ln y on ln⁡x\ln x, the slope giving the exponent directly

    Example: scaling law between body mass and metabolism

  • If one point is isolated, very far away in xx → recompute with and without it, compare the two slopes, investigate where it comes from

    Example: a slope that goes from 1.01.0 to 0.50.5

  • If the points form several distinct groups → do not regress on the whole set: the overall line describes none of the groups

    Example: two workshops with different machine settings

Every linearization transforms yy, so the r2r^{2} obtained refers to the TRANSFORMED data. Comparing a semi-log r2r^{2} with a raw r2r^{2} makes no sense.

Reading a residual plot

Plot the residuals against xx and look for any remaining shape.

no patterncurvefunnelisolated residual
Residuals against xx: the first plot has no shape and validates the model; a curve, a funnel or an isolated residual (red) signal a defect.
  • If a cloud with no structure, spread evenly on both sides of zero → the linear model fits, r2r^{2} can be interpreted

    Example: residuals scattered at random on both sides of zero

  • If the residuals form a curve → the relationship is not linear: linearize or change the model

    Example: negative residuals in the centre, positive at the ends

  • If the residuals open out into a funnel as xx grows → the spread is not constant: the prediction intervals no longer hold

    Example: incomes whose spread grows with their level

  • If one residual dwarfs all the others → outlier: investigate, then publish with and without it

    Example: a residual of 88 when the others stay within ±1\pm 1

The sum of the residuals is zero by construction: presenting it as proof that the model is good is a classic error; it only proves that aa was computed correctly.

How the answer is expected to be written

A marker ticks steps. Here they are in order, with the concluding sentence expected word for word.

Writing up a complete regression

When to use it: The question gives a table of pairs and asks for the line, the coefficient and a prediction.

  1. 1 Describe the scatter plot in one sentence: shape, direction, whether or not there are isolated points.
  2. 2 Write the three working sums SxyS_{xy}, SxxS_{xx}, SyyS_{yy} with their numerical values.
  3. 3 Compute bb, then aa from the mean point, and write the equation with the units of the context.
  4. 4 Give rr, then r2r^{2} as a percentage, stating that it is the square that is interpreted.
  5. 5 Predict only inside the observed range, and write down that reservation.

Concluding sentence

“b=3517.5=2b=\dfrac{35}{17.5}=2 and a=7−2×3.5=0a=7-2\times 3.5=0, so y^=2x\hat{y}=2x; r=0.97r=0.97 and r2=0.95r^{2}=0.95: 95%95\% of the variation in yy is explained by the linear relationship.”

The trap: Giving the prediction before checking that the requested xx lies within the observed range.

Marking: 1 point for describing the scatter plot, 2 points for the sums, 1 point for the equation, 1 point for interpreting r2r^{2}, 1 point for the reservation about the prediction.

Writing a conclusion about causation

When to use it: The question asks whether one variable “causes” the other, or asks you to comment on a newspaper claim.

  1. 1 Restate what the calculation establishes: a linear association, with its strength.
  2. 2 List the competing explanations, NAMING a plausible confounding variable from the context.
  3. 3 Say what it would take to conclude that there is a cause: an experiment with random assignment.
  4. 4 Conclude without denying the relationship or turning it into a cause.

Concluding sentence

“The data establish a strong association, but temperature may explain both the sales and the drownings: only a controlled experiment would allow us to conclude that there is a cause-and-effect link.”

The trap: Writing “correlation is not causation” without naming a confounding variable: the general sentence does not earn the mark.

Marking: 1 point for the association, 1 point for the confounding variable named, 1 point for the condition for a causal conclusion.

Check before you hand in

Five minutes of checking recover more marks than one more problem started in a hurry.

The typical problem, taken apart

A complete regression, from the scatter plot to the prediction

Six pairs are recorded: (1,2)(1, 2), (2,3)(2, 3), (3,7)(3, 7), (4,9)(4, 9), (5,9)(5, 9) and (6,12)(6, 12).

Find the least-squares line, interpret the coefficient of determination and predict the value for x=4.5x=4.5.

12345672468101214
The six pairs of the question: the scatter plot is clearly linear and increasing, with no isolated point, which allows a linear regression.

Step 1

∑x=21\sum x=21, ∑y=42\sum y=42, ∑xy=182\sum xy=182, ∑x2=91\sum x^{2}=91, ∑y2=368\sum y^{2}=368, so x‾=3.5\overline{x}=3.5 and y‾=7\overline{y}=7.

Why

The five sums are computed once and for all: everything else follows from them, and an error here spreads everywhere. Copying them out neatly earns the method mark.

Step 2

Sxy=182−21×426=35S_{xy}=182-\dfrac{21\times 42}{6}=35, Sxx=91−2126=17.5S_{xx}=91-\dfrac{21^{2}}{6}=17.5, Syy=368−4226=74S_{yy}=368-\dfrac{42^{2}}{6}=74.

Why

These three quantities are variations, so SxxS_{xx} and SyyS_{yy} are always positive. A negative SxxS_{xx} signals a badly computed sum of squares.

Step 3

b=3517.5=2b=\dfrac{35}{17.5}=2, then a=7−2×3.5=0a=7-2\times 3.5=0, so y^=2x\hat{y}=2x.

Why

The intercept is derived from the mean point: that is what guarantees the line passes through it, and it is the check to make right away.

Step 4

r=3517.5×74≈0.973r=\dfrac{35}{\sqrt{17.5\times 74}}\approx 0.973, so r2≈0.946r^{2}\approx 0.946.

Why

Give both, but interpret only the square: 94.6%94.6\% of the variation in yy is explained by the linear relationship with xx.

Step 5

Residuals: 0, −1, 1, 1, −1, 00,\,-1,\,1,\,1,\,-1,\,0. Sum zero, ∑e2=4\sum e^{2}=4, and se=46−2=1s_{e}=\sqrt{\dfrac{4}{6-2}}=1.

12345672468101214

Why

The residuals show no structure and stay within ±1\pm 1: the linear model holds, which no coefficient alone could establish.

Step 6

Prediction: y^(4.5)=9\hat{y}(4.5)=9, a value inside the range [1,6][1, 6] of the observed xx values.

Why

The reservation about the range must be written BEFORE the number. For x=50x=50, the same line would say nothing reliable, and the marker expects that sentence.

Step 7

Check: Syy(1−r2)=74×0.054=4=∑e2S_{yy}(1-r^{2})=74\times 0.054=4=\sum e^{2}.

Why

This identity links the coefficient and the residuals: the two routes of calculation validate each other in ten seconds.

The conclusion, written out

“The least-squares line is y^=2x\hat{y}=2x, with r=0.97r=0.97 and r2=0.95r^{2}=0.95: 95%95\% of the variation in yy is explained by the linear relationship with xx. For x=4.5x=4.5, a value within the observed range, we predict y^=9\hat{y}=9.”

The classic mistake on this problem: Announcing that 97%97\% of the variation is explained: it is rr, not r2r^{2}, that equals 0.970.97.

Learn by heart

  • • LOOK at the scatter plot before computing: an rr on a curved scatter plot means nothing.
  • • b=SxySxxb=\dfrac{S_{xy}}{S_{xx}}, then a=y‾−bx‾a=\overline{y}-b\overline{x}: the line ALWAYS passes through the mean point.
  • • rr gives the direction and the strength; only r2r^{2} is read as a percentage of variation explained.
  • • Least squares minimizes the VERTICAL deviations: the line of yy on xx is not the line of xx on yy.
  • • The sum of the residuals is zero by construction: it is their PLOT that judges the model.
  • • A leverage point can halve the slope while leaving rr high. Investigate, do not delete.
  • • Exponential: ln⁡y\ln y against xx. Power: ln⁡y\ln y against ln⁡x\ln x, the slope giving the exponent.
  • • Correlation is not causation: name the confounding variable, otherwise the sentence earns nothing.

Frequently asked questions

What is the difference between r and r squared?

The correlation coefficient gives the direction of the relationship through its sign and its strength through its absolute value, between minus one and one. Its square, the coefficient of determination, is read as a percentage: it is the share of the variation in the variable explained by the linear relationship. A coefficient of zero point eight thus corresponds to sixty-four percent, not to eighty.

Why look at the scatter plot before computing?

Because the coefficient measures alignment and nothing else. A perfectly deterministic but curved relationship can give a low coefficient, and two scatter plots of very different shapes can give exactly the same one. The calculator always returns a number, even where a straight line makes no sense at all.

Can an outlier be deleted?

No, not without an investigation. A distant point may be a data-entry error, but it may also be the most informative observation in the data set. The expected approach is to look for where it comes from, then to present the analysis with and without that point while pointing out the difference, rather than making it disappear.

What does the residual plot show?

What the coefficient hides. A shapeless cloud of residuals validates the linear model. A curvature signals that the relationship is not a straight line. A funnel-shaped widening signals a spread that grows with the explanatory variable, which invalidates the prediction intervals even if the fit looks good.

Does a strong correlation prove a cause?

Never. Four explanations remain possible: the first variable causes the second, the second causes the first, a third variable causes both, or chance on a small sample. Only an experiment in which individuals are assigned to the conditions at random makes it possible to conclude that there is a cause-and-effect link.

Practise it

Corrected exercises: Correlation and linear regression, 201-337

A method is proved on a paper, not on a sheet. The set for the same chapter takes each of these traps into a problem, with the solution written out step by step.

  • 11 corrected exercises
  • 110 points
  • 150 minutes
Do the exercises
Something missing from this sheet? A method, a trap, an exercise to practise it, a mistake you spotted: tell me, I read every request.

Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space. Rather not create an account? Write to me directly.

What is it about?
I read every request myself, nobody else sees it. No need to write your name or your school.
When your request is dealt with, you hear about it by email and in your space.

By sending, you agree that I read your request to answer it. It is kept with your account, erased with it, and never published: privacy policy.

Previous sheet Estimation and hypothesis testing

© Ahmed Squalli Houssaini. Revision sheet published at www.letuteurscientifique.ca/en/fiches/cegep-337-correlation-regression. Free for personal and classroom use; republishing it elsewhere requires written permission (legal notice).

See also

Looking for a 201-337 tutor in Montreal?

Get in touch for a first session. Regression is the most useful chapter of the course for the rest of your studies: we work on the calculations and on the interpretation in equal measure.

Site by Studio Squalli