What a regression line claims
A regression model makes three separable claims: that the relationship is linear in the parameters, that the average residual behaviour is stable across the range of the predictors, and that the residuals are independent draws with constant variance. When those claims hold, the coefficient estimates are the best linear unbiased estimators available, the standard errors are correct, and the p-values mean what they say. When they fail, the coefficients are usually still describable as the best linear projection, but the inference around them â the intervals, the t statistics, the claims of significance â is miscalibrated.
That distinction matters more than the algebra. Practitioners rarely get in trouble deriving the closed-form solution; they get in trouble reporting a coefficient with a confidence interval computed under violated assumptions. The workflow that works is therefore estimation first, diagnostics second, interpretation third. Fit the model, inspect the residuals, repair or reformulate if needed, and only then read the coefficients as effects.
Least squares: the estimator and its closed form
Ordinary least squares chooses the coefficients that minimise the sum of squared residuals â the vertical distances between each observation and the fitted plane. Squaring has two consequences worth internalising. It makes the objective smooth and uniquely minimised whenever the predictors are not perfectly collinear, and it makes large residuals disproportionately expensive, which is why a single outlier can rotate the fitted line noticeably.
For simple regression the solution is explicit. The slope is the covariance of x and y divided by the variance of x, which is why the slope is positive exactly when the two move together, and the intercept follows from forcing the line through the sample means. In matrix form the same result is the familiar hat formula: the coefficient vector is the inverse of the predictor cross-product times the cross-product of predictors and outcomes. That expression also reveals the fragility â if the cross-product matrix is nearly singular, the inverse explodes, which is the algebraic face of multicollinearity.
| Quantity | Formula | Interpretation |
|---|---|---|
| Slope | Cov(x, y) divided by Var(x) | Change in y for a one-unit rise in x |
| Intercept | Mean of y minus slope times mean of x | Expected y when every predictor is zero |
| Fitted values | Design matrix times coefficient vector | The model's point predictions |
| Residuals | Observed minus fitted | What the model failed to explain |
| Residual standard error | Square root of residual sum of squares over n minus p minus one | Typical size of an unexplained deviation |
Reading coefficients in multiple regression
Each coefficient in a multiple regression is a partial effect: the expected change in the outcome for a one-unit increase in that predictor while every other predictor is held fixed. That ceteris paribus reading is the reason multiple regression is useful and also the reason it is easy to misstate. If two predictors move together in the data, holding one fixed while varying the other describes a situation that scarcely occurs, and the coefficient becomes an unstable extrapolation rather than an effect you can act on.
Standardisation makes coefficients comparable across predictors measured on different scales, and comparing magnitudes is usually the point of a feature-importance discussion. But comparing raw coefficients from variables in different units â income in dollars against age in years â is meaningless. The same caution applies to the intercept: it is the expected outcome when all predictors are zero, and for most datasets that combination is far outside the observed range, making the intercept a mathematical anchor rather than a quantity to interpret.
R-squared, adjusted R-squared, and honest fit
R-squared is the share of variance in the outcome that the fitted model removes relative to always predicting the mean. It has an appealing geometric reading: the squared correlation between observed and fitted values in simple regression. Its weakness is that it cannot decrease when a predictor is added, even if that predictor is pure noise, because the least-squares fit can always shave off a little more residual variance by chance.
Adjusted R-squared answers that objection by dividing the explained variance by the number of predictors, so a useless variable now costs more than it earns. The gap between the two is a quick diagnostic: a large gap suggests some predictors are contributing little. Information criteria such as AIC and BIC make the same trade-off explicit with different penalties, and cross-validated error replaces in-sample fit entirely when prediction rather than explanation is the goal. An R-squared of zero point eight five is not evidence of a good model; it is evidence that the model tracks this sample well, which is a different claim.
The five diagnostics that decide whether to trust it
Linearity is checked with a plot of residuals against fitted values: a curved systematic pattern means the mean structure is wrong and needs polynomial terms, an interaction, or a transform. Normality of residuals matters for small samples and is checked with a Q-Q plot; heavy tails widen the true interval relative to the reported one. Homoscedasticity means the residual spread is constant â a funnel shape signals otherwise, and the fix is weighted least squares or heteroscedasticity-consistent standard errors.
Independence fails most often when the rows are ordered in time, which inflates apparent significance; the Durbin-Watson statistic or a residual autocorrelation plot detects it, and the remedy is a time-series model or clustered standard errors. Multicollinearity is diagnosed with variance inflation factors: a value above ten means the predictor is well explained by the others and its individual coefficient is unreliable, even though the model's predictions may be fine. Collinearity damages interpretation, not necessarily prediction, which is why regularised methods can still predict well after ordinary regression becomes uninterpretable.
Fitting and checking a model in Python
import numpy as np
def ols_fit(X, y):
"""Ordinary least squares with diagnostics. X includes a column of ones."""
beta, *_ = np.linalg.lstsq(X, y, rcond=None)
fitted = X @ beta
resid = y - fitted
n, p = X.shape
ss_res = float(resid @ resid)
ss_tot = float(((y - y.mean()) ** 2).sum())
r2 = 1 - ss_res / ss_tot
adj = 1 - (1 - r2) * (n - 1) / (n - p)
sigma2 = ss_res / (n - p)
cov = sigma2 * np.linalg.inv(X.T @ X)
se = np.sqrt(np.diag(cov))
return beta, se, r2, adj, resid
rng = np.random.default_rng(9)
n = 120
x1 = rng.normal(0, 1, n)
x2 = rng.uniform(0, 10, n)
y = 3 + 2.5 * x1 - 0.4 * x2 + rng.normal(0, 1.5, n)
X = np.column_stack([np.ones(n), x1, x2])
beta, se, r2, adj, resid = ols_fit(X, y)
names = ["intercept", "x1", "x2"]
for name, b, s in zip(names, beta, se):
print(f"{name:9s} {b:7.3f} (se {s:.3f}) t = {b / s:6.2f}")
print(f"R2 = {r2:.3f} adjusted R2 = {adj:.3f}")
vif = []
for j in range(1, X.shape[1]):
others = np.delete(X, j, axis=1)
b, _, r2_j, _, _ = ols_fit(others, X[:, j])
vif.append(1 / (1 - r2_j))
print("VIF:", np.round(vif, 2))
The printed coefficients match the data-generating values closely, and the variance inflation factors confirm that these two predictors are essentially orthogonal, so each coefficient is estimated with full precision. Replacing x2 with a noisy copy of x1 would push those factors above ten and blow up the standard errors while leaving R-squared barely changed.
The second block walks through the residual diagnostics that decide whether the first block's output can be believed.
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
def residual_report(resid, fitted):
z = (resid - resid.mean()) / resid.std(ddof=1)
_, r, _, _, _ = stats.probplot(resid, dist="norm")
_, shapiro_p = stats.shapiro(resid)
third = np.quantile(fitted, [0.0, 0.33, 0.66, 1.0])
bands = [resid[(fitted >= third[i]) & (fitted < third[i + 1])]
for i in range(3)]
_, levene_p = stats.levene(*bands)
print(f"shapiro p = {shapiro_p:.4f}, levene p = {levene_p:.4f}")
print(f"Q-Q correlation = {r:.3f}")
print(f"residual skew = {np.mean(z ** 3):.3f}, "
f"kurtosis = {np.mean(z ** 4) - 3:.3f}")
fig, ax = plt.subplots(1, 2, figsize=(10, 4))
ax[0].scatter(fitted, resid, alpha=0.6)
ax[0].axhline(0, color="red", lw=1)
ax[0].set_xlabel("fitted")
ax[0].set_ylabel("residual")
stats.probplot(resid, dist="norm", plot=ax[1])
plt.tight_layout()
plt.show()
residual_report(resid, X @ beta)
The fitted-versus-residual panel should look like an unstructured cloud around zero; any funnel or curve is a specific complaint with a specific fix. The Q-Q panel judges the tails, and the printed skew and kurtosis quantify what the eye is seeing.
Regression mistakes that invalidate inference
Common Mistakes
Interpreting a coefficient as causal from observational data
Fix: State the association explicitly, or justify the identification assumptions needed for a causal reading.
Fitting straight lines to clearly curved relationships
Fix: Plot residuals against fitted values first; add polynomials, interactions, or a transform when a pattern appears.
Trusting standard errors under funnel-shaped residuals
Fix: Use heteroscedasticity-consistent standard errors or weighted least squares.
Reporting R-squared as evidence of model quality
Fix: Pair it with adjusted R-squared and cross-validated error, which penalise needless complexity.
Ignoring predictors with variance inflation factors above ten
Fix: Drop or combine the collinear predictors, or switch to a regularised fit for prediction.
Extrapolating beyond the observed range of a predictor
Fix: Predictions outside the data are model assumptions, not estimates; state the supported range.
Best Practices
- Always plot residuals against fitted values before quoting any coefficient.
- Scale predictors when comparing coefficient magnitudes across different units.
- Report coefficients with standard errors and intervals, not bare point estimates.
- Check the Durbin-Watson statistic whenever rows are ordered in time.
- Validate predictive claims with held-out data rather than in-sample fit.
Regression essentials
Where to go next
- Simple Linear Regression derives the least-squares solution geometrically and algebraically.
- Regression Assumptions details what each Gauss-Markov condition buys you.
- Residual Analysis covers influence measures, Cook's distance, and leverage.
- Multicollinearity explains variance inflation and the remedies that preserve prediction.