How it works
Linear regression fits the straight line y = a + bx that minimizes the sum of squared vertical distances (residuals) between the points and the line. The slope b is how much y changes for each one-unit increase in x; the intercept a is the predicted y when x is 0.
R² is the share of the variation in y explained by the line. An R² of 0.95 means the line accounts for 95% of the variation; the rest is scatter around it.
Predictions inside the range of your x values (interpolation) are usually more reliable than predictions outside it (extrapolation), where the linear pattern may not hold.
Formula
b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² · a = ȳ − b·x̄ · R² = 1 − SSE ÷ SST
Questions people ask
What is a good R² value?
It depends on the field. Physical measurements often give R² above 0.9, while social and behavioral data with an R² of 0.3 can still be useful. A high R² does not prove the relationship is causal.
What are residuals?
A residual is the actual y minus the predicted y. Residuals that show a pattern (such as a curve) suggest a straight line is not the right model.
Is R² the same as r squared?
For simple linear regression with one x variable, yes: R² equals the square of the Pearson correlation r.