Linear regression calculator

Fit a least-squares line to paired numeric data and calculate residual sum of squares and R².

Enter values

Start with the example below, or enter your own values.

How it works

Ordinary least squares minimizes squared vertical residuals. The slope uses centered covariance divided by centered x variance. R² is undefined when all y values are equal.

Try an example

x values: 1, 2, 3, 4; y values: 3, 5, 7, 9. The form starts with these values; change them to explore your own case.

Example result: y = 2x + 1

  1. Center x and y around their means.
  2. Slope = centered cross-product / centered x sum of squares.
  3. Intercept = mean(y) − slope·mean(x).

Learn more in Statistics and regression tools.

Results are calculated locally. Floating-point tools provide numerical approximations, not formal proof certificates.