hanegreefs.com/Statistics I
Chapter 4 of 10

Correlation and the line of best fit

Scatterplots and how to describe them, explanatory and response variables, the correlation coefficient as the mean product of z-scores, its conditions and properties, lurking variables, residuals, the least squares line with b1 = r sy/sx, predictions and the danger of extrapolation.

Textbook: Ch. 4 (without 4.7, 4.8, 4.10 and 4.11) · Sessions: Module 4, lectures 5 and 6, tutorials 5 and 6 · About 60 minutes

ScatterplotsImportant

A scatterplot shows two quantitative variables measured on the same cases: one dot per case. Put the explanatory (predictor) variable x on the horizontal axis and the response variable y on the vertical axis. Which is which follows from the question: to predict sales from advertising, advertising is x.

Describe a scatterplot with four words: direction (positive: y tends to rise with x; negative: y falls), form (straight or curved), strength (how tightly the dots follow the form) and unusual features (outliers, separate groups).

The correlation coefficientImportant

The correlation coefficient r measures the strength and direction of a linear association. On the formula sheet it is the mean product of the z-scores:

Formula
r = Σ zx zy / (n − 1)

Why it works: with a positive association, most points lie bottom-left (both z-scores negative) or top-right (both positive), so the products are mostly positive. With a negative association the products are mostly negative.

  • r lies between −1 and +1; ±1 means all points on one straight line, 0 means no linear association.
  • r has no unit and does not change if you swap x and y, shift the values or change units.
  • Rough guide: |r| of 0.8 or more is strong, 0.5 to 0.8 moderate, below 0.5 weak.

Conditions: both variables quantitative; the form straight enough; and no outliers that dominate (one outlier can create or destroy a high r).

Common trapCorrelation is not causation. A lurking variable can drive both: ice cream sales and drowning accidents both rise with temperature.

The line of best fitImportant

The linear model is ŷ = b0 + b1 x, where ŷ ("y-hat") is the predicted value. For each case the residual e = y − ŷ is the vertical distance from the dot to the line: positive if the line underestimates, negative if it overestimates. The least squares line makes the sum of the squared residuals Σe2 as small as possible, which gives:

Formula
b1 = r · sy / sx (the slope)b0 = ȳ − b1 x̄ (the intercept; the line passes through (x̄, ȳ))
Worked example

Advertising and sales

A firm tried six monthly advertising budgets x of 1 to 6 thousand euro and recorded sales y of 12, 15, 19, 20, 25 and 27 thousand euro.

1

Means and SDs

x̄ = 3.5, sx ≈ 1.871; ȳ ≈ 19.67, sy ≈ 5.715 (thousand euro)
2

z-score products

the six products zxzy are about 1.79, 0.65, 0.03, 0.02, 0.75 and 1.71; their sum ≈ 4.957
3

Correlation

r ≈ 4.957/5 ≈ 0.991
4

Slope

b1 ≈ 0.991 × 5.715/1.871 ≈ 3.03 thousand euro of sales per thousand euro of advertising
5

Intercept

b0 ≈ 19.67 − 3.03 × 3.5 ≈ 9.07 thousand euro
6

Prediction and residual

at x = 4: ŷ ≈ 9.07 + 3.03 × 4 ≈ 21.18; observed 20, so e ≈ −1.18
Answer

Predicted sales ≈ 9.07 + 3.03 × advertising (both in thousand euro). Each extra thousand euro of advertising goes with about 3.03 thousand euro more sales on average. At x = 4 the line overestimates the actual month.

Interpret the slope with units: "per extra unit of x, ŷ changes by b1 units of y". The intercept is the prediction at x = 0, which only makes sense if x = 0 lies near the data.

Using the line: R squared and extrapolationNeutral

R2 = r2 is the fraction of the variation in y that the line accounts for. With r = 0.8, R2 = 0.64: 64% of the variation in y goes with the variation in x; the rest is left in the residuals.

When only summary statistics are given, the formula sheet route is enough. With x̄ = 10, sx = 4, ȳ = 50, sy = 8 and r = 0.75: b1 = 0.75 × 8/4 = 1.5 and b0 = 50 − 1.5 × 10 = 35, so at x = 12 the prediction is 35 + 18 = 53.

Extrapolation, predicting far outside the range of the x values, is risky: the straight pattern may not continue. On the TI-84, use DiagnosticOn once, then STAT, CALC, LinReg(ax+b) L1, L2: "a" is the slope b1 and "b" is the intercept b0. In R: lm(y ~ x).

Common trapThe TI-84 calls the slope a and the intercept b, the opposite of the letters in ŷ = b0 + b1 x. Read the output carefully.

Key takeaways

  • Scatterplot: direction, form, strength, unusual features.
  • r = Σzxzy/(n − 1), between −1 and 1, no units, linear only.
  • Conditions: quantitative, straight enough, no dominant outliers.
  • b1 = r sy/sx; b0 = ȳ − b1 x̄.
  • Residual e = y − ŷ; least squares minimises Σe2.
  • R2 = r2; beware of extrapolation and lurking variables.

Loading cards
Question
Click, tap or press space to flip
Answer

Multiple choice (10)

Question 1 · Chapter 4

A firm wants to predict revenue from its promotion budget. The response variable is...

Why: The response is what you predict.
Question 2 · Chapter 4

r = −0.85 means...

Why: Close to −1.
Question 3 · Chapter 4

Which change leaves r unchanged?

Why: r is unaffected by changes of unit.
Question 4 · Chapter 4

With r = 0.6, sx = 5 and sy = 20, the slope b1 is...

Why: 0.6 × 20/5.
Question 5 · Chapter 4

Means x̄ = 8 and ȳ = 30 with b1 = 2.5. The intercept is...

Why: 30 − 2.5 × 8.
Question 6 · Chapter 4

A house is predicted at 310,000 euro but sold for 295,000 euro. The residual is...

Why: e = y − ŷ.
Question 7 · Chapter 4

R output: intercept 4,700, slope 0.25 (benefits in euro per euro of salary). Predicted benefits at a salary of 120,000 euro?

Why: 4,700 + 0.25 × 120,000.
Question 8 · Chapter 4

r = 0.9 between a city's number of churches and its number of bars. The best explanation?

Why: Population drives both.
Question 9 · Chapter 4

r = 0.7. What share of the variation in y does the line account for?

Why: R2 = 0.72.
Question 10 · Chapter 4

The data cover x from 1 to 10. Predicting at x = 40 is...

Why: Far outside the data range.

Exam-style open questions (2)

Open question · Chapter 4

Line from summary statistics

For 40 flats, floor area has mean 80 m2 and SD 20 m2; monthly rent has mean 950 euro and SD 180 euro; r = 0.8. Find the line, interpret the slope, and predict the rent of a 100 m2 flat.

Show the worked outline
  • b1 = 0.8 × 180/20 = 7.2 euro per m2.
  • b0 = 950 − 7.2 × 80 = 374 euro.
  • Each extra m2 goes with 7.2 euro more rent on average.
  • Predicted rent at 100 m2: 374 + 720 = 1,094 euro. R2 = 0.64.
Open question · Chapter 4

Correlation by z-scores

Three points (x, y): (1, 2), (2, 3), (3, 7). Compute r with the z-score formula.

Show the worked outline
  • x̄ = 2, sx = 1; ȳ = 4, sy = √7 ≈ 2.646.
  • zx: −1, 0, 1; zy: −0.756, −0.378, 1.134.
  • Products: 0.756, 0, 1.134; sum 1.890; r ≈ 1.890/2 ≈ 0.945.

LabCorrelation and regression lab

The default data are the advertising example above.