Skip to main content

Linear Regression Calculator

Fit ŷ = b₀ + b₁·x by ordinary least squares, with R², SSE, and a predict-at-x helper.

Written by Golam Rabbani, Founder & Lead Engineer

Ordinary least squares: slope b₁ = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)², intercept b₀ = ȳ − b₁·x̄.

How to use this linear regression calculator

  1. Paste your (x, y) pairs — one per line, comma or space separated.
  2. Optionally type a value into "Predict ŷ at x" to get the fitted prediction.
  3. Press Calculate to see the regression equation, slope, intercept, R², SSE, and standard error.
  4. Copy the result or Reset to clear inputs.

About this linear regression calculator

Linear regression fits the best straight line ŷ = b₀ + b₁ · x through your (x, y) data by minimising the sum of squared residuals (ordinary least squares). The slope is b₁ = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² and the intercept is b₀ = ȳ − b₁ · x̄. The calculator also reports the Pearson correlation r, the coefficient of determination R² = r², the residual sum of squares SSE, and the standard error of the estimate √(SSE / (n − 2)) — useful for gauging how tightly the data clusters around the line.

Worked example. Enter the pairs (1, 2.1), (2, 3.9), (3, 6.0), (4, 8.1), (5, 10.0). x̄ = 3, ȳ = 6.02. Σ(x − x̄)(y − ȳ) = 19.8, Σ(x − x̄)² = 10. So slope b₁ = 19.8 / 10 = 1.98 and intercept b₀ = 6.02 − 1.98 · 3 = 0.08. The fitted line is ŷ = 1.98x + 0.08. R² ≈ 0.9994 — the line explains 99.94% of the variation. Set "Predict ŷ at x" to 6 and you get 1.98 · 6 + 0.08 = 11.96.

FAQ

What does R² mean here?
R² is the proportion of variance in y captured by the linear model. R² = 0.99 means the line accounts for 99% of variation; what is left is noise plus any non-linear pattern.
What is the standard error of the estimate?
√(SSE / (n − 2)). It is the typical residual size — roughly how far the data points sit from the fitted line in the original y units.
Can I extrapolate beyond the observed x range?
You can, but predictions outside the observed x range rely on the relationship continuing linearly there — which often it does not. Extrapolate with caution.
What if all x values are identical?
Σ(x − x̄)² = 0 and the slope is undefined. The calculator returns slope 0 and surfaces an effectively flat line — usually a signal to reconsider the problem.
Does this fit polynomial or multiple-regression models?
No, it is ordinary least squares on a single x. For polynomials, regress y on x, x², etc., outside this tool.