A brief note on The Least-Squares Line . Read it before a test. Try each question at the end before you open its answer.
Residuals Residual: y − y ^ y - \hat{y} y − y ^ , observed minus predicted. Above the line it is positive. SSE: the sum of the squared residuals, the score of a line. Least squares: the one line with the smallest SSE. Its residuals add up to 0 0 0 . The line Slope: b = r s y s x = S x y S x x b = r\,\dfrac{s_y}{s_x} = \dfrac{S_{xy}}{S_{xx}} b = r s x s y = S xx S x y , in units of y y y per unit of x x x . Intercept: a = y ˉ − b x ˉ a = \bar{y} - b\bar{x} a = y ˉ − b x ˉ . The line passes through ( x ˉ , y ˉ ) (\bar{x}, \bar{y}) ( x ˉ , y ˉ ) . Prediction: y ^ = a + b x \hat{y} = a + bx y ^ = a + b x . Inside the data is interpolation. Outside is extrapolation, and risky. Direction: the line predicts y y y from x x x . Predicting x x x from y y y needs another line. Checking the line Residual plot: a random band means a straight line fits. A curve or a fan means it does not. r 2 r^2 r 2 : 1 − SSE S y y 1 - \dfrac{\text{SSE}}{S_{yy}} 1 − S y y SSE , the share of the variation in y y y accounted for. Back to r r r : r = ± r 2 r = \pm\sqrt{r^2} r = ± r 2 , with the sign of the slope. A worked example Five made-up students revised for 1 1 1 to 5 5 5 hours and scored 52 52 52 , 55 55 55 , 61 61 61 , 62 62 62 and 70 70 70 marks.
Means and sums. x ˉ = 3 \bar{x} = 3 x ˉ = 3 hours, y ˉ = 60 \bar{y} = 60 y ˉ = 60 marks, S x x = 10 S_{xx} = 10 S xx = 10 and S x y = 43 S_{xy} = 43 S x y = 43 . The line. b = 4.3 b = 4.3 b = 4.3 marks per hour and a = 60 − 4.3 × 3 = 47.1 a = 60 - 4.3 \times 3 = 47.1 a = 60 − 4.3 × 3 = 47.1 marks, so y ^ = 47.1 + 4.3 x \hat{y} = 47.1 + 4.3x y ^ = 47.1 + 4.3 x . Prediction. For 3.5 3.5 3.5 hours, y ^ = 47.1 + 4.3 × 3.5 = 62.15 \hat{y} = 47.1 + 4.3 \times 3.5 = 62.15 y ^ = 47.1 + 4.3 × 3.5 = 62.15 marks. And r 2 = 0.9531 r^2 = 0.9531 r 2 = 0.9531 . Practice with new numbers
A program to try The program finds the line, the prediction and r 2 r^2 r 2 of the worked example.
Run it. Which line prints the answer to step 3?
1. Predict for 10 10 10 hours by changing 3.5 to 10. Why should you not trust that answer?
Mistakes to avoid Residual the wrong way round. Observed minus predicted. The ratio upside down. s y s_y s y goes on top in the slope. Reading r r r as the share explained. The share is r 2 r^2 r 2 . Trusting a high r r r without the residual plot. Check yourself A line predicts 25 25 25 and the observed value is 21 21 21 . What is the residual? Stuck? Show a hint Show the answerFor some data r = 0.5 r = 0.5 r = 0.5 , s x = 2 s_x = 2 s x = 2 , s y = 8 s_y = 8 s y = 8 , x ˉ = 4 \bar{x} = 4 x ˉ = 4 and y ˉ = 20 \bar{y} = 20 y ˉ = 20 . Find the least-squares line. Stuck? Show a hint Show the answerA line has r = − 0.9 r = -0.9 r = − 0.9 . What share of the variation in y y y does it account for? Stuck? Show a hint Show the answerThe residuals of a line are positive at both ends and negative in the middle. What does that mean? Stuck? Show a hint Show the answerSources OpenStax, Introductory Statistics , Chapter 12 (Linear Regression and Correlation).