Learn on your own. Parents beside you. Teachers guide.

Lemonmath
Tiếng Việt

Two-variable data and linear regression

Lesson 2.2 · 50 min read · Updated

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 xx on the horizontal axis and the response variable yy 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 rr is that number: it measures the direction and strength of a linear relationship. It satisfies −1≤r≤1-1\le r\le1, has no units, and is not changed by switching xx and yy or by changing units. Many students trip over the next point: a value near 00 means no linear relationship, not necessarily no relationship.

123456789405060708090xyO
Hours studied and test score for 1111 students, with the least-squares line

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 y^=a+bx\hat y=a+bx is the line that makes the sum of squared residuals as small as possible. From the summary statistics of the data, b=r sysx,a=yˉ−bxˉ,b=r\,\frac{s_y}{s_x},\qquad a=\bar y-b\bar x, so the line always passes through the point (xˉ,yˉ)(\bar x,\bar y), the point of means. The hat on y^\hat y means predicted value, not an actual one.

  • Slope: "For each additional [unit of xx], the predicted [yy] increases (decreases) by bb [units of yy]."
  • Intercept: "The predicted [yy] when [xx] =0=0 is aa." Say this only if x=0x=0 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

Exercise 1

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 and how to start

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.

Exercise 2

Using the same model, a 3-year-old car sells for 20 thousand dollars. Find and interpret its residual.

What you need and how to start

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.

Exercise 3

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 and how to start

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.

Exercise 4

For the data in the previous exercise, find r^2 and interpret it in general terms.

What you need and how to start

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.

Exercise 5

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 and how to start

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

Exercise 6

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 and how to start

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.

Exercise 7

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 and how to start

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.

Exercise 8

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 and how to start

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.

Exercise 9 Challenge

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 and how to start

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.

Mini test

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

Question 1. A least-squares line has slope -2.3. The correlation r is
Question 2. A residual is computed as
Question 3. Which value of r shows the strongest linear relationship?
Question 4. Predicting y for an x-value far outside the data is called

Part II. True or false

Question 1. A least-squares line is \hat y=5+2x and r=0.9. Decide whether each statement is 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.

Part III. Short answer

Question 1. For \hat y=5+2x, find the predicted value when x=7.

Question 2. If r=0.9, find r^2.

Show answers and explanations
  1. Part I, question 1: C. The correlation has the same sign as the slope.
  2. Part I, question 2: A. Residual =y-\hat y.
  3. Part I, question 3: D. Strength depends on the size of |r|.
  4. Part I, question 4: B. Extrapolation is unreliable.
  5. Part II, question 1: a) True; b) True; c) True; d) False. Correlation does not show causation.
  6. Part III, question 1: 19. 5+2(7)=19.
  7. Part III, question 2: 0.81. 0.9^2=0.81.
📈 My progress

Finding Lemonmath useful?

Send this page to a friend, a parent or a teacher who could use it. Studying on your own is easier with company, and Lemonmath is free for everyone.

Facebook ✉ Email