Linear Regression Calculator: Line of Best Fit y = a + bx with r² and Prediction

Enter X and Y values in pairs. You get the line of best fit, how well it fits (r²) and a prediction for any x you type.

Line of best fit

ŷ = 0.7333 + 2.1714x

Slope b
2.171429
Intercept a
0.733333
r² (coefficient of determination)
0.9902
Predicted y
15.9333

This x is outside your data range (1 to 6), so the prediction is an extrapolation and may be unreliable.

Least-squares fit; r² shows how much of the variation in y the line explains.

Show working
  1. x̄ = 3.5, ȳ = 8.333333
  2. Sxx = Σ(x − x̄)² = 17.5, Sxy = Σ(x − x̄)(y − ȳ) = 38
  3. b = Sxy / Sxx = 38 / 17.5 = 2.171429
  4. a = ȳ − b·x̄ = 8.333333 − 2.171429 × 3.5 = 0.733333
  5. r² = 1 − SSE/SST = 1 − 0.819048 / 83.333333 = 0.990171
  6. ŷ(7) = 0.733333 + 2.171429 × 7 = 15.933333

How to use

  1. Enter the X values, then the matching Y values in the same order.
  2. Optionally type an x to predict y.
  3. Read the equation, slope, intercept and r².

Good to know

Least squares: slope b = Sxy/Sxx and intercept a = ȳ − b·x̄. This is the line that makes the sum of squared vertical distances from the points as small as possible.

r² is the share of the variation in y explained by the line (0 to 1). The standard error of the estimate √(SSE/(n − 2)) is the typical size of a prediction miss, in y units.

Predicting outside the range of your x data (extrapolation) is risky: the straight-line pattern may not continue. The calculator warns you when you do it.

Questions

What is the regression line for x = 1…6, y = 3, 5, 7, 10, 11, 14?

ŷ = 0.7333 + 2.1714x, with r² ≈ 0.990.

What does the slope mean?

How much y changes on average when x goes up by 1. A slope of 2.17 means y rises about 2.17 per unit of x.

Is regression the same as correlation?

They are linked: r² is the same in both. Correlation measures strength; regression gives the actual line for predictions.

Can I fit a curve?

This tool fits a straight line only. For curved patterns try transforming the data (e.g. log of y) first.

Is my data stored or sent anywhere?

No. The calculation runs entirely in your browser; nothing you type leaves your device.

Last updated: