Skip to main content
Calcimator

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

Y-Intercept (b)0.667
R² (Coefficient of Determination)0.964
Equationy = 1.5x + 0.667
How to Use This Calculator
  1. Enter matched (x, y) data point pairs — at least three points are needed for a meaningful regression.
  2. The calculator fits a line y = mx + b using least squares: slope m = Σ(xi−x̄)(yi−ȳ) / Σ(xi−x̄)².
  3. Slope (m) tells you how much y changes per unit increase in x; Intercept (b) is the predicted y when x = 0.
  4. R-Squared (coefficient of determination) ranges from 0 to 1 — values closer to 1 indicate a stronger linear fit.
  5. The chart overlays your data points and the best-fit line so you can visually assess the fit quality.
  6. 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
3000.007
8000.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

  1. Identify Input Parameters
    4 parameters
    X₁ = 1, Y₁ = 2, X₂ = 2, Y₂ = 4 = 6 input(s) provided
  2. Calculate Slope
    Slope = slopeVal
    1.5 = 1.5
  3. Calculate Y-Intercept
    Y-Intercept = interceptVal
    0.667 = 0.667
  4. Calculate 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.

The questions that sit next to this one — chosen by subject, including calculators filed under a different category.

More in Math & Statistics.