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
| Input | Unit | Required | Notes |
|---|---|---|---|
| X values (independent) | text | Yes | Separate values with commas, spaces or new lines. |
| Y values (dependent) | text | Yes | Separate values with commas, spaces or new lines. |
| Predict Y for X = | number | Optional | Optional — predicts using the fitted line. |
How to use it
- Enter X values (independent) and Y values (dependent).
- Optionally add Predict Y for X =.
- 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.
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.