Linear Regression Calculator
Calculate linear regression line, slope, intercept, and R-squared. Find the best-fit line for your data points.
This calculator fits a least-squares regression line through exactly three fixed data points — no more, no fewer — computing the slope and intercept that minimize the total squared vertical distance between the line and each point, plus an R-squared value describing how well that line actually fits. At the calculator's default points, (1, 2), (2, 4), and (3, 5), something specific and genuinely surprising happens: moving Y₂ up or down has zero effect on the fitted slope. That isn't a coincidence of rounding — it follows directly from how the least-squares slope formula weights each point by how far its X-coordinate sits from the mean of all three X-values, and here X₂ (2) sits exactly on that mean, since the three X-values (1, 2, 3) are evenly spaced around it. A point sitting precisely at the mean X contributes nothing to the slope calculation regardless of its Y-value, though it still fully participates in the intercept and R-squared calculations, both of which do respond to Y₂ moving. Y₃, by contrast, pulls the slope up whenever it increases, since raising the line's rightmost point tilts the whole fitted line upward. Left unaddressed here: if all three Y-values happen to be identical, the true best fit is a perfectly flat horizontal line with a technically undefined R-squared, since there is no vertical spread in the data to explain, and rather than flagging that degenerate case, the calculator simply reports an R-squared of 0.
Inputs
Results
Slope (m)
1.5
How to Use This Calculator
- Enter matched (x, y) data point pairs — at least three points are needed for a meaningful regression.
- The calculator fits a line y = mx + b using least squares: slope m = Σ(xi−x̄)(yi−ȳ) / Σ(xi−x̄)².
- Slope (m) tells you how much y changes per unit increase in x; Intercept (b) is the predicted y when x = 0.
- R-Squared (coefficient of determination) ranges from 0 to 1 — values closer to 1 indicate a stronger linear fit.
- The chart overlays your data points and the best-fit line so you can visually assess the fit quality.
- For non-linear relationships consider transforming variables (e.g., log y) before entering them.
How the result changes with X₃
| X₃ | Slope (m) |
|---|---|
| -800 | -0.002 |
| -300 | -0.007 |
| 300 | 0.007 |
| 800 | 0.003 |
What each input means
- X₁
- First X coordinate.
- Y₁
- First Y coordinate.
- X₂
- Second X coordinate.
- Y₂
- Second Y coordinate.
- X₃
- Third X coordinate.
- Y₃
- Third Y coordinate.
How this is calculated
Worked example, using the default values
- Identify Input Parameters4 parametersX₁ = 1, Y₁ = 2, X₂ = 2, Y₂ = 4 = 6 input(s) provided
- Calculate SlopeSlope = slopeVal1.5 = 1.5
- Calculate Y-InterceptY-Intercept = interceptVal0.667 = 0.667
- Calculate R²R²0.964 = 0.964
Engine last updated . Checked against 1 independently-derived test — how we verify calculators.
Frequently Asked Questions
Why does moving Y₂ have no effect on the slope?
The least-squares slope formula weights every point's Y-value by how far that point's X-coordinate sits from the average of all three X-values. At this calculator's default points, X₂ is 2, which happens to be exactly the average of 1, 2, and 3 — so Y₂'s weight in the slope formula is exactly zero. Change the X-coordinates so they're no longer evenly spaced, and this stops being true.
If Y₂ doesn't affect the slope, does it matter at all?
Yes — it still fully affects both the intercept and the R-squared value, just not the slope specifically. A point exactly at the mean X-value can shift where the fitted line crosses the Y-axis and how tightly the line matches all three points, even though it contributes nothing to how steeply that line tilts.
Can I enter more than three data points?
No. This calculator is built around exactly three fixed coordinate pairs — X₁/Y₁, X₂/Y₂, and X₃/Y₃ — with no way to add a fourth point or remove one of the three. A regression across more data points would need a different tool built for a variable-length data set.
What happens if all three Y-values are the same number?
The best-fit line in that case really is perfectly flat, but R-squared is conventionally undefined when there's no vertical spread in the data to begin with, since the formula divides by that spread. Rather than flagging this degenerate case, the calculator falls back to reporting an R-squared of exactly 0.
Related Calculators
The questions that sit next to this one — chosen by subject, including calculators filed under a different category.
Average Calculator
Calculate mean, median, mode, range, geometric mean, and harmonic mean of a set of numbers.
Math & StatisticsStandard Deviation Calculator
Calculate the mean, median, standard deviation, and variance for a set of numbers. Supports both population and sample calculations.
StatisticsMultiple Regression Calculator
Evaluate a multiple regression model using SSR, SSE, number of predictors, and sample size. Calculate R², adjusted R², F-statistic, and model fit metrics.
Math & StatisticsPercentage Calculator
Calculate percentages easily — find a percentage of a number, percentage increase/decrease, and percentage change between two values.
More in Math & Statistics.