Skip to content
Tech Interview Prep
Technical interview guide

Regression Analysis

Modeling a relationship between variables: linear regression's assumptions, and what R² does and doesn't tell you.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v7
Editorial status
Reviewed

Scope: Standards and library references current as of 2026-09: NIST/SEMATECH e-Handbook, statsmodels, scikit-learn, and SciPy.

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

β^=(X⊤X)−1X⊤y\hat{\beta}=(X^{\top}X)^{-1}X^{\top}y VIFj=11−Rj2\mathrm{VIF}_j=\frac{1}{1-R_j^2} y^0±tn−p−1 se(y^0)(mean response)y^0±tn−p−1s2+se(y^0)2(new observation)\hat{y}_0 \pm t_{n-p-1}\,\mathrm{se}(\hat{y}_0)\quad\text{(mean response)}\qquad \hat{y}_0 \pm t_{n-p-1}\sqrt{s^2+\mathrm{se}(\hat{y}_0)^2}\quad\text{(new observation)}

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

  1. 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.
  2. 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.
  3. Independent, constant-variance errors are needed for valid standard errors. Violations leave coefficients unbiased but make intervals wrong.
  4. Plot residuals against fitted values first. A funnel signals heteroskedasticity, a bend signals a missing transformation, and clusters signal a missing grouping variable.
Talent Admission Test score Conditioning on admission

When to use and when not to

SituationUse OLS?Prefer instead
Mean relationship, few predictors, interpretation neededYes, with robust or HAC errorsNone
Binary outcomeNoLogistic regression, with a separation check
Count outcomeNoPoisson or negative binomial with an exposure offset
Many correlated predictors, prediction goalNot as the final modelRidge or lasso, scaled inside the pipeline
Causal question from observational dataCoefficient alone is insufficientCausal diagram, randomisation
Prediction outside the fitted rangeNoA validated mechanism

Traps interviewers probe

  1. 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.
  2. 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.
  3. 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.
  4. Controlling for everything. Conditioning on a collider manufactures association. Fix: choose controls from a causal diagram, never by which ones improve fit.
  5. 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:

  1. Define the fit in one sentence: linear in parameters, minimising squared residuals.
  2. State what the coefficient means, including the holding-fixed clause.
  3. Name one check, such as the residual plot or robust standard errors.
  4. Say what decision the result drives and what would change it.
  5. 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.