Linear regression calculator
"Least squares" is literal: the best line makes the total area of these squares as small as possible. Nudge the line yourself and try to beat it.
10 pairs read.
- x̄ = 5.5, ȳ = 66.7
- b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = 260.5 / 82.5 = 3.1576
- a = ȳ − b·x̄ = 66.7 − 3.1576 × 5.5 = 49.3333
- r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² · Σ(y − ȳ)²) = 0.9872
Why it is called "least squares"
For each point, the residual is the vertical gap between the actual y and the line's prediction ŷ. Square each residual and you get an actual square, drawn in orange on the scatter plot. The least-squares line is the one line, out of all possible lines, that makes the total area of those squares as small as possible. Tick "Try to beat the best line" and move the sliders: you can match it, but never beat it. Carl Friedrich Gauss and Adrien-Marie Legendre both published the method around 1805–1809 for fitting planetary orbits.
Reading the output
- Slope b: the predicted change in y for each one-unit increase in x.
- Intercept a: the predicted y when x = 0 (which may be meaningless if x = 0 is far outside your data).
- r: strength and direction of the linear relationship, between −1 and 1. Roughly: |r| above 0.7 is strong, 0.3 to 0.7 moderate, below 0.3 weak.
- r²: the fraction of the variation in y explained by the line.
Cautions
Always look at the scatter plot. Anscombe's quartet (1973) is four data sets with the same r, slope and intercept that look completely different: one curved, one with a single wild outlier. Do not predict far beyond the range of your x values (extrapolation), and remember that correlation alone does not show causation.
Still not clicking? Ask the tutor
An AI tutor that sees the numbers you entered above and explains them. It can make mistakes, so check anything important against the worked steps.
Questions students ask
What is the least squares regression line?
The line ŷ = a + bx that makes the sum of squared vertical distances from the points to the line as small as possible. Its slope is b = r × (s_y / s_x) and it always passes through (x̄, ȳ).
What does the correlation coefficient r mean?
r measures the strength and direction of a linear relationship, from −1 (perfect downhill line) through 0 (no linear pattern) to +1 (perfect uphill line). It says nothing about curved patterns.
What is r squared?
r² is the share of the variation in y that the line explains. r² = 0.64 means 64% of the variation in y is accounted for by its linear relationship with x.
Does correlation mean causation?
No. A strong correlation can come from a lurking third variable, from coincidence or from reverse causation. Only a controlled experiment can establish cause.