Correlation and linear regression
r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²)
Paste two columns of measurements: the tool computes Pearson’s correlation coefficient, the least-squares line, the share of variance explained, the standard error and confidence interval of the slope and intercept, the p-value of the hypothesis that the slope is zero, the residual of every point, and, on request, a prediction with both its confidence interval and its prediction interval. Extrapolation beyond the observed range is flagged, and the difference between correlation and causation is stated where it matters.
Scientific dossier
What the tool computes, what it assumes, where it stops being valid, and where its data comes from.
Method & formulasr = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²)
r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²)
slope = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²
intercept = ȳ − slope × x̄
s_e = √(Σ(y − ŷ)² / (n − 2))
CI(slope) = slope ± t × s_e / √(Σ(x − x̄)²)
The least-squares line is the one making the sum of squared vertical departures as small as possible. Two properties follow and serve as checks here: residuals sum to exactly zero, and the line passes through the mean point (x̄, ȳ). The coefficient r is the same quantity as the slope, stripped of units: it equals the slope times the standard deviation of x divided by that of y.
- r
- · Pearson correlation coefficient, between −1 and 1. Unitless.
- r²
- · share of the variance of y explained by the line. 0.64 means 64% explained, 36% left over.
- Residual
- · gap between the observed y and the y fitted by the line.
- s_e
- · standard deviation of the residuals: the typical error of the line, in the unit of y.
- Confidence interval
- · brackets the position of the line, that is, the mean of y at a given x.
- Prediction interval
- · brackets a new observation. Always wider: it adds individual scatter.
Validity domainA correlation is not a causation: a high r may come from a link one way, the other way, a third factor acting on both, or chance.
A correlation is not a causation: a high r may come from a link one way, the other way, a third factor acting on both, or chance. The inference (p-value, intervals) assumes independent residuals with constant variance and close to a normal law; it needs at least three points, since two determine the line exactly and leave no residual to measure. Sums of squares are computed from deviations about the mean rather than Σx² − n x̄², which loses precision as soon as the data sit far from zero, years for instance. A prediction outside the observed range of x is flagged as extrapolation: the line was never checked there, and the interval shown assumes the relationship continues.
Reading the resultThe sign of r gives the direction of the relationship, its absolute value the strength, and r² the share of variance explained, which is the more honest reading of the two.
The sign of r gives the direction of the relationship, its absolute value the strength, and r² the share of variance explained, which is the more honest reading of the two. The p-value answers a different question: is this data enough to rule out a zero slope? A significant slope on a large sample can still be tiny, and a strong slope on five points may prove nothing. The residual column is the one to read last and the one that says the most: if residuals follow a curve, the relationship is not linear; if one dwarfs the others, a single point holds the line.