Advanced Mathematics

Correlation and Regression

Measuring how closely two quantities move together, and fitting the straight line that best predicts one from the other.

Needs a step first: 5

For paired data, the correlation coefficient rr, between −1-1 and 11, measures how close the points lie to a straight line. The least-squares regression line y=a+bxy=a+bx has slope b=Sxy/Sxxb=S_{xy}/S_{xx}, passes through the point of means (xˉ,yˉ)(\bar x,\bar y), and explains a share r2r^2 of the variation in yy. Correlation does not show cause, and the line should not be trusted far outside the data. It is the statistician's view of least squares and the start of linear regression in machine learning.

Where it shows up: Linear regression in machine learning is the same fit with many inputs at once, found by least squares or by gradient descent.

How to hold it: Give it to the machine, then check

Let software compute rr and the regression line; check that the line passes through (xˉ,yˉ)(\bar x,\bar y), that the sign of its slope matches the scatter plot and that r2r^2 is believable before trusting any prediction.

What knowing it looks like

  • Compute the correlation coefficient and the regression line by hand for a small data set.
  • Interpret the slope, the intercept and r2r^2 in the context of the data.
  • Give an example of a strong correlation without causation, and of a strong relationship that rr misses because it is not straight.

Test yourself

For the data (1,2)(1,2), (2,4)(2,4), (3,5)(3,5), (4,4)(4,4), (5,5)(5,5), find the regression line of yy on xx and the correlation coefficient rr.
Show the worked answer
xˉ=3\bar x=3, yˉ=4\bar y=4. Deviations in xx: −2,−1,0,1,2-2,-1,0,1,2; in yy: −2,0,1,0,1-2,0,1,0,1. So Sxy=4+0+0+0+2=6S_{xy}=4+0+0+0+2=6, Sxx=10S_{xx}=10, Syy=4+0+1+0+1=6S_{yy}=4+0+1+0+1=6. Slope b=0.6b=0.6, intercept a=4−0.6×3=2.2a=4-0.6\times3=2.2: the line is y=2.2+0.6xy=2.2+0.6x. Then r=610×6=0.6≈0.77r=\frac{6}{\sqrt{10\times6}}=\sqrt{0.6}\approx0.77, so the line explains r2=60%r^2=60\% of the variation in yy.

Needs a step first: 5

Learn it with an AI

Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.

Be my maths tutor. I'm learning "Correlation and Regression" (Core tier): Measuring how closely two quantities move together, and fitting the straight line that best predicts one from the other.
I already know: Random Variables, Expectation and Variance.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: For the data $(1,2)$, $(2,4)$, $(3,5)$, $(4,4)$, $(5,5)$, find the regression line of $y$ on $x$ and the correlation coefficient $r$.
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.

On the way to

Recommended