Statistics & Probability

Linear Regression Calculator

Least-squares line through your data: slope, intercept, r², standard errors and predictions.

Tool no.
ECT-P03
Rev
1.0
Updated
Oct 2026
Method
Ordinary least squares
Examples

Given

Separate the numbers with spaces, commas or tabs. You can paste two columns straight from a spreadsheet; a header row is skipped.

Answers

Best-fit line —
Runs in your browser. Nothing you enter is uploaded.Ordinary least squares
How to use this calculator

Type or paste your data with x in the first column and y in the second, one point per line. The best-fit line, its statistics and the plot update as you type. Enter an x value to predict y there.

Formulas

SumsSxx = Σ(x − x̄)²  Sxy = Σ(x − x̄)(y − ȳ)  Syy = Σ(y − ȳ)²
Least-squares lineb1 = SxySxx  b0 = ȳ − b1x̄
Goodness of fitr² = 1 − SSESyy  se = √(SSEn − 2)  sb1 = se√Sxx

Worked example

Spring test: force 0 to 5 N, extension in mm (the default)

  1. x̄ = 2.5 N and ȳ = 5.1 mm.
  2. Sxx = 17.5, Sxy = 34.5 and Syy = 68.1.
  3. Slope b1 = 34.5/17.5 = 1.971 mm/N, so the spring rate is 1/1.971 = 0.507 N/mm.
  4. Intercept b0 = 5.1 − 1.971 × 2.5 = 0.171 mm, and r² = 0.9987.

Reading the results

r² is the fraction of the scatter in y that the line accounts for; lab calibrations usually reach 0.99 or better, while field data may sit at 0.7. The standard error of the slope tells you how precisely the slope is known: roughly, the true slope lies within about two standard errors of b1. Always look at the plot as well. A curved pattern or a single stray point can give a high r² and a misleading line.

Assumptions and limits

  • The relationship is a straight line, and the scatter is in y only, with similar size across the range.
  • Points are independent. Predictions outside the range of your x data are extrapolation.
  • For curves such as exponential decay, fit a straight line to the logarithm of y instead.

Frequently asked questions

What is the difference between r and r²?

r is the correlation coefficient, from −1 to 1, and its sign matches the slope. r² is its square, the share of the variation explained by the line.

Should I force the line through zero?

Only if physics guarantees y = 0 at x = 0 and your instrument has no offset. Otherwise the fitted intercept captures real zero errors, which is usually what you want.

How many points do I need?

At least 3 for any statistics, and preferably 6 or more spread evenly over the range you care about.