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.
Calculated locally. No account or uploads.
Result & working
ExampleThe calculator is loading. You can read the worked example below.
Step-by-step working
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)
| Symbol | Meaning |
|---|---|
| Sxx, Syy | Sums of squared deviations of x and y from their means. |
| Sxy | Sum of products (xᵢ − x̄)(yᵢ − ȳ). |
| SSE | Sum of squared residuals Σ(yᵢ − ŷᵢ)². |
| m, c | Slope 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.
- n = 5; x̄ = 3; ȳ = 4
- Sxx = Σ(xᵢ − x̄)² = 10
- Syy = Σ(yᵢ − ȳ)² = 6
- Sxy = Σ(xᵢ − x̄)(yᵢ − ȳ) = 6
- m = Sxy / Sxx = 6 / 10 = 0.6
- c = ȳ − mx̄ = 4 − (0.6) × 3 = 2.2
- SSE = Σ(yᵢ − ŷᵢ)² = 2.4
- r = Sxy / √(Sxx Syy) = 0.7745967; R² = 1 − SSE / Syy = 1 − 2.4 / 6 = 0.6
- Residual SD sₑ = √(SSE / (n − 2)) = √(2.4 / 3) = 0.8944272
- SE(m) = sₑ / √Sxx = 0.8944272 / √10 = 0.2828427
- 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.