Linear regression calculator
Paste paired x and y values to get the line of best fit (ŷ = bx + a), R², r and predictions, plus a scatter plot with the line drawn in.
Two columns pasted from a spreadsheet, or “x, y” per line. A header row is optional. 12 valid pairs.
| Equation | ŷ = 5.0447x + 46.3239 |
|---|---|
| Slope (b) | 5.044667 |
| Intercept (a) | 46.323914 |
| R² | 0.9743 (97.4% of variation in y explained) |
| Correlation r | 0.987 |
| Std. error of slope | 0.2593 |
| ŷ at x = 10 | 96.7706 |
| n | 12 |
| Mean x · mean y | 4.875 · 70.9167 |
| SD x · SD y (sample) | 2.4966 · 12.7597 |
Want to style and download this chart? Open the scatter plot maker.
The formulas
For n pairs with means x̄ and ȳ:
- Slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
- Intercept a = ȳ − b·x̄
- r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² · Σ(y − ȳ)²], and R² = r²
This “ordinary least squares” line minimises the sum of squared vertical distances between the points and the line. The line always passes through (x̄, ȳ).
Check the assumptions
Look at the scatter plot first. A straight line only makes sense if the points follow a roughly straight pattern. One outlier can drag the slope a long way, so try the explainer to see how much.
Drag a point, watch the best-fit line react
The line is placed so the total area of the yellow squares — the squared vertical errors — is as small as possible. Drag points up or down (or focus one and use the arrow keys).
y = 0.84x + 1.193 · r = 0.95 · squared error = 1.33
Questions
What does the slope mean?
The slope is the average change in y for each one-unit increase in x. A slope of 4.6 on hours vs score means each extra hour of study goes with about 4.6 more points, on average.
What is a good R² value?
It depends on the field. In controlled physics experiments R² above 0.99 is normal; in social science 0.3 can be meaningful. R² tells you how much variation the line explains, not whether the model is right.
Is this the same as a line of best fit calculator?
Yes. The least-squares regression line is the standard line of best fit, the same one Excel’s trendline, LINEST and TI calculators’ LinReg(ax+b) produce.
Can I predict values outside my data?
You can calculate them, but extrapolating beyond the range of x you measured is risky: the relationship may not stay linear.