Statistics

Linear Regression Calculator

What this does

Fit the least-squares line y = mx + b to paired data and get slope, intercept and R² with the equation spelled out.

Enter your details

Runs in your browser

Calculator inputs

Using the linear regression calculator

  1. 01

    Paste paired data

    One x,y pair per line, separated by a comma.

  2. 02

    Read the fitted equation

    y = mx + b is the prediction line; plug any x in to forecast y.

  3. 03

    Judge fit with R²

    Near 1 means points hug the line; low values warn against forecasting with it.

Reading slope and intercept in context

The slope answers “per one unit increase in x, how much does y change?” The intercept is the predicted y at x = 0; meaningful only when zero lies within plausible data range. Always state units: “each extra ad dollar yields $2.34 more revenue” beats “m = 2.34”.

Extrapolation is where fits go to die

Least squares lines describe the observed range. Predicting far outside it assumes the trend persists unboundedly; rarely true. Confidence in predictions decays quickly toward the edges and beyond the data.

  • Perfect fit → R² = 1.
  • R² of 0.49 means the line explains 49% of y variation.
  • Outliers tilt the line strongly; inspect residuals.

The math behind this calculator

m = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)² b = ȳ − m·x̄ R² = Sxy² / (Sxx·Syy)

Ordinary least squares chooses the line minimizing the summed squared vertical distances to your points. Closed-form solutions give the slope from the covariance of x and y over the variance of x, and the intercept follows so the line passes through the data’s centroid (x̄, ȳ).

R² reports the share of y-variance the line explains: 1 is a perfect fit, 0 means the line explains nothing beyond the mean. Regression requires x-values that actually vary; constant x is rejected.

Assumptions & limitations

  • One “x,y” pair per line, comma-separated.
  • At least two pairs with varying x values.
  • Linearity assumed; check a scatter plot before trusting R².

Worked example

Fitting the points (1,2), (2,4), (3,6) yields y = 2x + 0 exactly; slope 2, intercept 0, R² = 1, a perfect linear relationship.

Frequently asked questions

Why is my intercept absurd?
Probably x = 0 lies far outside your data, so the intercept is an extrapolation with inflated uncertainty. Center x before fitting if the intercept matters.
Does correlation imply causation here?
No; the line summarizes association. Confounders, reverse causation and coincidence all produce strong-looking fits.
What if some lines have extra commas?
Each line must parse as exactly two numeric fields; malformed lines return an error naming the offending line number.
Can I fit curves?
Not with this tool; it is strictly linear in the parameters. Transform variables (log, sqrt) first if theory suggests curvature.

Related calculators