Account

What new tool do you want?

Math & Education

Linear Regression & Correlation Calculator

Fit a least-squares line to x,y data: slope, intercept, equation, R², Pearson correlation coefficient r — and predict y for any x.

How to use

  1. 1Enter one x,y pair per line (e.g. '1, 2.1').
  2. 2Optionally enter an x value to predict y.

How it's calculated

Slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)². Intercept a = ȳ − b x̄. r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² Σ(y − ȳ)²). R² = r².

Frequently asked questions

What does R² tell me?

The share of the variation in y explained by the line. R² = 0.8 means 80% of the variation is explained by x.

What's a strong correlation?

Rough guide: |r| above 0.7 is strong, 0.4–0.7 moderate, below 0.3 weak. Always plot your data too.

Does correlation mean causation?

No — a third factor could drive both, or the relationship could be coincidence.

Why 'least squares' means minimizing squared distance, not plain distance

The fitted line is the one where Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² — the slope formula — minimizes the sum of squared vertical gaps between each point and the line, not the sum of plain gaps. Squaring is what makes the problem solvable with a clean formula (rather than needing iterative search) and it penalizes big misses more than small ones, which pulls the line toward reducing any single large outlier's distance.

r and R² measure the same thing on different scales

R² is literally r squared, which is why it's always between 0 and 1 even when the correlation itself is negative. The near-perfect default example (slope ≈ 1.99, intercept ≈ 0.05) has R² ≈ 0.998, meaning about 99.8% of the variation in y is explained by x — as close to a straight line as real data gets. A rough guide: |r| above 0.7 is a strong relationship, 0.4–0.7 moderate, below 0.3 weak, but always look at a scatter plot too, since a handful of outliers can produce a misleadingly high or low r.

Predicting outside your data range is a different kind of guess

The predict field will happily compute y for any x you enter, but a prediction at x = 10 from data that only spans x = 1 to 5 is extrapolation — the line is assumed to keep behaving the same way outside the range where you actually have evidence, which often isn't true. And regardless of how high R² is, a strong fit never proves x causes y: a third variable, or plain coincidence, can produce the same pattern.

Leaving the prediction blank hides it, and a flat y is called a perfect correlation

The predict box is optional. While it is empty I get the line, the slope, the intercept, the correlation, and R squared, and no predicted-y row. Typing an x adds that row, even if the x sits far outside the points I entered. Each line has to be an x and a y. A line I write wrong is rejected with its line number, and I need at least two points. If every x is the same, the fit stops, because a vertical line has no slope. If every y is the same and the x values differ, the correlation is reported as 1 rather than left blank, and the slope comes out at zero.

Related tools

More: Math & Education