# Least Squares Regression Line Calculator

URL: https://speedycalculator.com/calculators/math/least-squares-regression/
Last updated: 2026-10-30

> 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².

## Inputs

- x values
- y values (same order)
- Predict y at x =

## Results

- Slope a
- Intercept b
- Correlation r
- r²
- Predicted y
- Number of points

## Formula

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

## Explanation

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

- **x values**
- **y values (same order)**
- **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

FieldWhat to enterx valuesA list of numbers separated by commas, spaces or new linesy values (same order)A list of numbers separated by commas, spaces or new linesPredict 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 a3.52.025.252.0272.028.752.0210.52.02142.02

## 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.

## FAQ

**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

- [OpenStax – Introductory Statistics 2e: Linear regression](https://openstax.org/details/books/introductory-statistics-2e)
- [Wolfram MathWorld – Least squares fitting](https://mathworld.wolfram.com/LeastSquaresFitting.html)
