The two regression lines · Mathematics Class 11–12 | StemPy Lab
Course 17.3·Lesson 2 of 3
The two regression lines
The regression line of y on x is the straight line that makes the sum of the squared vertical misses as small as possible. It always passes through the point of the two means. There is a second line, of x on y, and the product of the two slopes is r2.
about 25 min1 simulation1 practice question1 Python program5 questions to check yourself
This lesson is free to read. Enroll free to keep your place and take the tests.
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
find the least squares line of y on x and the line of x on y;
use the slopes to find r, and use r to find a slope;
find the means, r and the ratio of the spreads from two given regression lines.
The line of best fit
The marks of five students rise with their study hours. We want one straight line that describes the pattern and lets us predict a mark from the hours. Many lines look reasonable. Which one is best?
For a line y^=a+bx, the residual of a point is the vertical miss y−y^. The least squares line makes ∑(y−y^)2 as small as possible. Using the three sums of the last lesson, it has
b=SxxSxy=rσxσy,a=yˉ−bxˉ.
Equivalently, the line passes through (xˉ,yˉ) and has the equation
y−yˉ=byx(x−xˉ).
The slope is written byx and called the regression coefficient of y on x. For the five students, byx=1050=5 and a=60−5×3=45. So y^=45+5x: each extra hour of study goes with 5 more marks. Notations differ: A-Level and AP write y^=a+bx, and IB writes y=ax+b. The line is the same.
The other line
We can also ask for a line that predicts x from y. Now the misses are measured horizontally, and the line is
x−xˉ=bxy(y−yˉ),bxy=SyySxy=rσyσx.
For the five students, bxy=25650=0.195. The line is x=−8.72+0.195y.
A scatter plot of five points, study hours 1 to 5 against marks 50, 56, 58, 66 and 70. A blue line, the regression of marks on hours, rises steeply through the point (3, 60). A red line, the regression of hours on marks drawn in the same picture, rises less steeply and also passes through (3, 60). A black dot at (3, 60) marks the point of the two means where the lines cross.
The two lines are not the same line written differently. They both pass through (xˉ,yˉ), and they cross there. The nearer the points are to a line, the closer the two lines are to each other. If r=±1 they coincide. If r=0, the line of y on x is horizontal and the line of x on y is vertical.
Facts that link the two lines
byx×bxy=r2, so r=±byxbxy, with the sign of the two slopes. Both slopes have the sign of r.
So byxbxy≤1. If a pair of lines gives a product above 1, the lines were assigned the wrong way round.
Use the line of y on x to predict y from x. Use the line of x on y to predict x from y. Do not rearrange one into the other.
A worked example from two lines
The regression lines of a data set are 4x−5y+60=0 and 20x−9y−20=0. Find the means, which line is which, and r.
The means. Both lines pass through the point (xˉ,yˉ). Solving them, xˉ=10 and yˉ=20.
Try the first as y on x. Its slope is byx=54=0.8. The second then is x on y: x=209y+1, so bxy=0.45.
The test.0.8×0.45=0.36≤1, so this assignment is possible. The other way gives byx=920 and bxy=45, with product 2.78>1, which is impossible.
The coefficient.r=+0.36=0.6, positive because both slopes are positive.
The spreads.σxσy=rbyx=0.60.8=34.
Practise with new numbers
Try it in Python
The program finds both regression lines for the hours and the marks, checks that the product of the slopes is r2, and predicts the mark for 3.5 hours.
Common mistakes
Using the wrong line to predict. To predict x from y, use the line of x on y.
Turning the line of y on x round to get the other line. The slope of the other line is SyySxy, not byx1.
Forgetting the sign.r has the sign of byx and bxy.
Taking the root of a product above 1. Then the assignment of the lines is wrong.
Forgetting that the lines meet at the means.
Remember these
byx=SxxSxy=rσxσy, bxy=SyySxy=rσyσx, and byxbxy=r2.
Both lines pass through (xˉ,yˉ).
The least squares line makes the sum of the squared vertical residuals smallest.
y−yˉ=byx(x−xˉ) and x−xˉ=bxy(y−yˉ).
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Data have xˉ=4, yˉ=10, r=0.8, σx=2 and σy=5. Find the line of y on x.
For the same data, find the line of x on y.
The two regression coefficients of a data set are 1.2 and 0.3. Find r.
A student says that the two regression coefficients of a data set are 1.5 and 0.9. Is this possible?
Why does the line of y on x always pass through (xˉ,yˉ)?
References
OpenStax, Introductory Statistics, Chapter 12, sections on the regression equation and the least squares line.
A-Level, IB and AP texts all give b=SxxSxy for the regression of y on x. The regression of x on y and the product byxbxy=r2 are standard in Indian texts.
Enroll free in Correlation and Regression
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.