ProMathTools
ProMathTools

Linear Regression Calculator – Line of Best Fit (y = mx + b)

Fit the ordinary least-squares line ŷ = b₀ + b₁x from paired X and Y data — slope, intercept, R², SEE, residuals, prediction, and a scatter plot with the line of best fit.

Comma, space, or newline separated

Same length as X

Optional — leave blank to skip prediction

How it works

Simple linear regression finds the straight line that best describes how Y changes with X. This calculator uses ordinary least squares: it chooses intercept b₀ and slope b₁ so that the sum of squared vertical residuals is as small as possible. Enter X and Y as two lists of equal length, or paste two columns (one pair per line). Optionally predict ŷ for any x — including values outside the observed range. Results include the equation, R², the standard error of estimate, a residual table, and an inline scatter plot of the points with the fitted line.

Required Inputs & Typical Use Cases

  • X and Y data

    Separate comma/space-separated lists, or pasted columns of x y pairs. Need at least two pairs with non-constant X.

  • Predict y for x (optional)

    Any finite x; ŷ = b₀ + b₁x is evaluated at that point and marked on the graph.

Use this tool for homework line-of-best-fit problems, quick trend checks on small datasets, residual inspection before a report, or predicting a next value from a simple linear trend. Pair it with correlation when you care about association strength, or with a t-test when you need formal inference on means.


The Formula

b₁ = Sxy / Sxx
b₀ = ȳ − b₁ x̄
ŷ = b₀ + b₁ x
R² = 1 − SSE / SST
SEE = √(SSE / (n − 2))   (n > 2)
where Sxx = Σ(xᵢ − x̄)², Sxy = Σ(xᵢ − x̄)(yᵢ − ȳ),
SSE = Σ(yᵢ − ŷᵢ)², SST = Σ(yᵢ − ȳ)²
  • b₁

    Slope (change in ŷ per unit x)

  • b₀

    Y-intercept (ŷ when x = 0)

  • R²

    Coefficient of determination

  • SEE

    Standard error of the estimate

  • residual

    yᵢ − ŷᵢ for each observation


Worked Example

  1. Default sample: X = 1…5, Y = 2, 4, 5, 4, 5

    x̄ = 3, ȳ = 4, Sxx = 10, Sxy = 6 → slope b₁ = 0.6, intercept b₀ = 2.2, so ŷ = 2.2 + 0.6x. R² = 0.6. Predicting at x = 6 gives ŷ = 2.2 + 0.6×6 = 5.8.


Tips, Assumptions & Limitations

  • X and Y must have the same number of values; mismatched lengths are a common paste error.
  • If all X values are identical, Sxx = 0 and no unique regression line exists.
  • R² close to 1 means a tight linear fit — not that X causes Y.
  • Extrapolating far beyond your X range can be misleading even when the in-sample fit looks excellent.
  • Inspect residuals in Show steps: large patterned residuals suggest a nonlinear relationship or outliers.
  • SEE is undefined for n = 2 (no leftover degrees of freedom); you still get slope, intercept, and R².

Ordinary least squares chooses the intercept b₀ and slope b₁ that minimize the sum of squared vertical residuals Σ(yᵢ − ŷᵢ)². The fitted equation is ŷ = b₀ + b₁x.

With means x̄ and ȳ, slope b₁ = Sxy / Sxx where Sxx = Σ(xᵢ − x̄)² and Sxy = Σ(xᵢ − x̄)(yᵢ − ȳ). Intercept b₀ = ȳ − b₁x̄. You need at least two points and non-zero variance in X.

R² = 1 − SSE/SST is the proportion of Y variance explained by the linear fit. R² = 1 means perfect fit; R² = 0 means the line predicts no better than ȳ. R² near 1 does not prove causation.

SEE = √(SSE / (n − 2)) estimates the typical size of residuals around the regression line (for n > 2). Smaller SEE means points hug the line more tightly.

Yes — the calculator evaluates ŷ = b₀ + b₁x at any finite x you enter. Extrapolation beyond the observed X range is mathematically fine but statistically riskier because the linear pattern may not continue.

If every x is identical, Sxx = 0 and the slope is undefined — there is no unique best-fit line through a vertical stack of points. Spread out X or add more distinct x-values.

Related Calculators

Correlation CoefficientCovariance CalculatorT-Test CalculatorSample Size CalculatorStandard DeviationConfidence IntervalZ-Score CalculatorMeanMedian ModeVarianceNormal Distribution

Related Guides

About UsBlogChrome ExtensionFAQsTerms and ConditionsPrivacy PolicySitemap
EmailLinkedInFacebook

© 2025-2026 PromathTools. All rights reserved.

Built by KruskalCode – SaaS & Automation Experts · EverydayDevTools