Linear Regression and Correlation Calculator
Enter one pair of values per line, x then y. You get the least squares line, Pearson and Spearman correlation, r squared, a significance figure, a table of residuals and a prediction for an x of your choice.
Separate x and y with a comma or a space. You need at least three pairs for the correlation.
Worked examples
A small data set
1,2 2,4 3,5 4,4 5,5
y = 2.2 + 0.6x, r = 0.7746, r² = 0.6
The mean of x is 3 and of y is 4.
A prediction
Same data, x = 6
y = 5.8
2.2 + 0.6 × 6.
About Linear Regression and Correlation Calculator
Linear regression finds the straight line that best fits a set of points: the line that makes the total of the squared vertical gaps between the points and the line as small as possible. That is why it is called least squares. The line is y = a + bx, where b is the slope, the change in y for each step of 1 in x, and a is the intercept, the value of y when x is zero. It is used to spot trends and to predict one value from another.
The correlation coefficient r, from -1 to 1, shows how closely the points follow a straight line, and r squared is the share of the variation in y that the line explains. The page also gives Spearman's rank correlation, which uses the order of the values and copes better with outliers, a p-value for r, the standard errors of the slope and intercept, and a table of each point with its fitted value and residual. For the pairs 1,2 2,4 3,5 4,4 5,5 the line is y = 2.2 + 0.6x and r is about 0.775. Correlation does not show that one thing causes the other.
How to use Linear Regression and Correlation Calculator
- Enter one pair per line, with x first and y second, separated by a comma or a space.
- Optionally enter an x value to predict y.
- Read the equation of the line, r squared and the correlation.
- Check the residuals table to see which points the line fits poorly.
Common uses
- Fitting a trend line in science coursework
- Predicting sales, costs or temperatures from a known pattern
- Testing whether two measurements move together
- Checking a spreadsheet trend line
Frequently asked questions
What does r squared mean?
It is the proportion of the variation in y explained by the straight line on x. An r squared of 0.6 means 60% of the variation is accounted for.
What is a good correlation?
Values near 1 or -1 show a strong straight line link, and values near 0 show none. What counts as good depends on the field and the size of the sample.
What is a residual?
It is the gap between a real y value and the value on the line. Points with large residuals are fitted badly.
Does correlation mean causation?
No. Two things can move together because of a third factor, or by chance. Correlation shows a link, not a cause.
How many pairs do I need?
At least two for a line and three for a correlation and its p-value, but a small sample gives an unreliable result. More is better.