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:
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).
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:
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.
Means and SDs
z-score products
Correlation
Slope
Intercept
Prediction and residual
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).
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.
Multiple choice (10)
A firm wants to predict revenue from its promotion budget. The response variable is...
r = −0.85 means...
Which change leaves r unchanged?
With r = 0.6, sx = 5 and sy = 20, the slope b1 is...
Means x̄ = 8 and ȳ = 30 with b1 = 2.5. The intercept is...
A house is predicted at 310,000 euro but sold for 295,000 euro. The residual is...
R output: intercept 4,700, slope 0.25 (benefits in euro per euro of salary). Predicted benefits at a salary of 120,000 euro?
r = 0.9 between a city's number of churches and its number of bars. The best explanation?
r = 0.7. What share of the variation in y does the line account for?
The data cover x from 1 to 10. Predicting at x = 40 is...
Exam-style open questions (2)
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.
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.