Linear Regression Calculator

Fit a least-squares line, with slope, intercept, r² and prediction.

What the Linear Regression Calculator does

Linear regression fits the straight line that minimises the squared distances to your data points. The slope tells you how much Y changes per unit of X, and r² tells you how much of Y's variation that line accounts for.

Formula

  • Slope m = Σ((x − x̄)(y − ȳ)) ÷ Σ(x − x̄)²
  • Intercept b = ȳ − m × x̄
  • R² = 1 − (Residual sum of squares ÷ Total sum of squares)

Inputs explained

InputUnitRequiredNotes
X values (independent)textYesSeparate values with commas, spaces or new lines.
Y values (dependent)textYesSeparate values with commas, spaces or new lines.
Predict Y for X =numberOptionalOptional — predicts using the fitted line.

How to use it

  1. Enter X values (independent) and Y values (dependent).
  2. Optionally add Predict Y for X =.
  3. Select Calculate.

Worked example

Advertising spend of 1, 2, 3, 4, 5 against sales of 2.1, 4.3, 6.2, 8.1, 9.8.

X
1, 2, 3, 4, 5
Y
2.1, 4.3, 6.2, 8.1, 9.8

y = 1.92x + 0.34 with r² = 0.998 — each unit of spend adds about 1.92 units of sales.

Reading the result

  • The residuals table is the honest complement to r² — a high r² alongside a visible pattern in the residuals (not random scatter) signals the relationship isn't truly linear even though the summary statistic looks good.
  • "Standard error of the estimate" measures typical prediction error in the same units as Y, distinct from r², which measures the proportion of variance explained rather than the size of a typical miss.

Assumptions and limitations

  • The "outside data range" warning only fires for extrapolation beyond the observed X range — a prediction well within that range still assumes the true relationship is genuinely linear, which a high r² alone does not guarantee.
  • The p-value for the slope assumes constant error variance and independent observations — violations of either aren't detected by the calculator, only assumed.

Common mistakes

  • Trusting a prediction at the edge of the data range as if it carries the same reliability as one from the middle.
  • Reading r² alone as validation of the model without checking the residuals table for a pattern — a hidden non-linearity shows up there, not in r².

Frequently asked questions

What is a good r² value?

It depends on the field. Physics experiments expect above 0.95; social science often accepts 0.3. What matters is whether the model is useful, not whether r² clears a threshold.

Can I predict outside my data range?

You can, but you should not trust it. Extrapolation assumes the linear relationship continues, which is frequently false.

Related calculators