Statistics & data

Linear Regression Calculator with Graph

Paste x–y pairs to fit y = mx + c. Inspect the graph and see how every coefficient is calculated.

Your measurements

Start with the example, or enter your own values. Use a dot for decimals and e for scientific notation.

Linear Regression Calculator with Graph inputs
One x–y pair per line. Spaces, tabs or commas separate columns. Omit headers.

Calculated locally. No account or uploads.

Result & working

Example

The calculator is loading. You can read the worked example below.

The formula

m = Sxy/Sxx; c = ȳ − mx̄

r = Sxy/√(Sxx Syy); R² = 1 − SSE/Syy

sₑ = √[SSE/(n − 2)]

SE(m) = sₑ/√Sxx; SE(c) = sₑ√(1/n + x̄²/Sxx)

What the variables mean
SymbolMeaning
Sxx, SyySums of squared deviations of x and y from their means.
SxySum of products (xᵢ − x̄)(yᵢ − ȳ).
SSESum of squared residuals Σ(yᵢ − ŷᵢ)².
m, cSlope and intercept. Slope units are y-units divided by x-units.
r, R²Signed linear correlation and coefficient of determination.

When to use this calculator

Ordinary least squares chooses the line that minimizes squared vertical residuals. It treats x as known and fits an intercept; it does not force the line through the origin or account for x uncertainty.

Coefficient standard errors need at least three points and assume independent errors with constant variance. Confidence intervals require further assumptions and an appropriate t multiplier. Constant y gives a horizontal fitted line, but r and R² are undefined because y has no variation.

Worked example

The calculator opens with these example values. All steps below are available even with JavaScript disabled.

  1. n = 5; x̄ = 3; ȳ = 4
  2. Sxx = Σ(xᵢ − x̄)² = 10
  3. Syy = Σ(yᵢ − ȳ)² = 6
  4. Sxy = Σ(xᵢ − x̄)(yᵢ − ȳ) = 6
  5. m = Sxy / Sxx = 6 / 10 = 0.6
  6. c = ȳ − mx̄ = 4 − (0.6) × 3 = 2.2
  7. SSE = Σ(yᵢ − ŷᵢ)² = 2.4
  8. r = Sxy / √(Sxx Syy) = 0.7745967; R² = 1 − SSE / Syy = 1 − 2.4 / 6 = 0.6
  9. Residual SD sₑ = √(SSE / (n − 2)) = √(2.4 / 3) = 0.8944272
  10. SE(m) = sₑ / √Sxx = 0.8944272 / √10 = 0.2828427
  11. SE(c) = sₑ √(1/n + x̄²/Sxx) = 0.8944272 × √(1/5 + (3)²/10) = 0.9380832

y = 0.6x + 2.2

Common mistakes

  • A fitted intercept is not automatically evidence of a calibration error.
  • A high R² can hide curvature or outliers; inspect the graph.
  • Keep each x paired with its original y.
  • Do not confuse a regression standard error with the max/min-gradient method.