Linear Regression Calculator (Line of Best Fit)
Fit a least-squares line to paired X and Y data — get the slope, intercept, equation, correlation, and R².
Result
- Slope (b)0.600000
- Intercept (a)2.200000
- Correlation r0.774597
- R² (coefficient of determination)0.600000
- Means (x̄, ȳ)3.0000, 4.0000
- Points (n)5
Step-by-step
- Means: x̄ = 3.0000, ȳ = 4.0000.
- Slope b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)² = 6.0000 ÷ 10.0000 = 0.600000.
- Intercept a = ȳ − b·x̄ = 4.0000 − 0.6000×3.0000 = 2.200000; R² = 0.600000.
How to use this calculator
- Enter your X (independent) values, comma-separated.
- Enter the matching Y (dependent) values in the same order.
- Read the best-fit equation y = bx + a.
- Check R² to judge how well the line fits the data.
About this calculator
Linear regression finds the straight line that best summarizes the relationship between two variables, X and Y. The least-squares line minimizes the total squared vertical distance between the data points and the line, giving a slope (how much Y changes per unit of X) and an intercept (the predicted Y when X is zero). This calculator also reports the correlation coefficient r, which measures how tightly the points cluster around the line, and R², the square of r, which is the proportion of the variation in Y that the line explains. An R² near 1 means the line fits well; near 0 means X tells you little about Y. Paste your X and Y values as matching lists and the tool returns the full equation and fit statistics.
How it works — the formula
b (slope) = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)²
a (intercept) = ȳ − b·x̄
r = Σ(x−x̄)(y−ȳ) / √(Σ(x−x̄)²·Σ(y−ȳ)²)
R² = r²The slope is the covariance of X and Y divided by the variance of X; the intercept anchors the line through the means. r and R² quantify fit quality.
Worked examples
- Inputs:
- xs=1,2,3,4,5; ys=2,4,5,4,5
- Output:
- y = 0.6x + 2.2, R² = 0.6
- Inputs:
- xs=1,2,3; ys=2,4,6
- Output:
- y = 2x + 0, R² = 1
- Inputs:
- xs=1,2,3,4; ys=4,3,2,1
- Output:
- y = −1x + 5, R² = 1
Limitations
- Ordinary least squares only; sensitive to outliers and assumes a linear relationship.
- Requires at least two points and non-constant X values.
- Does not report confidence intervals or residual diagnostics.
Association, not causation; verify linearity with a scatter plot.