Line of Best Fit
Drop a cloud of points and find the one line that fits them best — the least-squares line — then measure how strong the relationship really is with the correlation r. Grade 12 / first-year statistics.
Best in what sense?
Given a scatter of points, "best fit" needs a definition. For each point, the residual is the vertical gap between the point and the line — how badly the line misses it. The line of best fit is the one that makes the total of the squared residuals as small as possible. Squaring keeps every miss positive and punishes big misses hardest.
Fit the cloud 🔵
Drag the points around. The orange line re-fits instantly to minimise the total squared length of the dashed purple residuals. Watch r climb toward ±1 as the cloud tightens onto a line.
How strong is the link?
Correlation r
r runs from −1 to +1. Near +1 the cloud hugs an uphill line; near −1, a downhill one; near 0 there's no linear pattern at all. It measures tightness, not steepness.
r² — variance explained
Square r and you get the fraction of the ups-and-downs in y that the line accounts for. r² = 0.9 means the line explains 90% of the variation; the rest is scatter.
One neat fact you can check in the demo: the best-fit line always passes through the mean point (x̄, ȳ), marked with a green ring. The whole cloud balances there, whichever way you tilt it. And beware — a strong r shows a linear relationship, not proof that one thing causes the other.