Squares Regression Line Calculator

This least squares regression line calculator finds the slope, intercept and equation of the best fit line from raw data or from summary statistics.

Checks on your data

  • The line passes through (x̄, ȳ), which is a built-in property of least squares.
  • Only predict inside the range of your x data. Outside it the prediction is an extrapolation.
  • Regression shows association. It does not prove that x causes y.

Results

Least squares regression line
ŷ = 0.17143 + 1.9786x
Slope (b)
1.97857
Intercept (a)
0.171429
Correlation r
0.997649
R²
0.995304
Line passes through (x̄, ȳ)
(4.5, 9.075)
Data with the least squares regression line (r = 0.998)
510152468xy
Calculation table
xyx − x̄y − ȳ(x − x̄)(y − ȳ)(x − x̄)²
12.3-3.5-6.77523.71212.25
24.1-2.5-4.97512.4386.25
35.8-1.5-3.2754.91252.25
48.4-0.5-0.6750.33750.25
59.70.50.6250.31250.25
612.51.53.4255.13752.25
713.62.54.52511.3136.25
816.23.57.12524.93812.25
Show step-by-step solution
  1. n = 8, x̄ = 4.5, ȳ = 9.075.
  2. Sxx = Σ(x − x̄)² = 42, Sxy = Σ(x − x̄)(y − ȳ) = 83.1.
  3. Slope b = Sxy ÷ Sxx = 1.97857.
  4. Intercept a = ȳ − b·x̄ = 9.075 − 1.97857 × 4.5 = 0.171429.
Slopeb = Sxy / Sxx = r·sy/sx
Intercepta = ȳ − b·x̄
Passes through(x̄, ȳ)

What Is Least Squares Regression Line?

The least squares regression line is the straight line ŷ = a + bx that makes the sum of squared vertical distances from the points as small as possible. It is the standard way to fit a line to paired data.

The slope is b = Sxy ÷ Sxx, or r × sy ÷ sx if you only have summary statistics. The intercept is a = ȳ − b·x̄, which forces the line through the point of means.

Choose raw data or summary mode, enter your values, and optionally add an x value to predict y.

How to Use the Least Squares Regression Line Calculator

  1. Choose raw data or summary statistics.
  2. Enter the values. For summary mode you need both means, both standard deviations and r.
  3. Read the slope, intercept and equation, and add an x value if you want a prediction.

Least Squares Regression Line Formula

Slope

b=∑(x−xˉ)(y−yˉ)∑(x−xˉ)2=r sysxb=\frac{\sum(x-\bar x)(y-\bar y)}{\sum(x-\bar x)^2}=r\,\frac{s_y}{s_x}

Intercept

a=yˉ−bxˉa=\bar y-b\bar x

Least Squares Regression Line Variables Explained

SymbolMeaningNotes
bSlope of the liner × sy / sx
aInterceptȳ − b·x̄
rCorrelation coefficient
ŷPredicted value of ya + bx

Least Squares Regression Line Worked Example

With the example values loaded in the calculator above, the steps are:

  1. n = 8, x̄ = 4.5, ȳ = 9.075.
  2. Sxx = Σ(x − x̄)² = 42, Sxy = Σ(x − x̄)(y − ȳ) = 83.1.
  3. Slope b = Sxy ÷ Sxx = 1.97857.
  4. Intercept a = ȳ − b·x̄ = 9.075 − 1.97857 × 4.5 = 0.171429.
  5. Prediction: ŷ = 0.17143 + 1.9786 × 9 = 17.9786.

Result: Least squares regression line = ŷ = 0.17143 + 1.9786x; Slope (b) = 1.97857.

Worked example from summary statistics

Suppose x̄ = 10, sx = 2, ȳ = 50, sy = 8 and r = 0.6.

Slope = 0.6 × (8 ÷ 2) = 2.4. Intercept = 50 − 2.4 × 10 = 26. The line is ŷ = 26 + 2.4x.

What the slope and intercept mean

The slope is the predicted change in y for each one unit increase in x. The intercept is the predicted y when x = 0, which is only meaningful if x = 0 is a sensible value in your data.

Where Least Squares Regression Line Is Used

Fitting a trend line

Get the equation of the best fit line through paired data.

Prediction

Estimate y for a new x inside the data range.

Statistics coursework

Find the line from means, standard deviations and r alone.

Common Least Squares Regression Line Mistakes to Avoid

  • Check that the scatter plot looks roughly linear before trusting the line.
  • Do not predict far outside the x values you measured.

Least Squares Regression Line Terms and Definitions

Least squares
A fitting rule that minimises the sum of squared vertical errors.
Residual
The observed y minus the predicted y for a point.

Least Squares Regression Line FAQs

How do you find the slope of the least squares regression line?

Divide Sxy, the sum of products of deviations, by Sxx, the sum of squared x deviations. With summary statistics it is r times sy divided by sx.

How do you find the intercept?

Subtract the slope times the mean of x from the mean of y.

Does the least squares line always pass through the means?

Yes. The point (x̄, ȳ) always lies on the line.

Can I get the line without the raw data?

Yes. Means, standard deviations and r are enough, using the summary mode.

Why squares and not absolute errors?

Squaring gives a single clean formula and treats large misses more heavily. Absolute errors need iterative methods.

Related calculators

Last updated 2026-11-09. See our disclaimer.