Linear regression calculator

Enter your x values and y values to fit the best straight line, y = slope × x + intercept. The tool also reports the correlation r and R², and predicts y for an x you choose.

Separate numbers with commas, spaces or semicolons.
The same count as the x values, in the same order.
Optional. Leave empty to skip.
Regression liney = 0.6x + 2.2
Slope (b)
0.6
Intercept (a)
2.2
Correlation coefficient (r)
0.77459667
Coefficient of determination (R²)
0.6
Number of points
5
Predicted y
5.8

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Enter the x values and the y values, in the same order and the same count.
  2. Optionally enter an x to predict y for.
  3. Read the equation, r and R², and the prediction.

How it works

The calculation uses sums of deviations from the means, which avoids the rounding errors of the raw-sum shortcut. Sxx = Σ(x − x̄)², Sxy = Σ(x − x̄)(y − ȳ), Syy = Σ(y − ȳ)². Then slope = Sxy / Sxx, intercept = ȳ − slope × x̄ and r = Sxy / √(Sxx × Syy).

Worked example

x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5.

  • Means: x̄ = 3, ȳ = 4
  • Sxx = 10, Sxy = 6, Syy = 6
  • Slope = 0.6, intercept = 2.2, so y = 0.6x + 2.2
  • r = 6 / √60 ≈ 0.7746, R² = 0.6
  • Prediction at x = 6: 0.6 × 6 + 2.2 = 5.8

Tips

  • Plot your data first: a curve or a cluster of outliers can make a line misleading.
  • If every y is equal, the line is flat and r and R² cannot be calculated (shown as —).
  • This fits y on x. Swapping the axes gives a different line.

Frequently asked questions

What does least squares mean?

It picks the line that makes the sum of the squared vertical distances from the points to the line as small as possible. Squaring stops positive and negative errors from cancelling and punishes large misses more.

How are the slope and intercept calculated?

Slope = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² and intercept = ȳ − slope × x̄. For x = 1 to 5 and y = 2, 4, 5, 4, 5 the slope is 6 / 10 = 0.6 and the intercept is 4 − 0.6 × 3 = 2.2.

What do r and R² tell me?

r runs from −1 to 1 and shows how closely the points follow a line, with the sign giving the direction. R² = r² is the share of the variation in y explained by x. In the example above R² = 0.6, so 60% is explained.

Is it safe to predict outside my data?

Be careful. A prediction inside the range of your x values is interpolation and is generally reasonable. Beyond that range it is extrapolation, and the straight-line pattern may not continue.

Does a high R² prove one thing causes the other?

No. It measures a linear association only. Two variables can move together because of a third factor, or by chance, especially with few points.

More in Math

All tools in this category: Math ·Updated November 3, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.