esc
Calculators

Linear regression calculator:
line of best fit

Paste X and Y values and get the equation of the best straight line through them, how well it fits and a predicted Y for any X you type.

The predictor, in the same order as Y.
Regression lineŷ = 2.2 + 0.6xR² = 0.6
Predicted Y at X = 6
5.8
Slope (b)
0.6
Intercept (a)
2.2
R²
0.6
Correlation (r)
0.7746
Points (n)
5
Residual standard error
0.8944272
Standard error of the slope
0.2828427
Standard error of the intercept
0.9380832
p-value for the slope (two-tailed)
0.124027
Fitted values and residuals
XYPredicted ŷResidual
122.8-0.8
243.40.6
3541
444.6-0.6
555.2-0.2
  • Least squares: b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², a = ȳ − b x̄. The line makes the sum of squared residuals as small as possible.
  • Predictions far outside the range of your X values are guesses: the straight-line pattern may not continue.

How to use Linear regression calculator

  1. 01Paste X and YSame number of values.
  2. 02Type an X to predictOptional.
  3. 03Read the equationWith R² and residuals.
File character arranging marked pages

The least-squares line.

Least squares picks the line that makes the sum of squared vertical distances (residuals) from the points as small as possible. The slope is b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and the intercept is a = ȳ − b x̄. The standard error of the slope gives a t-test of whether the slope differs from zero.

At a glance

Price
Free. No sign-up, no watermark.
Privacy
Your text stays in your browser. Nothing is uploaded.
Works in
Chrome, Edge, Firefox and Safari, on phones and computers

Questions

Can you show a small worked example?

For X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5: x̄ = 3, ȳ = 4, Σ(x − x̄)(y − ȳ) = 6 and Σ(x − x̄)² = 10, so b = 0.6 and a = 4 − 0.6 × 3 = 2.2. The line is ŷ = 2.2 + 0.6x, with R² = 0.6, and it predicts 5.8 at X = 6.

What is a residual?

The actual Y minus the Y the line predicts. A good fit has residuals that are small and scattered without a pattern; a curve in the residuals means a straight line is the wrong model.

Is this the same as Excel’s LINEST or a trendline?

Yes. Ordinary least squares gives the same slope, intercept, R² and standard errors as LINEST, a chart trendline or a TI calculator’s LinReg.

Is what I type sent anywhere?

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