Linear regression calculator: line of best fit

Line of best fit, r and r².

Line of best fit (least squares)

y = 2.02x − 0.02

r = 0.9991: a very strong positive linear relationship.

Slope (m)
2.02
Intercept (b)
−0.02
Correlation coefficient (r)
0.999105
r²
0.998211
Number of points (n)
6
Standard error of the estimate
0.178885
12345624681012

Residuals

xyPredicted ŷResidual (y − ŷ)
12.120.1
23.94.02−0.12
36.26.040.16
47.88.06−0.26
510.110.080.02
612.212.10.1

Runs in your browser. Nothing uploaded.

How to find the line of best fit

  1. Paste your data with one x, y pair per line. Commas, spaces or tabs between the two numbers all work, so two columns copied from a spreadsheet paste straight in. A header row is skipped.
  2. Read the equation y = mx + b, the slope, the intercept, the correlation coefficient r and r², with the points and the line plotted.
  3. Optionally type an x value to predict y. The residuals table shows how far each point is from the line.

Reading the result

For the sample data the line is y = 2.02x − 0.02 and r is 0.999: y rises by about 2 for each step in x, almost perfectly in a line. The standard error of the estimate is the typical size of a residual, in the same units as y, which is often more useful than r² for judging whether predictions are good enough.

When a straight line is the wrong model

Least squares always finds a line, even for data that curves. Look at the scatter plot and the residuals: if they bend in a U shape or fan out as x grows, the relationship isn’t linear and r can be misleading. A single far-off point can also pull the line a long way, so check outliers with the quartile calculator before trusting the slope.