Skip to content
LoveToCalc

Definition — what does that mean?

Least-squares line

The straight line that makes the squared vertical distances to it as small as possible.

In Swedish: Regressionslinje

Least-squares line

The relation

b=Σ(xi−x)(yi−y)Σ(xi−x)²

The straight line through a scatter of paired values that makes the sum of the squared vertical distances to it as small as possible: a slope read off the lists, and an intercept that puts the line through the point (x̄, ȳ).

Separate the numbers with spaces, commas or semicolons, for example 2.5, 4, 7

Separate the numbers with spaces, commas or semicolons, for example 2.5, 4, 7

b=0.6

b equals (((1 minus 3) times (2 minus 4)) plus ((2 minus 3) times (4 minus 4)) plus ((3 minus 3) times (5 minus 4)) plus ((4 minus 3) times (4 minus 4)) plus ((5 minus 3) times (5 minus 4))) divided by ((1 minus 3) squared plus (2 minus 3) squared plus (3 minus 3) squared plus (4 minus 3) squared plus (5 minus 3) squared), equals ((−2 times (−2)) plus ((−1) times 0) plus (0 times 1) plus (1 times 0) plus (2 times 1)) divided by ((−2) squared plus (−1) squared plus 0 squared plus 1 squared plus 2 squared), equals (4 plus 0 plus 0 plus 0 plus 2) divided by (4 plus 1 plus 0 plus 1 plus 4), equals 6 divided by 10, equals 0.6

Working5 steps

What the formula says

b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²

The least-squares line y = a + bx is the straight line closest to a scatter of paired values. Closest here means that the sum of the squared vertical distances from the points to the line is as small as possible, hence the name. The formula gives the slope b. It is a definition.

The intercept a then follows from the line always passing through the point (x̄, ȳ):

a = ȳ − b · x̄

That is a formula of its own, not a rearrangement of the first, so the card works out b only. Once b is known, a is one line of arithmetic.

Worked examples

Five pairs. x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5, the same pairs as on the correlation coefficient page. There the numerator came to 6 and the x list’s sum of squares to 10. The slope is b = 6 / 10 = 0.6.

The intercept. With x̄ = 3 and ȳ = 4, a = 4 − 0.6 · 3 = 2.2. The line is y = 2.2 + 0.6x.

A prediction. For x = 6 the line gives y = 2.2 + 0.6 · 6 = 5.8. That is reasonable as long as x stays near the values the line was built on; for x = 100, 62.2 would be a guess the line has no grounds for.

Common mistakes

Common questions

Why does the line always pass through (x̄, ȳ)? Because that is how the intercept is chosen. Putting x = x̄ into y = a + bx with a = ȳ − b · x̄ gives y = ȳ. That it is the right choice follows from least squares: a line that missed the centre point could be moved there and get a smaller sum of squares.

How is the slope related to the correlation coefficient? b = r · (s_y / s_x), where s_y and s_x are the lists’ standard deviations. They always have the same sign: a positive correlation gives a rising line. For the example, r ≈ 0.775 and b = 0.6.

Why can I not just solve for the intercept from scratch? Because a and b are settled together, by the two equations least squares produces. The formula card solves one equation at a time, so it works out b from the lists, and a follows from b. To solve a system of equations step by step, there is the system of equations calculator.

Looking for another letter? The formula solved for each one
Solved for each letter
Solve forRearrangedWith the numbersComes to
bΣ(xi−x)(yi−y)Σ(xi−x)²(1−3)(2−4)+(2−3)(4−4)+(3−3)(5−4)+(4−3)(4−4)+(5−3)(5−4)(1−3)²+(2−3)²+(3−3)²+(4−3)²+(5−3)²0.6

Last reviewed September 24, 2026 ·How pages are reviewed

Read more in articles

Statistics and probabilityAll formulas

Put this formula on your site

Copy the code into your page where the formula card should appear. It loads from lovetocalc.com, so it stays current on its own — all we ask is that the credit line comes with it.