Free statistics tool
Scatter Plot & Line of Best Fit Calculator
Paste or type x, y data to make a scatter plot and find the line of best fit by least-squares linear regression. Get the equation, the correlation coefficient r and r², predictions for any x, the residuals, and the calculation worked through step by step. Free, no signup.
Separate x and y with a space, comma or tab. You can paste two columns from a spreadsheet.
Line of best fit
Correlation r
r²
Predicted y
Step by step
- 1Find the mean of the 10 x-values and of the y-values.\bar{x} = 4.3 \qquad \bar{y} = 69.7
- 2Add up the products of the deviations from the means, and the squared deviations of x.S_{xy} = \sum (x - \bar{x})(y - \bar{y}) = 245.4 \qquad S_{xx} = \sum (x - \bar{x})^2 = 45.6
- 3The slope of the least-squares line:b = \frac{S_{xy}}{S_{xx}} = \frac{245.4}{45.6} \approx 5.3816
- 4The line passes through the point of means, which gives the intercept:a = \bar{y} - b\bar{x} = 69.7 - 5.3816 \times 4.3 \approx 46.5592
- 5The correlation coefficient measures how closely the points follow a straight line, from −1 to 1:r = \frac{S_{xy}}{\sqrt{S_{xx} S_{yy}}} = \frac{245.4}{\sqrt{45.6 \times 1334.1}} \approx 0.9949
- 6r² is the share of the variation in y that the line explains.r^2 \approx 0.9899 \approx 98.99\%
Correlation isn't causation: a strong r shows the variables move together, not that one causes the other.
The least-squares formulas
Sxy adds up (x − x̄)(y − ȳ) over all the points, and Sxx and Syy add up the squared deviations of x and of y. The line always passes through the point of means (x̄, ȳ).
Check the residuals
Turn on residuals to see how far each point is from the line. If they look random, a straight line suits the data; if they curve in a pattern, the relationship probably isn't linear, even when r is high.
Frequently asked questions
What is a line of best fit?+
The straight line that comes closest to all the points on a scatter plot. The least-squares line is the one that makes the total of the squared vertical distances from the points to the line as small as possible. Its equation, ŷ = a + bx, lets you predict y from x.
What does the correlation coefficient r mean?+
r measures how closely the points follow a straight line, from −1 to 1. Near 1 means a strong upward trend, near −1 a strong downward trend, and near 0 no straight-line pattern. As a common rule of thumb, |r| above about 0.7 is called strong and below about 0.2 very weak, though conventions vary by subject.
What is r²?+
r² (the coefficient of determination) is the share of the variation in y that the line explains. An r² of 0.81 means 81% of the ups and downs in y line up with the line; the other 19% is scatter the line doesn't account for.
Can I use the line to predict?+
Yes, within the range of your data. Predicting far outside it (extrapolating) is risky, because the pattern may not continue. The calculator warns you when the x you type is outside your data.
Does a strong correlation mean one thing causes the other?+
No. Correlation shows that two variables move together, not why. A third factor may drive both, or the link may be a coincidence. Showing cause needs a controlled experiment.
Working with data?
Summarize one variable with the statistics calculator, or get a statistics tutor for one-on-one help. Your first trial lesson is free.
Make statistics click
A 1-on-1 statistics tutor helps you interpret r, r² and residuals, not just compute them. Your first trial lesson is free.