Two-variable data and linear regression
🖨 Print a self-study sheet Why print?
If you know how many hours each student revised, can you guess their test score? Not exactly, student by student. But you can describe the general trend, and regression is the tool for that. Regression is Unit 5 of the revised course and has its own set of three multiple-choice questions on the exam, so it is worth secure marks. The arithmetic is light. Points come from interpretations written in context, with the right words: "predicted", "on average", "for each additional ...". Here we cover only what remains in the course; transformations to achieve linearity and inference for the slope have been removed.
Scatterplots and correlation
Every regression lesson starts with a picture. A scatterplot shows two quantitative variables measured on the same individuals: the explanatory variable on the horizontal axis and the response variable on the vertical axis. Looking at it, you should be able to say four things, always in context:
| Feature | What to say |
|---|---|
| Direction | positive or negative |
| Form | linear or curved |
| Strength | strong, moderate or weak |
| Unusual features | points far from the pattern, clusters |
A picture is not enough; we also want one number that says how tightly the points follow a straight line. The correlation is that number: it measures the direction and strength of a linear relationship. It satisfies , has no units, and is not changed by switching and or by changing units. Many students trip over the next point: a value near means no linear relationship, not necessarily no relationship.
The least-squares regression line
Many straight lines can be drawn through a cloud of points. Which one do we pick? The least-squares regression line is the line that makes the sum of squared residuals as small as possible. From the summary statistics of the data, so the line always passes through the point , the point of means. The hat on means predicted value, not an actual one.
- Slope: "For each additional [unit of ], the predicted [] increases (decreases) by [units of ]."
- Intercept: "The predicted [] when [] is ." Say this only if makes sense in the situation. Practise saying these two sentences aloud, swapping in the names and units of each problem.
Residuals and r^2
To see how far off a prediction is, we look at the residual. A residual is \text{residual}=y-\hat y=\text{actual}-\text{predicted}. A positive residual means the line underestimates that point. A residual plot (residuals against x) lets us check the whole model: if the residuals are scattered with no pattern, a linear model is supported; if they curve, a linear model is not appropriate.
Two last numbers tell us how good the model is. The coefficient of determination r^2 is the proportion of the variation in y that is accounted for by the linear model with x. The standard deviation of the residuals s is the typical size of a prediction error, that is, how far off a prediction usually is.
Limits of regression
- Extrapolation: predicting far outside the range of the x-values used to build the line is unreliable, because we do not know whether the pattern still holds there.
- Association is not causation: an observational data set can show a strong correlation because of a lurking variable that affects both x and y. Only a well-designed experiment can show cause and effect.
- Linear form: r and the least-squares line describe only linear patterns, so always look at the scatterplot and the residual plot. Regression gives us a prediction of the trend, and these three limits remind us not to ask more of it than that.
Similar exercises
A used-car model is \hat y=24-1.8x, where x is the age in years and y the price in thousands of dollars. Interpret the slope and the intercept in context.
What you need: the slope is the change in predicted y per unit of x; the intercept is the predicted y at x=0.
Show solution
The slope is -1.8: for each additional year of age, the predicted price of a used car decreases by 1.8 thousand dollars.
The intercept is 24: the predicted price of a car that is 0 years old, that is a new car, is 24 thousand dollars. This makes sense if new cars were in the age range of the data.
So the price is predicted to fall by 1800 dollars per year from a predicted 24{,}000 dollars when new.
Answer. Slope: -1.8 thousand dollars per year; intercept: 24 thousand dollars for a new car.
Using the same model, a 3-year-old car sells for 20 thousand dollars. Find and interpret its residual.
What you need: residual =y-\hat y.
Show solution
The predicted price is \hat y=24-1.8(3)=18.6 thousand dollars.
The residual is 20-18.6=1.4 thousand dollars.
So the residual is 1.4: this car sold for 1400 dollars more than the model predicts.
Answer. 1.4 thousand dollars; the model underestimates its price.
For a data set, \bar x=20, s_x=4, \bar y=65, s_y=10 and r=-0.6. Find the least-squares regression line.
What you need: b=r\,\dfrac{s_y}{s_x} and a=\bar y-b\bar x.
Show solution
The least-squares regression line has the form \hat y=a+bx, where the slope is b=r\cdot\dfrac{s_y}{s_x}.
Substituting r=-0.6, s_x=4, s_y=10, we get b=-0.6\cdot\frac{10}{4}=-1.5.
The regression line always passes through the point (\bar x, \bar y)=(20, 65), so \bar y=a+b\bar x. It follows that a=\bar y-b\bar x=65-(-1.5)(20)=65+30=95.
So the least-squares regression line is \hat y=95-1.5x.
Answer. \hat y=95-1.5x.
For the data in the previous exercise, find r^2 and interpret it in general terms.
What you need: square r.
Show solution
Squaring the correlation gives r^2=(-0.6)^2=0.36.
So 36\% of the variation in y is accounted for by the linear model with x, and the remaining 64\% is due to other factors.
Answer. r^2=0.36.
A scatterplot of the age of trees, in years, and their trunk diameter, in centimetres, shows points close to an increasing straight line with no unusual points, and r=0.92. Describe the relationship.
What you need: direction, form, strength, unusual features, in context.
Show solution
Since r=0.92 is positive and close to 1 and the points lie close to a line, the association is strong and positive.
There is a strong, positive, linear relationship between the age of a tree and its trunk diameter, with no unusual points: older trees tend to have wider trunks.
Answer. Strong, positive, linear, no unusual features.
Applied exercises
For a group of adults, height y in cm and arm span x in cm are related by \hat y=10+0.95x.
a) Predict the height of a person with arm span 170 cm.
b) That person is actually 168 cm tall. Find the residual.
What you need: substitute x=170, then compute actual minus predicted.
Show solution
a) The predicted height is \hat y=10+0.95(170)=10+161.5=171.5 cm.
b) The residual is 168-171.5=-3.5 cm.
So the predicted height is 171.5 cm, and the residual of -3.5 cm means the model overestimates this person's height.
Answer. a) 171.5 cm; b) -3.5 cm.
A model for the height of children aged 2 to 10 years is \hat y=80+6x, where x is age in years and y height in cm. Use it to predict the height of a 40-year-old, and comment.
What you need: compare x=40 with the range of the data.
Show solution
Substituting gives \hat y=80+6(40)=320 cm.
A height of 3.2 m is impossible. The model was built from children aged 2 to 10, and growth stops in adulthood, so using it at age 40 is extrapolation far beyond the data.
So the prediction of 320 cm is not reliable; the model should only be used for ages 2 to 10.
Answer. 320 cm, an unreliable extrapolation.
Data from many towns show a strong positive correlation between monthly ice cream sales and the number of swimming accidents. Does eating ice cream cause swimming accidents? Explain.
What you need: look for a lurking variable.
Show solution
No. These are observational data, so they cannot show cause and effect.
A lurking variable, hot weather, increases both ice cream sales and the number of people swimming, and more swimming leads to more accidents. This explains the correlation without ice cream causing accidents.
So the association is real, but it does not show that ice cream causes swimming accidents.
Answer. No; hot weather is a lurking variable.
For two variables, r=0.8, s_x=2 and s_y=6. If a value of x is one standard deviation above \bar x, by how much is its predicted y above \bar y?
What you need: b=r\,\dfrac{s_y}{s_x} and the line passes through (\bar x,\bar y).
Show solution
The slope is b=0.8\cdot\dfrac{6}{2}=2.4. An increase of one standard deviation in x is 2 units, so the predicted y increases by 2.4\times2=4.8.
In standard deviations of y, this is \dfrac{4.8}{6}=0.8=r: the prediction moves only r standard deviations, which is why the method is called regression.
So the predicted y is 4.8 units, that is 0.8 standard deviations, above \bar y.
Answer. 4.8 units.
Marked like the Vietnamese graduation exam: Part I 0.25 points per question; Part II up to 1 point per question (1, 2, 3, 4 correct statements give 0.1, 0.25, 0.5, 1 point); Part III 0.5 points per question.
Part I. Multiple choice
The correlation has the same sign as the slope.
Residual =y-\hat y.
Strength depends on the size of |r|.
Extrapolation is unreliable.
Part II. True or false
| a) The line passes through (\bar x,\bar y). | ||
| b) The predicted y when x=3 is 11. | ||
| c) r^2=0.81. | ||
| d) The relationship must be causal. |
Correlation does not show causation.
Part III. Short answer
5+2(7)=19.
0.9^2=0.81.
Show answers and explanations
- Part I, question 1: C. The correlation has the same sign as the slope.
- Part I, question 2: A. Residual =y-\hat y.
- Part I, question 3: D. Strength depends on the size of |r|.
- Part I, question 4: B. Extrapolation is unreliable.
- Part II, question 1: a) True; b) True; c) True; d) False. Correlation does not show causation.
- Part III, question 1: 19. 5+2(7)=19.
- Part III, question 2: 0.81. 0.9^2=0.81.