🧮
🧮 Math & statistics

Linear Regression Calculator (least squares)

Results update as you type.

Your numbers

Understanding the linear regression calculator — concept and principle

Simple linear regression finds the straight line y = bx + a that best fits a set of (x, y) points, so you can describe a trend and predict y for a new x. It is used for calibration curves, cost versus volume, sales trends and countless lab exercises.

Least-squares line through five pointsThe fitted line y = 1.96x + 0.22 rises 1.96 for every step of 1 in x, passes almost exactly through the five points (R² = 0.9989) and predicts 11.98 at x = 6.One straight line through the points0123456+1.96+111.980.22slope1.96intercept0.22R²0.9989predict x = 61.96×6 + 0.22= 11.98y = 1.96x + 0.22
Each step in x adds 1.96 to y; the line predicts 11.98 at x = 6.

How it is calculated

The slope is in "units of y per unit of x"; the intercept is in units of y.

The principle

"Least squares" means the line is chosen to make the sum of squared vertical errors as small as possible. Setting the derivatives of that sum with respect to a and b to zero gives the two formulas above, and they guarantee that the line passes through the point of means (x̄, ȳ). Squaring penalises large misses more than small ones and makes the solution unique. Legendre published the method in 1805 and Gauss later gave it a probabilistic justification. The divisor n − 2 reflects the two parameters estimated from the data.

Worked example

  1. X = 1, 2, 3, 4, 5 and Y = 2.2, 4.1, 6.2, 7.9, 10.1. Means: x̄ = 3, ȳ = 6.1.
  2. Σ(x − x̄)(y − ȳ) = 19.6 and Σ(x − x̄)² = 10, so slope b = 1.96.
  3. Intercept a = 6.1 − 1.96 × 3 = 0.22. Line: y = 1.96x + 0.22.
  4. Residuals: 0.02, −0.04, 0.10, −0.16, 0.08, so SSR = 0.044. SST = 38.46.
  5. R² = 1 − 0.044 ÷ 38.46 = 0.9988559542; standard error = √(0.044 ÷ 3) = 0.1211060142.
  6. Prediction at x = 6: 1.96 × 6 + 0.22 = 11.98.

How to read the result

The slope says y rises by 1.96 for each one-unit rise in x. R² near 1 means the points lie almost exactly on the line; values around 0.5 mean a lot of scatter. The standard error (0.12 here) gives the scale of typical prediction errors: roughly two standard errors either side of ŷ covers most points if the residuals are normal. Predicting at x = 6 is a small extrapolation beyond the data range (1 to 5).

Common mistakes

Keep in mind: The line describes association in these data, not cause and effect, and the inference assumes independent errors with constant variance.

Frequently asked questions

Can the intercept be meaningless?

Yes. If x = 0 is outside the data (for example, a height of 0 cm), the intercept is just a mathematical anchor for the line.

How is R² related to the correlation coefficient?

In simple linear regression R² equals r², where r is Pearson's correlation between x and y.

How many points do I need?

At least 3 for this calculator, but reliable slopes usually require many more, especially when the data are noisy.

Sources: NIST/SEMATECH e-Handbook of Statistical Methods, Section 4.1.4.1 Linear Least Squares Regression. · Montgomery, D. C., Peck, E. A. & Vining, G. G. Introduction to Linear Regression Analysis. Wiley.

Checked 8 Nov 2026. Standard formulas, computed in your browser with double-precision numbers.

🧮 All math & statistics tools →🌍 Calculators by country →