Linear Regression Slope & Intercept Calculator
Fit a least-squares line y = a + bx to paired data and get the slope, intercept, correlation and the full regression equation.
How it works
b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² · a = ȳ − b·x̄ · line: y = a + b·x
Ordinary least-squares regression finds the single straight line that minimises the sum of squared vertical gaps between the points and the line. The slope b is the covariance of X and Y divided by the variance of X, and the intercept a is fixed by forcing the line through the point of averages (x̄, ȳ). Together they give a predictive equation, while r² reports how much of Y’s spread the line accounts for.
Worked example
For X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 6, the means are x̄ = 3 and ȳ = 4.2. The cross-deviation sum is 8 and Σ(x − x̄)² is 10, so b = 8 ÷ 10 = 0.8 and a = 4.2 − 0.8 × 3 = 1.8. The fitted line is y = 0.8x + 1.8, predicting y = 6.6 when x = 6.
Sources: Simple linear regression — Wikipedia
Frequently asked questions
What is the difference between the slope and the correlation?
The slope is in the units of the data — how many units Y moves per unit of X — while the correlation r is a unitless number between −1 and 1 describing how tightly the points hug the line. Two data sets can share the same r but have very different slopes.
Which variable should be X?
X is the predictor (independent variable) and Y is the response you want to predict. Swapping them gives a different line, because least squares minimises vertical error in Y only, so choose X and Y based on which you are predicting from which.
Can I use the equation to extrapolate far beyond the data?
Cautiously at best. A regression line describes the range you fitted; pushing it well past your observed X values assumes the straight-line pattern keeps holding, which often fails and can give misleading predictions.
Related calculators
For education — check the assumptions (sample size, independence, distribution) before using these statistics in real decisions.