Statistics

Linear Regression Calculator

Fit the best straight line through paired data and predict new values — with r² showing honestly how well that line actually fits.


Linear Regression Calculator

Advertisement

Linear regression finds the straight line that best fits a set of paired data points. This computes that line’s slope and intercept, and predicts a new value from it — alongside r², which says honestly how well the line actually describes the data.

How it works

Least-squares regression line

y = m x + b  ·  m = Σ((x−x̄)(y−ȳ)) / Σ(x−x̄)²  ·  b = ȳ − m x̄

This is the ordinary least-squares fit — the line that minimises the sum of squared vertical distances from every point to the line itself.

The line is always drawn, whether or not it is the right shape

Least squares always returns a straight line — it has no way to say “actually, a curve fits this data much better.” That is exactly what r² is for: a low r² alongside a confidently drawn line is this calculator’s way of telling you the line does not describe the data well, even though the arithmetic behind it is entirely correct. r² specifically means the proportion of the variation in Y that the line accounts for — an r² of 0.6 means the line explains 60% of the spread in Y, leaving 40% unexplained by a straight-line relationship with X.

Interpolating versus extrapolating

The line is fitted to the range of X-values you supplied. Using it to predict far outside that range assumes the same straight-line pattern keeps holding beyond where you have any evidence for it — the data itself says nothing about what happens out there, and a prediction far outside the original range should be treated with real caution.

How to use this calculator

  1. Enter your X values and matching Y values.
  2. Optionally, enter a new X value to predict a Y for.
  3. Read the equation, the slope and intercept, and r² for how well it actually fits.

Frequently asked questions

What’s the difference between this and the correlation calculator?

Correlation (r) measures how strongly two variables move together. Regression goes a step further and produces an actual equation you can use to predict one from the other. r² here is simply r squared — the two calculators are closely related, using the same underlying arithmetic.

Can I trust a prediction far outside my data’s range?

Only with real caution. The regression line is fitted to, and only validated within, the range of X-values you provided — extrapolating far beyond that range assumes the same pattern continues, which your data cannot confirm.

What does a negative slope mean?

As X increases, Y tends to decrease — an inverse relationship. The line still fits the same way; only its direction changes.

Why is r² always between 0 and 1, unlike r itself?

Because it is r squared, and squaring any number between −1 and 1 removes the sign, always landing between 0 and 1. An r² of 1 means a perfect fit; an r² of 0 means the line explains none of the variation in Y.

What if all my X values are identical?

The slope is undefined — a vertical spread of X with no variation gives least squares nothing to fit a line’s angle against, so this calculator declines that input rather than returning an undefined or infinite slope.

Be the first to rate this

Written by

J. Adeyemi

Statistics writer

J. Adeyemi writes the statistics and probability calculators, from descriptive summaries through to distributions and conditional probability. The recurring theme is scope: each page states precisely which question it answers, because most statistical mistakes come from applying a correct formula to the wrong question. Related-but-different measures get separate pages rather than being quietly merged.

Reviewed by

K. Novak

Calculator reviewer — statistics

K. Novak reviews the statistics and probability calculators, checking formula correctness and the scope boundary each page draws around itself. Closely related measures are routinely confused with one another, so review confirms that a page computing one of them says clearly that it is not computing the others.

How we write and review

Related calculators