Linear Regression & Correlation
Fit a least-squares line to x,y pairs: slope, intercept, r and R², standard errors, t and p for the slope, a confidence interval, residuals and a chart.
The equation y = a + b·x, r and R², standard errors, t and p-value for the slope, its confidence interval, the residual standard error, a residual table and a chart with the fitted line.
Example: (1,2) (2,4) (3,5) (4,4) (5,5) → y = 2.2 + 0.6·x, r = 0.7746, R² = 0.60, slope SE 0.283, t = 2.12 on 3 df, p = 0.124; ŷ(6) = 5.8 flagged as extrapolation.
Least squares,
then honest error bars.
How the line is fitted, what the statistics mean, and what the p-value assumes.
Fitting the line
Ordinary least squares picks the line that makes the squared vertical distances from the points as small as possible. With Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ), the slope is b = Sxy ÷ Sxx and the intercept a = ȳ − b·x̄. The correlation r = Sxy ÷ √(Sxx·Syy) runs from −1 to 1 and R² = r² is the share of the variation in y the line explains.
Standard errors and the test
The residual standard error s = √(SSE ÷ (n − 2)) is the typical vertical miss. The slope’s standard error is s ÷ √Sxx and the intercept’s s·√(1/n + x̄²/Sxx). t = b ÷ SE(b) on n − 2 degrees of freedom tests whether the slope could be zero; the confidence interval is b ± t·SE(b) with the shared t distribution. A prediction ŷ = a + b·x outside the observed x range is flagged as extrapolation.
What it assumes
The p-value and interval assume independent points, residuals roughly normal with the same spread everywhere, and a relationship that really is a straight line — look at the residual table for a pattern. Correlation is association, not cause. Nothing leaves the browser; the same four anonymous usage counts as the rest of the site apply.
SOURCES
- Ordinary least squares: b = Sxy/Sxx, a = ȳ − b·x̄, r = Sxy/√(Sxx·Syy); SE of the slope s/√Sxx with s = √(SSE/(n − 2)); t distribution on n − 2 df for the p-value and interval
Last reviewed 21 September 2026. How results are checked: How we verify.