Linear Regression Calculator

Linear regression finds the straight line that best fits a cloud of paired data points. Enter X and Y values and this calculator computes the least-squares line, its equation, and the correlation statistics that tell you how trustworthy the fit is.

The independent variable, e.g. 1, 2, 3, 4, 5
The dependent variable, same count as X

Results

Formula

The least-squares line minimizes the total squared vertical distance to the points:
Slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²  ·  Intercept = ȳ − Slope × x̄

How to use this calculator

  1. Enter the X values, then the Y values in the matching order.
  2. Make sure both lists have the same number of entries.
  3. Press Calculate and read the equation plus r and R².
Linear Regression Calculator — how the calculation works, illustrated
Linear Regression Calculator — how the calculation works, illustrated

Worked example

X: 1, 2, 3, 4, 5 and Y: 2, 4, 5, 4, 5.

  1. Means: x̄ = 3, ȳ = 4.
  2. Slope: 6 ÷ 10 = 0.6.
  3. Intercept: 4 − 0.6 × 3 = 2.2.
  4. r ≈ 0.775, so R² ≈ 0.60 — about 60% of Y’s variation is explained.

Result: The regression line is y = 0.6x + 2.2.

Frequently asked questions

What does R² actually tell me?

R² is the share of the variation in Y accounted for by the line: 0.60 means 60% explained, 40% left to other factors and noise. Higher is a stronger linear fit — not proof of causation.

Can I use the equation to predict new values?

Yes, within (and cautiously near) the range of your X data. Extrapolating far beyond the observed range is unreliable because the linear pattern may not continue.

What if my data is curved?

A low R² with a visible curve in a scatter plot suggests a non-linear model (exponential, quadratic) fits better than a straight line.

Related calculators