Overview
Curated: · Written: · Reviewed:
Regression Analysis
In one line
Ordinary least squares fits a model that is linear in its parameters by minimising squared residuals. Reach for it when you need an interpretable mean relationship or a prediction interval, and check the assumptions before quoting any standard error or coefficient.
Key definitions
- Residual: observed minus fitted value. Every diagnostic examines these.
- Partial coefficient: expected change in the outcome per unit of one predictor, holding the others fixed.
- Heteroskedasticity: error variance that changes across fitted values. It biases standard errors, not coefficients.
- Leverage and Cook's distance: leverage measures how unusual a predictor value is; Cook's distance measures how far a point actually moves the fit.
- Variance inflation factor: 1/(1 - R_j^2), the inflation of a coefficient's variance from correlation with the other predictors.
- Collider: a variable caused by two others. Conditioning on it creates an association between them.
Formulas and complexity
OLS is a single linear solve over an n by p design matrix, with no iteration. Cook's distance above 4/n is the usual flag.
How it works
- The fit minimises the sum of squared residuals. Because the model is linear in parameters, the solution is closed form and cannot stop at a local minimum.
- Squaring lets one extreme point dominate. On y = 2x + 1 over x = 0 to 4, setting the last reading to 29 moves the slope from 2 to 6.
- Independent, constant-variance errors are needed for valid standard errors. Violations leave coefficients unbiased but make intervals wrong.
- Plot residuals against fitted values first. A funnel signals heteroskedasticity, a bend signals a missing transformation, and clusters signal a missing grouping variable.
When to use and when not to
| Situation | Use OLS? | Prefer instead |
|---|---|---|
| Mean relationship, few predictors, interpretation needed | Yes, with robust or HAC errors | None |
| Binary outcome | No | Logistic regression, with a separation check |
| Count outcome | No | Poisson or negative binomial with an exposure offset |
| Many correlated predictors, prediction goal | Not as the final model | Ridge or lasso, scaled inside the pipeline |
| Causal question from observational data | Coefficient alone is insufficient | Causal diagram, randomisation |
| Prediction outside the fitted range | No | A validated mechanism |
Traps interviewers probe
- Reading R-squared as fit quality. It never falls when a predictor is added and says nothing about residual pattern or error on new data. Fix: plot residuals and compare models on held-out error or an information criterion.
- Quoting a correlated coefficient as a marginal effect. With predictors correlated at 0.90, the partial coefficient describes a comparison the data rarely contains. Fix: state the holding-fixed comparison and report predicted values.
- Trusting default standard errors under heteroskedasticity or autocorrelation. Fix: use HC3 or HAC errors and check Durbin-Watson. A t of 4.2 can fall well below 2 once the effective sample size is corrected.
- Controlling for everything. Conditioning on a collider manufactures association. Fix: choose controls from a causal diagram, never by which ones improve fit.
- Reading a huge coefficient under separation as a huge effect. A coefficient of 24.7 with a standard error of 12,400 signals perfect separation. Fix: check convergence and standard errors, then use a penalised fit.
Interview tips
Opening: "Least squares gives the best linear approximation of the mean. First I need to know whether the goal is prediction or an effect, because that decides the specification and the evaluation."
Expect these follow-ups:
- What does a coefficient mean when predictors correlate?
- Why is R-squared an unreliable model comparison?
- How do you detect and handle heteroskedasticity?
- When is a prediction interval the right interval?
- Why does lasso keep one of two duplicate columns?
30-second outline:
- Define the fit in one sentence: linear in parameters, minimising squared residuals.
- State what the coefficient means, including the holding-fixed clause.
- Name one check, such as the residual plot or robust standard errors.
- Say what decision the result drives and what would change it.
- Name the main caveat: outliers, correlated errors, or the causal gap.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.