Linear Regression Calculator
Enter your data as x and y pairs, one per line, and get the least squares line of best fit with its slope, intercept, correlation coefficient r, R squared and standard errors. A chart shows the points and the line, you can predict y for any x, and a table lists the fitted values and residuals. Everything runs in your browser.
| x | y | Fitted | Residual |
|---|---|---|---|
| 10 | 8.04 | 8.001 | 0.039 |
| 8 | 6.95 | 7.0008 | -0.05082 |
| 13 | 7.58 | 9.5013 | -1.921 |
| 9 | 8.81 | 7.5009 | 1.309 |
| 11 | 8.33 | 8.5011 | -0.1711 |
| 14 | 9.96 | 10.001 | -0.04136 |
| 6 | 7.24 | 6.0006 | 1.239 |
| 4 | 4.26 | 5.0005 | -0.7405 |
| 12 | 10.84 | 9.0012 | 1.839 |
| 7 | 4.82 | 6.5007 | -1.681 |
| 5 | 5.68 | 5.5005 | 0.1795 |
Least squares regression finds the straight line y = a + bx that makes the sum of the squared vertical distances from the points as small as possible. The slope is b = Sxy / Sxx, where Sxy is the sum of (x minus the mean of x) times (y minus the mean of y) and Sxx is the sum of (x minus the mean of x) squared, and the intercept is a = mean of y minus b times the mean of x. The correlation r runs from -1 to 1, and R squared is r squared. A high r shows a linear pattern, not that x causes y, and a line fitted to a few points should not be used far outside their range. Everything is worked out in your browser and nothing is uploaded.
Related Tools
[5 suggestions]Slope Calculator
Find the slope, equation, intercepts, distance and midpoint of the line through two points, with exact fractions.
Student ToolsStandard Deviation Calculator
Find the standard deviation, variance, mean and more for a list of numbers, as a sample or a population, with the working shown.
Math & MoneyZ-Score Calculator
Turn a value into a z-score, a z-score into probabilities and percentiles, or a percentile back into a z-score, using the standard normal distribution.
Math & MoneyMean, Median and Mode Calculator
Find the mean, median, mode, range, quartiles, variance and standard deviation of a list of numbers, with exact decimal arithmetic.
Math & MoneyQuartile and Outlier Calculator
Find Q1, the median, Q3, the interquartile range and the outliers of a list of numbers, with a box plot and a choice of four quartile methods.
Math & MoneyAbout the Linear Regression Calculator
Simple linear regression finds the straight line y = a + bx that comes closest to a set of points, where closest means the smallest sum of squared vertical distances. The slope is b = Sxy / Sxx, where Sxy is the sum of (x minus the mean of x) times (y minus the mean of y) and Sxx is the sum of (x minus the mean of x) squared. The intercept is a = mean of y minus b times the mean of x. The correlation coefficient r = Sxy / the square root of (Sxx x Syy) measures how closely the points follow a line, from -1 for a perfect falling line to 1 for a perfect rising one, and R squared is r squared, the share of the variation in y that the line explains. The standard error of the estimate is the square root of SSE / (n - 2), where SSE is the sum of the squared residuals, and the standard error of the slope is that divided by the square root of Sxx. These need at least three points. As a check, the first set of Anscombe's quartet, eleven points, gives y = 3.0001 + 0.5001x with r = 0.8164 and R squared = 0.6665. The other three sets give almost the same line from very different data, which is why a chart matters as much as the numbers. Correlation does not show cause, and a prediction far outside the range of your data is unreliable. Nothing is uploaded.
What is the line of best fit?▾
The straight line that makes the sum of the squared vertical distances from the points as small as possible. It has the form y = a + bx, where b is the slope and a is the intercept.
What does R squared mean?▾
It is the share of the variation in y that the line explains, from 0 to 1. An R squared of 0.67 means about two thirds of the variation in y is accounted for by x. It is the square of the correlation r.
How many points do I need?▾
Two points define a line, but standard errors need at least three. More points make the line more reliable, and a chart helps you see whether a straight line suits the data at all.
Does a high correlation mean x causes y?▾
No. A high r only shows that the points follow a line. Both could be driven by something else, and a curved pattern can also give a decent r, so check the chart before relying on it.
Is my data uploaded?▾
No. The calculation runs in your browser and the numbers you enter are not sent anywhere.