Linear Regression Calculator
Get the line of best fit, the correlation coefficient and r² from paired data, and see the residuals on a scatter plot.
Least squares, in one sentence
The regression line is the one straight line that makes the sum of the squared residuals (the orange gaps, squared) as small as possible. Tick and untick the residuals above to see what is being minimised.
b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² · a = ȳ − b·x̄
The line always passes through the point (x̄, ȳ). The correlation coefficient uses the same sums: r = Sxy ÷ √(Sxx · Syy). Always look at the scatter plot: Anscombe’s quartet (1973) is four data sets with identical r and regression lines that look completely different when plotted.
Frequently asked questions
How do I interpret the slope and intercept?
The slope is the predicted change in y for each one-unit increase in x. The intercept is the predicted y when x = 0, which only has a real-world meaning if x = 0 is within or near the range of your data.
What is the difference between r and r²?
r, the Pearson correlation coefficient, runs from −1 to 1 and shows the direction and strength of a straight-line relationship. r² is the proportion of variation in y explained by the line: r = 0.9 means r² = 0.81, so the line explains 81% of the variation.
What counts as a strong correlation?
Rough guides call |r| above 0.7 strong, 0.4 to 0.7 moderate and below 0.4 weak, but it depends on the field. In physics r = 0.9 might be disappointing; in psychology r = 0.3 can be important.
Does correlation mean causation?
No. A strong correlation can come from a third variable affecting both, from reverse causation, or from coincidence. Ice cream sales and drowning deaths correlate because both rise in summer.
Can I predict outside my data range?
Extrapolating beyond the smallest and largest x in your data is risky: the relationship may bend or stop. The calculator will compute it, but flags predictions outside the observed range.
What is the p-value for the slope?
It tests whether the true slope is zero, meaning no linear relationship. It uses t = slope ÷ SE(slope) with n − 2 degrees of freedom, and is identical to testing whether r = 0.