Skip to content
AllCalcHub

Linear Regression Calculator

Fit a straight line, parabola, exponential or power curve to paired data by least squares, with the normal equations, R² and predictions.

About the Linear Regression Calculator

Linear regression finds the line y = a + bx that makes the sum of squared vertical distances to the points as small as possible. R² is the share of the variation in y the line explains, from 0 (none) to 1 (all).

Curve fitting by least squares uses the normal equations: for a line, Σy = na + bΣx and Σxy = aΣx + bΣx²; for a parabola add c and one more equation. The steps show the sums and solve the equations exactly. Exponential and power curves are fitted by taking logarithms: ln y = ln a + bx, or ln y = ln a + b ln x.

The formula

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²; a = ȳ − b·x̄

R²
(Sxy)² ÷ (Sxx·Syy)

Worked example

Example: Line of best fit = y = 1.99x + 1.05

  1. Inputs: Fit: Straight line y = a + bx; x values: 1, 2, 3, 4, 5; y values: 3.1, 4.9, 7.2, 8.8, 11.1; Predict y at x = (optional): 8.
  2. Formula: b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²; a = ȳ − b·x̄
  3. The sums: n = 5, Σx = 15, Σx² = 55, Σy = 351/10, Σxy = 626/5
  4. Normal equation 1: Σy = an + bΣx: 351/10 = 5a + 15b
  5. Normal equation 2: Σxy = aΣx + bΣx²: 626/5 = 15a + 55b
  6. Solve the equations: a = 21/20, b = 199/100
  7. Result: Line of best fit = y = 1.99x + 1.05
  8. Slope: 1.99
  9. Intercept: 1.05
  10. R²: 0.997305

Things to keep in mind

  • Predictions far outside the range of your x values are unreliable.
  • Correlation isn't causation.

Questions people ask

What's a good R²?

It depends on the field: physics often expects above 0.99, social sciences can treat 0.3 as meaningful.

Can I fit a curve?

Yes: choose a parabola (normal equations in a, b, c), an exponential or a power curve. The exponential and power fits take logs first, as textbooks do, which is least squares on ln y rather than on y.