A brief note on Correlation and Regression . Read it before a test. Try each question at the end before you open its answer.
Correlation Sums: S x x = ∑ ( x − x ˉ ) 2 S_{xx} = \sum (x - \bar{x})^2 S xx = ∑ ( x − x ˉ ) 2 , S y y = ∑ ( y − y ˉ ) 2 S_{yy} = \sum (y - \bar{y})^2 S y y = ∑ ( y − y ˉ ) 2 , S x y = ∑ ( x − x ˉ ) ( y − y ˉ ) S_{xy} = \sum (x - \bar{x})(y - \bar{y}) S x y = ∑ ( x − x ˉ ) ( y − y ˉ ) . Coefficient: r = S x y S x x S y y r = \dfrac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}} r = S xx S y y S x y , with − 1 ≤ r ≤ 1 -1 \le r \le 1 − 1 ≤ r ≤ 1 and no unit. Meaning: r r r measures straight-line association only. r = 0 r = 0 r = 0 does not mean no relationship. Changes: adding a number or multiplying by a positive number leaves r r r unchanged. A negative multiplier flips its sign. Rank correlation: r s = 1 − 6 ∑ d 2 n ( n 2 − 1 ) r_s = 1 - \dfrac{6\sum d^2}{n(n^2 - 1)} r s = 1 − n ( n 2 − 1 ) 6 ∑ d 2 . Regression y y y on x x x : y − y ˉ = b y x ( x − x ˉ ) y - \bar{y} = b_{yx}(x - \bar{x}) y − y ˉ = b y x ( x − x ˉ ) , with b y x = S x y S x x = r σ y σ x b_{yx} = \dfrac{S_{xy}}{S_{xx}} = r\dfrac{\sigma_y}{\sigma_x} b y x = S xx S x y = r σ x σ y . x x x on y y y : x − x ˉ = b x y ( y − y ˉ ) x - \bar{x} = b_{xy}(y - \bar{y}) x − x ˉ = b x y ( y − y ˉ ) , with b x y = S x y S y y = r σ x σ y b_{xy} = \dfrac{S_{xy}}{S_{yy}} = r\dfrac{\sigma_x}{\sigma_y} b x y = S y y S x y = r σ y σ x . Link: b y x b x y = r 2 b_{yx}\,b_{xy} = r^2 b y x b x y = r 2 . Both lines pass through ( x ˉ , y ˉ ) (\bar{x}, \bar{y}) ( x ˉ , y ˉ ) . Least squares: the sum of the squared vertical misses is smallest. Prediction and traps Interpolation is safe. Extrapolation is risky. r 2 r^2 r 2 is the share of the variation in y y y that the line explains. One odd point can change r r r and the line a lot. Correlation is not cause. Look for a lurking variable. Mixed groups can reverse a pattern. A worked example Study hours 1 , 2 , 3 , 4 , 5 1, 2, 3, 4, 5 1 , 2 , 3 , 4 , 5 and marks 50 , 56 , 58 , 66 , 70 50, 56, 58, 66, 70 50 , 56 , 58 , 66 , 70 .
The sums. x ˉ = 3 \bar{x} = 3 x ˉ = 3 , y ˉ = 60 \bar{y} = 60 y ˉ = 60 , S x x = 10 S_{xx} = 10 S xx = 10 , S y y = 256 S_{yy} = 256 S y y = 256 and S x y = 50 S_{xy} = 50 S x y = 50 . The correlation. r = 50 2560 = 0.988 r = \dfrac{50}{\sqrt{2560}} = 0.988 r = 2560 50 = 0.988 . The line of y y y on x x x . b = 50 10 = 5 b = \dfrac{50}{10} = 5 b = 10 50 = 5 and a = 60 − 15 = 45 a = 60 - 15 = 45 a = 60 − 15 = 45 , so y ^ = 45 + 5 x \hat{y} = 45 + 5x y ^ = 45 + 5 x . A prediction. At 3.5 3.5 3.5 hours, y ^ = 62.5 \hat{y} = 62.5 y ^ = 62.5 . At 12 12 12 hours it gives 105 105 105 , which is extrapolation and cannot be right. Practice with new numbers
A program to try The program finds r r r , the line of best fit and a prediction for a short data set.
Run it. Is r 2 r^2 r 2 the square of r r r ?
1. Change the last y y y value 11 to 3. What happens to r r r and to the slope?
Mistakes to avoid Reading r = 0 r = 0 r = 0 as no relationship. Reading a strong r r r as proof of cause. Using the line of y y y on x x x to predict x x x . Extrapolating far outside the data. Reading r r r as the share explained. It is r 2 r^2 r 2 . Check yourself Find r r r when S x x = 9 S_{xx} = 9 S xx = 9 , S y y = 16 S_{yy} = 16 S y y = 16 and S x y = 6 S_{xy} = 6 S x y = 6 . Stuck? Show a hint Show the answerThe regression coefficients are 0.8 0.8 0.8 and 0.45 0.45 0.45 . Find r r r . Stuck? Show a hint Show the answerThe line of y y y on x x x is y = 3 + 2 x y = 3 + 2x y = 3 + 2 x and x ˉ = 5 \bar{x} = 5 x ˉ = 5 . Find y ˉ \bar{y} y ˉ . Stuck? Show a hint Show the answerFor r = − 0.7 r = -0.7 r = − 0.7 , find the share of the variation in y y y explained by the line. Stuck? Show a hint Show the answerA line was fitted to data with x x x from 5 5 5 to 20 20 20 . Is it sensible to predict y y y at x = 80 x = 80 x = 80 ? Stuck? Show a hint Show the answerSources OpenStax, Introductory Statistics , Chapter 12 (Linear Regression and Correlation). A-Level, IB and AP Statistics texts on the product moment correlation coefficient and least squares regression.