What linear regression does
Simple linear regression finds the straight line that sits closest to a set of points. "Closest" means the line that makes the sum of the squared vertical distances between the points and the line as small as possible, which is why it is called the least-squares line. You can then use the line to describe the trend or to predict y for a new x.
The formulas
b = Sxy ÷ Sxx a = ȳ − b·x̄ ŷ = bx + a
- Sxx = Σ(x − x̄)², how much the x values vary.
- Sxy = Σ(x − x̄)(y − ȳ), how x and y vary together.
- b is the slope: how much y changes, on average, when x goes up by 1.
- a is the intercept: the predicted y when x is 0.
Example
x: 1, 2, 3, 4, 5 and y: 2, 4, 5, 4, 5.
- x̄ = 3, ȳ = 4.
- Sxx = 10, Sxy = 6, Syy = 6.
- b = 6 ÷ 10 = 0.6; a = 4 − 0.6 × 3 = 2.2.
- Line: ŷ = 0.6x + 2.2.
- r = 6 ÷ √(10 × 6) ≈ 0.7746, so R² = 0.6.
Reading r and R²
- r (correlation) runs from −1 to 1. The sign gives the direction; the size gives the strength. As a rough guide, |r| above 0.8 is strong, 0.5 to 0.8 moderate, 0.3 to 0.5 weak.
- R² is the share of the variation in y that the line explains. An R² of 0.6 means 60% of the ups and downs in y follow the line; the other 40% is not explained by x.
A high R² does not prove that x causes y. It only shows that a straight line describes the data well.
Check before you trust the line
- Look at the plot. A curved pattern can still give a decent r, but a straight line is the wrong model for it.
- Watch for outliers. One extreme point can tilt the whole line. Try the fit with and without it.
- Do not stretch predictions. Predicting far outside your range of x values (extrapolation) is unreliable. The calculator warns you when you do it.
Frequently asked questions
How do you calculate a line of best fit?
Find the means of x and y, then the slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², and the intercept a = ȳ − b·x̄. The line is ŷ = bx + a.
What is the difference between r and R²?
r is the correlation coefficient and shows direction and strength, from −1 to 1. R² is r squared in simple linear regression and shows the share of variation in y explained by the line, from 0 to 1.
How many data points do I need?
At least two, but two points always fit a line perfectly. For a meaningful result use more, ideally 10 or more.
Can I paste data from Excel?
Yes. Paste each column into the x and y boxes, or switch to x, y pairs and paste two columns at once.
Does this match Excel's SLOPE, INTERCEPT and RSQ?
Yes. It uses the same ordinary least-squares method, so the slope, intercept and R² match Excel's SLOPE, INTERCEPT and RSQ functions.
Last checked: 2026-12-03. How we test our calculators.