01 / Fit
Least squares line
The line that makes the squared gaps between your y values and the line as small as they can be.
Free tool
Paste your x and y numbers, one pair on each line, or open a CSV file, and this linear regression calculator finds the best fit line by least squares: the slope, the intercept, the correlation r, R squared, the standard error and the equation. It draws a scatter chart with the line, shows the working table and every residual, and predicts y from x or x from y. Your numbers stay in your browser.
Examples
Predict
Show
The line is worked out in your browser. Your numbers are never uploaded. Numbers you type are kept in this browser for next time; opened files are not.
What you get
01 / Fit
The line that makes the squared gaps between your y values and the line as small as they can be.
02 / Working
A table of deviations, squares and products, so you can check the answer or copy it into homework.
03 / Residuals
The actual y, the y on the line, and the gap between them for every point.
Guide
A linear regression calculator finds the straight line that best describes how y changes with x. It gives the line as an equation, y = mx + b, where m is the slope and b is the intercept. This one uses ordinary least squares, the standard method: the line that makes the sum of the squared vertical gaps between your points and the line as small as possible. It also reports r, R squared and the standard error, so you can tell how well a straight line fits your data.
3 61. A tab, comma, semicolon or space between them all work, so you can paste straight from Excel, Google Sheets or Numbers.First find the mean of x and the mean of y. Then add up two sums over all points: Sxx is the sum of (x − mean x) squared, and Sxy is the sum of (x − mean x) times (y − mean y). The slope is m = Sxy ÷ Sxx. The intercept is b = mean y − m × mean x. The correlation is r = Sxy ÷ √(Sxx × Syy), where Syy is the sum of (y − mean y) squared, and R squared is r times r. The standard error of the estimate is s = √(sum of squared residuals ÷ (n − 2)).
Click the 5 points example: x is 1, 2, 3, 4, 5 and y is 2, 4, 5, 4, 5.
| x | y | x − 3 | y − 4 | (x − 3)² | (y − 4)² | Product |
|---|---|---|---|---|---|---|
| 1 | 2 | −2 | −2 | 4 | 4 | 4 |
| 2 | 4 | −1 | 0 | 1 | 0 | 0 |
| 3 | 5 | 0 | 1 | 0 | 1 | 0 |
| 4 | 4 | 1 | 0 | 1 | 0 | 0 |
| 5 | 5 | 2 | 1 | 4 | 1 | 2 |
| Sum | 10 | 6 | 6 |
The means are 3 and 4. The slope is 6 ÷ 10 = 0.6. The intercept is 4 − 0.6 × 3 = 2.2, so the line is y = 0.6x + 2.2. The correlation is 6 ÷ √(10 × 6) = 0.7746, and R squared is 0.6. The line gives 2.8, 3.4, 4.0, 4.6 and 5.2, so the residuals are −0.8, 0.6, 1.0, −0.6 and −0.2. Their squares add up to 2.4, and with n − 2 = 3 the standard error is √(2.4 ÷ 3) = 0.8944. To predict y at x = 6, work out 0.6 × 6 + 2.2 = 5.8. To find x when y is 4.6, work out (4.6 − 2.2) ÷ 0.6 = 4.
For the spread of a single list of numbers, use the standard deviation calculator or the average calculator.
Questions
Find the mean of x and y, then the slope m = Sxy ÷ Sxx and the intercept b = mean y − m × mean x. The guide above works through a five-point example with every sum shown.
y = mx + b, where m is the slope and b is the intercept. The calculator writes it with your numbers, such as y = 0.6x + 2.2.
It is the share of the changes in y that the line explains, from 0 to 1. An R squared of 0.97 means the line explains 97 percent.
It depends on the field. Careful lab work can give values near 1, while data about people is often much lower. Look at the chart and the residuals as well as the number.
r = Sxy ÷ √(Sxx × Syy). It is shown in the cards. Its sign is the sign of the slope, and its square is R squared.
Type the x under y for this x. The page puts it into y = mx + b. It also works the other way, from y to x, and warns you when the value is outside your data.
The gap between a real y value and the y value on the line. Residuals add up to zero, and the least squares line is the one with the smallest sum of their squares.
Two points give a line but no error estimate. Three or more give the standard error, the p value and the 95 percent intervals. More points make the line more trustworthy.
Yes. Paste two columns from a spreadsheet, or click Open a CSV file. The file is read in your browser and not uploaded.