Least Squares Regression Line Calculator

Quick answer

The least squares regression line calculator fits the best straight line y = a·x + b through a set of points, with the correlation coefficient r and the coefficient of determination r².

Slope a
2.02
Intercept b
-0.02
Correlation r
0.999105
r²
0.998211
Predicted y
14.12
Number of points
6

The least squares line minimises the sum of squared vertical distances from the points to the line. It is the most common way to find a trend in data – sales over time, height versus weight, dose versus response.

How to use the Least Squares Regression Line Calculator

  1. x values
  2. y values (same order)
  3. Predict y at x =

Results update as you type, and everything is calculated in your browser.

How it works

The slope and intercept come from the means and the sums of products of the data. r measures the strength and direction of the linear relationship; r² is the share of the variation in y explained by the line.

Inputs explained

Field What to enter
x values A list of numbers separated by commas, spaces or new lines
y values (same order) A list of numbers separated by commas, spaces or new lines
Predict y at x = A number

What each result means

  • Slope a = slope([x values], [y values (same order)])
  • Intercept b = intercept([x values], [y values (same order)])
  • Correlation r = corr([x values], [y values (same order)])
  • r² = corr([x values], [y values (same order)])^2
  • Predicted y = slope([x values], [y values (same order)])×[Predict y at x =] + intercept([x values], [y values (same order)])
  • Number of points = min(count([x values]), count([y values (same order)]))

Example values

How the main result changes when Predict y at x = changes and everything else stays at the example values above:

Predict y at x = Slope a
3.5 2.02
5.25 2.02
7 2.02
8.75 2.02
10.5 2.02
14 2.02

Formula

a = (n·Σxy − Σx·Σy) ÷ (n·Σx² − (Σx)²), b = ȳ − a·x̄ r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² · Σ(y − ȳ)²]

Worked example

Inputs — x values: 1, 2, 3, 4, 5, 6; y values (same order): 2.1, 3.9, 6.2, 7.8, 10.1, 12.2; Predict y at x =: 7.
Results — Slope a = 2.02; Intercept b = -0.02; Correlation r = 0.999105; r² = 0.998211; Predicted y = 14.12; Number of points = 6.

Key terms

Residual
The vertical distance from a point to the line.
r²
The proportion of variance explained by the line.

Frequently asked questions

Why "least squares"?

The line makes the sum of the squared residuals as small as possible.

What does r = 0.99 mean?

A very strong positive linear relationship.

Is a high r² proof of causation?

No – correlation does not imply causation.

Can I predict far outside my data?

Extrapolation is risky; the relationship may not stay linear.

Sources

  1. OpenStax – Introductory Statistics 2e: Linear regression
  2. Wolfram MathWorld – Least squares fitting

Cite this calculator

Speedy Calculator. (2026). Least Squares Regression Line Calculator. Speedy Calculator. https://speedycalculator.com/calculators/math/least-squares-regression/