Correlation and linear regression calculator
Least-squares line, r and r², slope p-value, confidence and prediction intervals, residuals point by point.
The scatter and its line
Awaiting the quantities required for the calculation.
Result
computed on commandAwaiting the quantities required for the calculation.
Calculation, assumptions and sources
OverviewTwo columns of measurements give the least-squares line, Pearson’s correlation coefficient r and r², the standard error and confidence interval of the slope and intercept, the p-value of the zero-slope test, the residuals and, on request, a prediction with its confidence and prediction intervals.
Two columns of measurements give the least-squares line, Pearson’s correlation coefficient r and r², the standard error and confidence interval of the slope and intercept, the p-value of the zero-slope test, the residuals and, on request, a prediction with its confidence and prediction intervals.
Method & formulasr = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²)
The least-squares line minimises the sum of squared vertical departures. The residuals sum to zero and the line passes through the mean point (x̄, ȳ). The unitless coefficient r 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.
- Residual
- gap between the observed y and the y fitted by the line.
- se
- standard deviation of the residuals, in the unit of y.
- Confidence interval
- brackets the mean of y at a given x (the position of the line).
- Prediction interval
- brackets a new observation; wider than the confidence interval, it adds individual scatter.
Validity domainA correlation does not establish causation: a high r may come from a link one way or the other, a third factor acting on both, or chance.
A correlation does not establish causation: a high r may come from a link one way or the other, 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. Outside the observed range of x, a prediction is an extrapolation: the line was not checked there.
Reading the resultThe sign of r gives the direction of the relationship, its absolute value the strength.
The sign of r gives the direction of the relationship, its absolute value the strength. On a large sample a tiny slope can be significant; on five points a strong slope may prove nothing. Residuals that follow a curve indicate a non-linear relationship; one residual that dwarfs the others indicates a single point holding the line. Anscombe built four datasets with identical statistics and different shapes, including a parabola and one where a single outlier fixes the line. On the figure, the thick stroke brackets the mean of y, the thin stroke a new observation.