Chapter 1 — Derivations
Seventeen derivations cover every regression proof an interviewer can reasonably ask for; Cards 14–17 are for research and quant roles. Each card has the same five parts: the statement, the derivation (4–8 lines), the key move that unlocks it, the common slip, and how it's asked. Learn the four tools first — every card is those tools in a different order.
The toolkit: four moves
Every derivation below is some combination of these four. Memory hook: D-V-T-A — Differentiate, Variance, Trace, Add-and-subtract.
1. Differentiate (matrix calculus). Two rules cover all of regression:
- \frac{\partial}{\partial \mathbf w}
- how fast the expression after it changes as you nudge each weight, holding the rest fixed: a slope, not a fraction to divide
- \mathbf w
- the weight vector, one weight per feature (bold = a vector)
- \mathbf a
- a fixed vector that doesn't depend on \mathbf w
- ^\top
- transpose: rows become columns, so \mathbf a^\top \mathbf w is a single number
- A
- a fixed square matrix that doesn't depend on \mathbf w
Intuition: these are the matrix versions of d(ax)/dx = a and d(ax^2)/dx = 2ax.
2. Variance of a linear transform. For a fixed matrix A and random vector \varepsilon:
- \mathbb E
- expected value: the average over many repeated draws of the noise
- \boldsymbol\varepsilon
- the noise vector: every house's error (luck, haggling) stacked in one column
- \text{Var}
- covariance matrix: each entry's variance on the diagonal, pairwise covariances off it
Intuition: the scalar rule \text{Var}(a\varepsilon) = a^2\,\text{Var}(\varepsilon), with a^2 written as A \cdot A^\top. Its covariance cousin, used in every Level 4 problem: Cov is bilinear — \text{Cov}(X + Z, X + u) splits into four pairwise terms, and independence zeroes the cross terms.
3. The trace trick. For a quadratic form in a random vector with \text{Var}(\varepsilon) = \sigma^2 I:
- M
- any fixed n \times n matrix (later, the residual maker I - H)
- \sigma^2
- the noise variance: how far each house's price scatters around the true line
- \text{tr}
- trace: the sum of a matrix's diagonal entries
- B
- another fixed matrix, shaped so both AB and BA exist
Intuition: a scalar equals its own trace, and the trace lets you rotate matrices so the expectation lands on \varepsilon\varepsilon^\top.
4. Add and subtract. To split an error into parts, insert a term and remove it again: (a - c) = (a - b) + (b - c). Expand the square and show the cross term has zero expectation. This one move gives every bias–variance decomposition.
Two matrix facts you'll also need: the hat matrix H = X(X^\top X)^{-1}X^\top and M = I - H are both symmetric and idempotent (HH = H — projecting twice changes nothing), and \operatorname{tr}(H) = p.
Formulas to memorize
Memorize these 22 cold. Everything else in the chapter can be derived from them in a minute or two. Each label says which card proves it, so a formula you forget can always be rebuilt.
Fitting
1. Simple slope and intercept (Card 1)
- w
- the fitted slope: $k of price per extra sq ft
- S_{xy}
- \sum_i (x_i - \bar x)(y_i - \bar y): how size and price move together
- S_{xx}
- \sum_i (x_i - \bar x)^2: how spread out the sizes are
- r
- the correlation between size and price, from −1 to 1
- s_y
- the standard deviation of the prices
- s_x
- the standard deviation of the sizes
- b
- the fitted intercept: the line's price for a 0 sq ft house
- \bar y
- the average price over all houses (bar = mean)
- \bar x
- the average size
2. Normal equation (Card 2)
- X
- the design matrix: one row per house, one column per feature
- ^\top
- transpose: rows become columns
- X^\top X
- the p \times p table of feature sums of squares and cross-products
- \hat{\mathbf w}
- the fitted weight vector (hat = estimated from data, bold = a vector)
- \mathbf y
- the column of all n actual prices
- (X^\top X)^{-1}
- the inverse of X^\top X: the matrix that undoes it
3. Hat matrix, leverage, orthogonality (Cards 2, 7)
- H
- the hat matrix: turns actual prices into fitted ones, \hat{\mathbf y} = H\mathbf y
- h_{ii}
- house i's leverage: how strongly its own price pulls its own fit
- [H]_{ii}
- the i-th diagonal entry of H (row i, column i)
- \textstyle\sum_i
- add up over every house i
- p
- the number of fitted weights (features, counting the intercept)
- \mathbf e
- the residual vector: each house's actual minus fitted price
4. Variance decomposition and R^2 (Card 4)
- \text{TSS}
- total sum of squares: how much prices vary around their mean
- \text{ESS}
- explained sum of squares: the part of that variation the line captures
- \text{RSS}
- residual sum of squares: the part left over, \sum_i e_i^2
- R^2
- the share of price variation the line explains, from 0 to 1
- R^2_{\text{adj}}
- adjusted R^2: docked for each extra feature, so useless features can't inflate it
- n
- the number of houses (rows)
Inference
5. Coefficient covariance (Card 6)
- \text{Var}
- variance (a covariance matrix for a vector): how much it wobbles across repeated samples
- \mid X
- given X: the houses' features held fixed, only the noise redrawn
- \sigma^2
- the noise variance: how far prices scatter around the true line
- \hat w
- the fitted slope when size is the only feature
6. Robust (sandwich) covariance (Card 6)
- \Omega
- the noise covariance matrix: each house's own error variance on the diagonal, possibly unequal
7. Unbiased noise variance (Card 7)
- s^2
- the estimate of the noise variance \sigma^2, built from the residuals
- \mathbb E
- expected value: the average over many repeated samples
8. t statistic and confidence interval (Card 6)
- t
- the t statistic: how many standard errors the weight sits from 0
- \hat w_j
- the fitted weight on feature j
- \text{SE}(\hat w_j)
- its standard error: the typical wobble of \hat w_j across samples
- t_{0.975,\,n-p}
- the 97.5th percentile of a t distribution with n - p degrees of freedom (≈ 2 for large n)
9. Confidence vs prediction interval (Cards 6, 12)
- \hat y_0
- the predicted price for a new house
- t
- here the critical value t_{0.975,\,n-p} from formula 8
- s
- \sqrt{s^2}: the estimated noise standard deviation, in $k
- \mathbf x_0
- the new house's feature vector
10. Moulton factor (Card 16)
- \text{Var}_{\text{true}}(\hat w)
- the slope's actual variance when errors within a group are correlated
- \text{Var}_{\text{naive}}(\hat w)
- the variance the usual formula reports, assuming independent errors
- m
- the number of houses in each group (e.g. each neighbourhood)
- \rho_x
- how correlated the feature is within a group (1 if shared, like a school rating)
- \rho_\varepsilon
- how correlated the errors are within a group
Bias
11. Omitted-variable bias (Card 9)
- \hat\beta_1
- the fitted slope on size when the omitted feature is left out
- \beta_1
- the true effect of size on price
- \gamma
- the omitted feature's true effect on price
- \delta
- the slope from regressing the omitted feature on size: how they move together
- \text{Cov}
- covariance: how two quantities move together
- x
- the included feature (size)
- z
- the omitted feature (e.g. neighbourhood quality)
12. Attenuation from measurement error (Card 10)
- \text{plim}
- probability limit: where the estimate settles with endless data
- \hat\beta
- the slope fitted on the noisily measured size
- \beta
- the true slope of price on size
- \sigma^2_{x^*}
- the variance of the true sizes x^* (the signal)
- \sigma^2_u
- the variance of the measurement noise u in recorded size
13. Fixed-effects (within) estimator (Card 14)
- y_{it}
- house i's price at its sale in year t (each house sells several times)
- \bar y_i
- house i's average price over its sales
- x_{it}
- house i's feature at that sale (e.g. size after renovations)
- \bar x_i
- house i's average of that feature
- \varepsilon_{it}
- the noise on that sale
- \bar\varepsilon_i
- house i's average noise over its sales
14. Probit with an omitted independent variable (Card 17)
- \hat\beta
- the probit slope fitted with the independent variable z left out
- \beta
- the true probit slope on x
- \gamma
- the omitted variable z's true effect on the hidden score
- \sigma_z^2
- the variance of the omitted variable z
- \pi^2/3
- the variance of the logistic error, which logit fixes in place of probit's 1
Regularization and prediction
15. Ridge (Card 11)
- \hat{\mathbf w}_{\text{ridge}}
- the ridge weights: least squares plus a penalty on large weights
- \lambda
- the penalty strength you choose; bigger shrinks the weights more
- I
- the identity matrix: 1s on the diagonal, 0s elsewhere
- ^{-1}
- matrix inverse: undoes the matrix
- \hat{\mathbf w}_{\text{OLS}}
- the plain least-squares weights, no penalty
16. Lasso soft threshold (Card 11)
- \hat w_j^{\text{lasso}}
- the lasso weight on feature j
- \text{sign}
- +1 if positive, −1 if negative: keeps the weight's direction
- |\hat w_j|
- the size of the OLS weight, ignoring its sign
17. Expected prediction error (Card 12)
- y_0
- the actual price of a new house
- \hat f(\mathbf x_0)
- the model's prediction for that house (hat = learned from training data)
- \text{Bias}^2
- squared gap between the average prediction and the true price function
18. Training vs test error (Card 15)
- \text{train MSE}
- mean squared error on the houses the model was fit to
- \text{test MSE}
- mean squared error on fresh prices at those same houses
Diagnostics
19. Leave-one-out residual (Card 13)
- e_{(-i)}
- house i's leave-one-out residual: its miss when the line is fit without it
- e_i
- house i's ordinary residual from the full fit
20. Cook's distance (Card 13)
- D_i
- Cook's distance: how far all fitted prices move if house i is dropped
21. Variance inflation factor
- \text{VIF}_j
- variance inflation factor: how much collinearity inflates \hat w_j's variance
- R_j^2
- the R^2 from regressing feature j on all the other features
22. Matrix-calculus rules (Tool 1)
- \partial
- how fast the top changes as you nudge the bottom, holding the rest fixed: a slope, not a fraction to divide
- \mathbf a
- a fixed vector that doesn't depend on \mathbf w
- \mathbf w
- the weight vector, one weight per feature (bold = a vector)
- A
- a fixed square matrix that doesn't depend on \mathbf w
- \boldsymbol\varepsilon
- the noise vector: every house's error stacked in one column
Fitting the line — Cards 1–4
Card 1 — OLS for one feature, by hand
Statement. For \hat y = b + wx, least squares gives:
- b
- the fitted intercept: the line's price for a 0 sq ft house
- w
- the fitted slope: $k of price per extra sq ft
- \bar y
- the average price over all n houses (bar = mean)
- \bar x
- the average size
- S_{xy}
- \sum_i (x_i - \bar x)(y_i - \bar y): how size and price move together
- S_{xx}
- \sum_i (x_i - \bar x)^2: how spread out the sizes are
Derivation.
- L
- the loss: the total squared miss, as a function of b and w
- \sum_i
- add up over every house i
- y_i
- house i's actual sale price
- x_i
- house i's size
- \frac{\partial L}{\partial b}
- how fast the loss changes as you nudge b, holding w fixed: a slope, not a fraction to divide
- \frac{\partial L}{\partial w}
- how fast the loss changes as you nudge w, with b already solved out
Key move. Solve for b first. Substituting it back centers the data, and the slope falls out in one line.
Common slip. Writing \sum x_i y_i / \sum x_i^2. That's the slope of a line forced through the origin, not this one.
How it's asked. "Derive the least-squares estimates." · "Why does the fitted line pass through (\bar x, \bar y)?" (Because b = \bar y - w\bar x is exactly that statement.)
Card 2 — The normal equation
Statement. Minimizing the squared error gives the normal equation; the solution is unique when X has full column rank:
- \mathbf w
- the weight vector, one weight per feature (bold = a vector)
- \lVert
- length of a vector (closed by \rVert); squared, it's the sum of squared entries
- \mathbf y
- the column of all n actual prices
- X
- the design matrix: one row per house, one column per feature
- ^\top
- transpose: rows become columns
- X^\top X
- the p \times p table of feature sums of squares and cross-products
- \hat{\mathbf w}
- the fitted weights (hat = estimated from data)
Derivation.
- L
- the loss: the sum of squared residuals, now a function of the weight vector \mathbf w
- \nabla L
- the gradient: the vector of slopes of L, one per weight; points uphill
- (X^\top X)^{-1}
- the inverse of X^\top X: the matrix that undoes it
- \nabla^2 L
- the Hessian: the matrix of second derivatives, how the slopes themselves change
- \succeq 0
- is positive semi-definite: curves up (or stays flat) in every direction
Rearranged, the first-order condition says the residuals are orthogonal to every column:
- \mathbf e
- the residual vector: each house's actual minus fitted price
Key move. Expand, then use Tool 1. The two middle terms combine because y^\top X w is a scalar, so it equals its own transpose w^\top X^\top y.
Common slip. Writing (XX^\top)^{-1} instead of (X^\top X)^{-1} (check dimensions: X^\top X is p \times p), or assuming invertibility without full rank.
How it's asked. "Derive OLS in matrix form. When is it unique? Why is it a minimum and not a maximum?"
Card 3 — Least squares is maximum likelihood
Statement. With independent Gaussian noise, maximizing the likelihood over w is minimizing RSS, and the MLE of the noise variance divides by n:
- \mathbf x_i
- house i's feature vector (size, bedrooms, …)
- \varepsilon_i
- house i's error: how far its price lands from the true line
- \sim
- is distributed as
- N(0, \sigma^2)
- a normal (Gaussian) bell curve centred at 0 with variance \sigma^2
- \sigma^2
- the noise variance: how far prices scatter around the true line
- \hat{\mathbf w}_{\text{MLE}}
- the weights that make the observed prices most likely
- \hat{\mathbf w}_{\text{OLS}}
- the least-squares weights
- \hat\sigma^2_{\text{MLE}}
- the most-likely estimate of the noise variance
- \text{RSS}
- residual sum of squares: \sum_i e_i^2
- n
- the number of houses
Derivation.
- \mathcal L
- the likelihood: how probable the observed prices are, given \mathbf w and \sigma^2
- \prod_i
- multiply together over every house i (the errors are independent)
- \pi
- the constant 3.14159…, part of the normal curve's height
- \textstyle\sum_i
- add up over every house i
- \frac{\partial \log\mathcal L}{\partial \sigma^2}
- how fast the log-likelihood changes as you nudge the noise variance
- \sigma^4
- (\sigma^2)^2: the noise variance squared
Key move. The log turns a product into a sum, and only the exponent contains w.
Common slip. Thinking the MLE of \sigma^2 is unbiased. It divides by n and is biased low (Card 7).
How it's asked. "Why squared error?" · "What loss would Laplace noise give?" (absolute error — its log-density is -\lvert e \rvert / b) · "Is the MLE always unbiased?"
Card 4 — TSS = ESS + RSS, and R² = r²
Statement. With an intercept, total variation splits into explained plus residual; in simple regression, R^2 is the squared correlation:
- \text{TSS}
- total sum of squares: how much prices vary around their mean
- \text{ESS}
- explained sum of squares: the part of that variation the line captures
- R^2
- the share of price variation the line explains
- r
- the correlation between size and price
Derivation.
- \hat y_i
- the line's fitted price for house i
- e_i
- house i's residual: y_i - \hat y_i
- \textstyle\sum
- add up over every house
- S_{yy}
- \sum_i (y_i - \bar y)^2: how spread out the prices are (equals TSS)
Key move. Add and subtract \hat y (Tool 4); orthogonality kills the cross term.
Common slip. Using 1 - \text{RSS}/\text{TSS} for a model without an intercept. The cross term no longer vanishes, so the "decomposition" fails and R^2 can go negative.
How it's asked. "Show R^2 = r^2 in simple regression." · "When can R^2 be negative?"
Trusting the line — Cards 5–8
Card 5 — OLS is unbiased
Statement. If the model is linear, X has full rank and the errors are exogenous, OLS is unbiased:
- \mathbf y
- the column of all n actual prices
- X
- the design matrix: one row per house, one column per feature
- \boldsymbol\beta
- the true weights of the real-world model (unknown)
- \boldsymbol\varepsilon
- the noise vector: every house's error stacked in one column
- \mathbb E
- expected value: the average over many repeated samples
- \mid X
- given X: the houses' features held fixed, only the noise redrawn
- \hat{\mathbf w}
- the OLS weights fitted from the data (hat = estimated)
Derivation.
- ^\top
- transpose: rows become columns
- (X^\top X)^{-1}
- the inverse of X^\top X: the matrix that undoes it
Key move. Substitute the true model into the estimator. Every OLS proof starts here: estimate = truth + weighted noise.
Common slip. Saying it needs normality or constant variance (it doesn't), or that E[\varepsilon] = 0 is enough (it isn't — the noise must average zero at every X, which is exogeneity).
How it's asked. "Prove OLS is unbiased. Which assumptions did you use, and which didn't you?"
Card 6 — The variance of OLS, standard errors, and the sandwich
Statement. With equal-variance, uncorrelated errors the covariance is \sigma^2 (X^\top X)^{-1}; in general it's the sandwich:
- \text{Var}
- variance; for a vector, the covariance matrix (variances on the diagonal)
- \sigma^2
- the noise variance: how far prices scatter around the true line
- I
- the identity matrix: 1s on the diagonal, so equal variances and no correlation
- \Omega
- the general noise covariance: per-house variances may differ, errors may correlate
Derivation.
- A
- the fixed matrix that turns noise into estimation error (Tool 2's A)
- \hat w
- the fitted slope on size, with one feature
- S_{xx}
- \sum_i (x_i - \bar x)^2: how spread out the sizes are
- \text{SE}(\hat w)
- standard error: the estimated typical wobble of \hat w across samples
- s
- the estimated noise standard deviation, from the residuals
- \mathbf x_0
- a new house's feature vector
The last line gives the confidence interval for the mean at x_0. A new observation adds its own \sigma^2, which is the "1 +" in the prediction interval.
Key move. Tool 2 with A = (X^\top X)^{-1}X^\top. The bread is (X^\top X)^{-1}X^\top, the filling is \Omega — hence "sandwich".
Common slip. Simplifying to \sigma^2 (X^\top X)^{-1} without stating that it assumes equal variance and uncorrelated errors.
How it's asked. "Derive the variance of the OLS estimator." · "What changes under heteroscedasticity?" · "Why is a prediction interval wider than a confidence interval?"
Card 7 — Why divide by n − p
Statement. The expected residual sum of squares is (n - p)\sigma^2, so dividing by n - p gives an unbiased noise estimate:
- \text{RSS}
- residual sum of squares: the total squared miss, \mathbf e^\top\mathbf e
- n
- the number of houses
- p
- the number of fitted weights (counting the intercept)
- s^2
- the noise-variance estimate: RSS divided by n - p
Derivation.
- \mathbf e
- the residual vector: each house's actual minus fitted price
- H
- the hat matrix X(X^\top X)^{-1}X^\top: turns prices into fitted prices
- M
- the residual maker I - H: turns prices into residuals
- \text{tr}
- trace: the sum of a matrix's diagonal entries
- I_p
- the p \times p identity matrix
Key move. Residuals are a projection of the noise, e = M\varepsilon; then the trace trick (Tool 3). Rotating inside the trace turns \operatorname{tr}(H) into \operatorname{tr}(I_p).
Common slip. Saying \operatorname{tr}(H) = n. H is n \times n but has rank p.
How it's asked. "Why n - p degrees of freedom?" · "Prove s^2 is unbiased." · "Why does the sample variance divide by n - 1?" (Same proof with X = a column of 1s, p = 1.)
Card 8 — Gauss–Markov: OLS is BLUE
Statement. Under linearity, full rank, exogeneity and spherical errors, every linear unbiased estimator has at least the variance of OLS:
- \tilde{\mathbf w}
- any rival estimator that is linear in the prices (tilde = an alternative)
- C
- the fixed matrix defining that rival: how it weights each price
- \hat{\mathbf w}_{\text{OLS}}
- the ordinary least-squares weights
- \succeq 0
- is positive semi-definite: the rival's variance is never smaller, in any direction
Derivation.
- D
- how the rival differs from OLS: C minus the OLS matrix
Since DD^\top is positive semi-definite, \text{Var}(\tilde w) \ge \text{Var}(\hat w), with equality only when D = 0.
Key move. Write any competitor as "OLS + D". Unbiasedness forces DX = 0, which deletes the cross terms, leaving OLS's variance plus something non-negative.
Common slip. Forgetting where the conditions entered: \sigma^2 I is used in \text{Var}(Cy) = \sigma^2 CC^\top. Without it, OLS stops being best.
How it's asked. Research and quant roles: "Prove Gauss–Markov." Elsewhere: "Why is OLS called BLUE, and when does it stop being best?"
Bias, regularization, and prediction — Cards 9–13
Card 9 — Omitted-variable bias
Statement. If the truth includes z but you regress y on X alone, the estimate absorbs z's effect through its correlation with X:
- \mathbf y
- the column of all actual prices
- X
- the features you did include, one row per house
- \boldsymbol\beta
- the true weights on those features
- \mathbf z
- the omitted feature for every house (e.g. neighbourhood quality)
- \gamma
- the omitted feature's true effect on price
- \boldsymbol\varepsilon
- the noise vector: every house's error
- \mathbb E
- expected value: the average over many repeated samples
- \hat{\mathbf w}
- the weights fitted without \mathbf z (the short regression)
- \boldsymbol\delta
- slopes from regressing \mathbf z on X: how the omitted feature tracks the included ones
- ^\top
- transpose: rows become columns
- (X^\top X)^{-1}
- the inverse of X^\top X: the matrix that undoes it
Derivation.
- \mid X, \mathbf z
- given both included and omitted features: only the noise is redrawn
- \delta
- with one feature: the slope from regressing z on x
- \text{Cov}
- covariance: how two quantities move together
- \text{Var}
- variance: how spread out a quantity is
- x
- the included feature (size)
- z
- the omitted feature (neighbourhood quality)
Key move. Card 5's substitution, but with the long (true) model plugged into the short regression.
Common slip. Forgetting that bias needs both \gamma \ne 0 and \delta \ne 0, or getting the sign wrong. Sign of bias = \operatorname{sign}(\gamma) \times \operatorname{sign}(\delta).
How it's asked. "Derive omitted-variable bias." · Worked problem 2 in the Interview Bank (NBA height).
Card 10 — Attenuation from measurement error
Statement. If you observe x = x^* + u with independent noise u, the slope converges to \beta shrunk by the reliability ratio \lambda:
- y
- a house's price
- \beta
- the true slope of price on true size
- x^*
- the house's true size (never seen)
- \varepsilon
- the price noise
- x
- the size you actually record: true size plus measurement noise
- u
- the measurement noise in size, independent of everything else
- \text{plim}
- probability limit: where the estimate settles with endless data
- \hat w
- the slope fitted on recorded size
- \lambda
- the reliability ratio: the share of recorded size's variance that is real signal
Derivation.
- \frac{\text{Var}(y)}{\text{Cov}(x, y)}
- the reverse-regression slope flipped: regress size on price, then take 1 over it
Key move. "Cov over Var", then bilinearity (Tool 2): of the four cross-covariances, only \text{Cov}(x^*, x^*) survives in the numerator, while \text{Var}(u) stays in the denominator.
Common slip. Saying noise in y also biases the slope (it doesn't — it only appears in the numerator as \text{Cov}(\text{noise}, x) = 0).
How it's asked. Worked problem 1 in the Interview Bank (the reported Upstart question) · "Can you bound the true effect without knowing the noise variance?"
Card 11 — Ridge's closed form, and lasso's soft threshold
Statement. Ridge has a closed form that's always invertible for \lambda > 0 and is biased toward zero; with orthonormal features ridge divides and lasso soft-thresholds:
- \hat{\mathbf w}_R
- the ridge weights: least squares plus a penalty on squared weights
- \lambda
- the penalty strength you choose; bigger shrinks the weights harder
- I
- the identity matrix: 1s on the diagonal, 0s elsewhere
- ^{-1}
- matrix inverse: undoes the matrix
- \hat w_j^{R}
- the ridge weight on feature j
- \hat w_j
- the plain OLS weight on feature j
- \hat w_j^{L}
- the lasso weight on feature j
- \text{sign}
- +1 if positive, −1 if negative: keeps the weight's direction
- |\hat w_j|
- the size of the OLS weight, ignoring its sign
Derivation.
- L
- the ridge loss: squared misses plus \lambda times the squared weight length
- \lVert
- length of a vector (closed by \rVert); squared, it's the sum of squared entries
- \mathbf w
- the weight vector being chosen, one weight per feature
- \hat{\mathbf w}_{\text{OLS}}
- the plain least-squares weights, no penalty
- \sigma^2
- the noise variance: how far prices scatter around the true line
- w_j
- a candidate weight on feature j, being chosen
- \hat w_j^{\text{lasso}}
- the lasso weight on feature j: the winning candidate
Invertibility: X^\top X has eigenvalues \ge 0, so X^\top X + \lambda I has eigenvalues \ge \lambda > 0. In the SVD view, ridge shrinks each direction by a factor, and the weakly-determined directions (small singular values d_j, the collinear ones) shrink the most:
- U
- left singular vectors: orthonormal directions across houses, as columns
- D
- diagonal matrix of singular values d_j: how much X stretches each direction
- V
- right singular vectors: orthonormal directions across features
- \sum_j
- add up over every direction j
- \mathbf u_j
- the j-th column of U
- d_j
- the j-th singular value; small means a weakly determined (collinear) direction
Key move. Card 2 plus a 2\lambda w term. For lasso, split into cases w > 0 and w < 0; any \lvert \hat w \rvert \le \lambda/2 lands exactly on zero.
Common slip. Penalizing the intercept, or forgetting to standardize features first.
How it's asked. "Derive ridge. Why is it always invertible? Show it's biased." · "Why does lasso give exact zeros but ridge doesn't?"
Card 12 — Bias–variance decomposition of prediction error
Statement. For a new point y_0 = f(x_0) + \varepsilon_0 and a model \hat f trained on independent data:
- y_0
- the actual price of a new house
- \mathbf x_0
- that new house's features
- \hat f
- the model trained on one sample of houses (hat = learned from data)
- f
- the true price function: the average price for given features
Derivation.
- \varepsilon_0
- the new house's own noise, independent of the training data
For a correctly specified OLS model the bias is zero, and the variance averaged over the training points is:
- n
- the number of training houses
- \sum_i
- add up over every training house i
- \hat y_i
- the fitted price for training house i
- \text{tr}(H)
- trace of the hat matrix: its diagonal sum, which equals p
- p
- the number of fitted weights
So each extra feature costs \sigma^2/n of expected error — the precise reason more features can hurt.
Key move. Add and subtract twice (Tool 4): once with f, once with E[\hat f].
Common slip. Forgetting the irreducible \sigma^2, or confusing this with the estimator decomposition \text{MSE}(\hat\theta) = \text{bias}^2 + \text{variance} (that one has no noise term).
How it's asked. "Derive the bias–variance trade-off." · "Why can adding features make test error worse?"
Card 13 — Leave-one-out CV without refitting
Statement. Each leave-one-out residual comes from a single fit, so LOOCV needs no refitting:
- e_{(-i)}
- house i's leave-one-out residual: its miss when the line is fit without it
- e_i
- house i's ordinary residual from the full fit
- h_{ii}
- house i's leverage: the i-th diagonal entry of the hat matrix
- \text{LOOCV}
- leave-one-out cross-validation error: the average squared leave-one-out miss
- \sum_{i=1}^{n}
- add up over every house, i = 1 to n
Derivation. With A = X^\top X, removing row i is a rank-one update. Sherman–Morrison gives:
- A
- shorthand for X^\top X from the full data
- \mathbf x_i
- house i's feature vector (row i of X, stood up as a column)
- A^{-1}
- the inverse of A: the matrix that undoes it
- \hat{\mathbf w}_{(-i)}
- the weights refit with house i left out
- y_i
- house i's actual price
The same pieces give Cook's distance — a big residual times high leverage (both formulas checked numerically against a brute-force refit):
- D_i
- Cook's distance: how far all fitted prices move if house i is dropped
- s^2
- the noise-variance estimate, \text{RSS}/(n - p)
Key move. Sherman–Morrison for a rank-one change to X^\top X.
Common slip. Dropping the (1 - h_{ii}) — high-leverage points have LOO errors much larger than their in-sample residuals.
How it's asked. "How would you compute LOOCV for linear regression efficiently?" · "Why are high-leverage points' residuals misleadingly small?"
Research-level extensions — Cards 14–17
Card 14 — Fixed effects, and why they worsen attenuation
Statement. Demeaning within each unit removes a fixed trait a_i and gives an unbiased slope under strict exogeneity; with noisy x, the within estimator is attenuated more than pooled OLS:
- y_{it}
- house i's price at its sale in year t (each house sells several times)
- \beta
- the true slope: price change per unit of the feature
- x_{it}
- house i's feature at that sale (e.g. size after renovations)
- a_i
- house i's fixed trait: everything constant about it (location, view), unobserved
- \varepsilon_{it}
- the noise on that sale
- \mathbb E
- expected value: the average over many repeated samples
- \hat\beta_{\text{FE}}
- the fixed-effects (within) slope estimate
- x
- the feature (e.g. size), across all sales
- \lambda_{\text{within}}
- the reliability ratio after demeaning: the share of x's variance that is signal
- \lambda_{\text{pooled}}
- the same ratio for the raw, pooled data
Derivation.
- \ddot y_{it}
- the demeaned price: this sale's price minus house i's average (double dot = demeaned)
- \bar y_i
- house i's average price over its sales (bar = mean)
- \ddot x_{it}
- the demeaned feature: this sale's value minus house i's average
- \ddot\varepsilon_{it}
- the demeaned noise
- \bar a_i
- house i's average fixed trait, which is just a_i
- \sum_{i,t}
- add up over every house i and every sale t
- \tilde x
- the recorded feature, with measurement noise (tilde = observed with noise)
- x
- the feature's true value
- v
- measurement noise, independent across sales
- \text{plim}
- probability limit: where the estimate settles with endless data
- \text{Var}
- variance: how spread out a quantity is
- \ddot x
- the true feature after demeaning within each house
- \ddot v
- the noise after demeaning within each house
Demeaning removes all between-unit signal in x but only a 1/T share of the (independent) noise, so the within reliability ratio is lower than the pooled one.
Key move. Subtract each unit's mean — equivalent to adding a dummy per unit (Frisch–Waugh–Lovell).
Common slip. Forgetting that fixed effects need strict exogeneity: errors uncorrelated with x in every period. A lagged y violates it (Nickell bias, Drill 25).
How it's asked. "What does a fixed-effects model control for, and what can't it fix?" · Drill 13.
Card 15 — The training-vs-test gap (optimism)
Statement. For a correctly specified OLS model with p parameters, evaluated at the training x's:
- \text{train MSE}
- mean squared error on the houses the model was fit to
- \text{test MSE}
- mean squared error on fresh prices at those same houses
- \sigma^2
- the noise variance: how far prices scatter around the true line
- p
- the number of fitted weights
- n
- the number of training houses
Derivation.
- \text{RSS}
- residual sum of squares: the total squared training miss
- \lVert
- length of a vector (closed by \rVert); squared, it's the sum of squared entries
- \mathbf y_{\text{new}}
- fresh prices for the same houses, with new noise
- X
- the design matrix: one row per training house
- \hat{\mathbf w}
- the weights fitted on the training prices
- \boldsymbol\beta
- the true weights
- \text{tr}(H)
- trace of the hat matrix: its diagonal sum, which equals p
Key move. The trace trick twice (Tool 3): once on M = I - H for the training error, once on H for the prediction variance.
Common slip. Thinking the gap is p\sigma^2/n. It's 2p\sigma^2/n — training error sits p\sigma^2/n below \sigma^2 and test error p\sigma^2/n above it.
How it's asked. "Why does training error underestimate test error, and by how much?" · "Where do Mallows' Cp and AIC come from?"
Card 16 — The Moulton factor
Statement. With groups of size m, x constant within groups and within-group error correlation \rho, clustering inflates the slope's variance:
- \text{Var}(\hat w)
- the slope's actual variance when errors are correlated within groups
- \text{Var}_{\text{naive}}(\hat w)
- the variance the usual formula reports, assuming independent errors
- m
- the number of houses in each group (e.g. each neighbourhood)
- \rho
- the correlation between two houses' errors in the same group
- \rho_x
- how correlated the feature is within a group (1 if shared, like a school rating)
- \rho_\varepsilon
- the within-group error correlation (the \rho above)
Derivation. With centered x, \hat w - \beta = \sum_i x_i \varepsilon_i / \sum_i x_i^2. Group g contributes m identical x-values \tilde x_g:
- \text{Var}
- variance: how spread out a quantity is across repeated samples
- \sum_i
- add up over every house i
- x_i
- house i's centred feature value
- \varepsilon_i
- house i's error
- \sum_g
- add up over every group g
- \tilde x_g
- the feature value shared by every house in group g
Key move. Tool 2 with a block-diagonal error covariance: each group adds m variance terms and m(m - 1) covariance terms.
Common slip. Assuming clustering only matters when \rho is large. With m = 100 and \rho = 0.05, the variance is already about 6× the naive one.
How it's asked. "Why do we cluster standard errors?" · Drill 24.
Card 17 — Non-collapsibility: omitting an independent variable in probit and logit
Statement. In probit, omitting a variable z that is independent of x still shrinks x's coefficient; logit behaves almost the same way:
- y^*
- the hidden score: buyer keenness; the house sells above asking when it's positive
- \beta
- the true effect of x on that score
- x
- the included feature (e.g. size)
- \gamma
- the true effect of the omitted variable z on the score
- z
- a variable left out of the model, independent of x
- \varepsilon
- the noise in the score, standard normal in probit
- \perp
- is independent of
- \hat\beta_{\text{probit, omit } z}
- the probit slope fitted with z left out
- \sigma_z^2
- the variance of z
Derivation.
- y
- 1 if the house sells above asking, 0 if not
- \mathbf 1
- 1 if the condition in brackets is true, else 0
- \sim
- is distributed as
- N(0,1)
- the standard normal: mean 0, variance 1
- N
- a normal distribution, with (mean, variance) in the brackets
- P(y = 1 \mid x)
- the probability the house sells above asking, given x
- \Phi
- the standard normal CDF: turns a score into a probability
With \beta = \gamma = 1 and \text{Var}(z) = 4, that's 1/\sqrt{5} \approx 0.447 (simulation: 0.445). For logit, replace 1 with \pi^2/3 inside the square root; it's an approximation because the sum is no longer exactly logistic (Drill 26: about 0.67 predicted, 0.61 simulated).
Key move. Fold the omitted variable into the error, then rescale so the error has the variance the model insists on.
Common slip. Carrying over the OLS rule "an independent omitted variable causes no bias". In OLS the slope is unaffected; in probit and logit it shrinks.
How it's asked. "Adding an uncorrelated control changed my logistic coefficient. Why?" · "Can you compare odds ratios across models with different controls?"
Practice protocol
Reading a derivation feels like understanding it; reproducing it is what an interview tests. Practice like this:
- Blank page, out loud. Write the statement, then derive while explaining each line as if to an interviewer.
- Stuck? Peek at the key move only, never the full derivation. Then try again.
- Log every slip next to the card's Common slip. Your own slips are the ones you'll repeat under pressure.
- Review the day after, 3 days later, a week later, and 3 weeks later. A card you miss goes back to day 1.
| Level it's asked at | Cards | Target from a blank page |
|---|---|---|
| Onsite core | 1, 2, 3, 4 | Under 3 minutes each |
| Senior | 5, 6, 7, 9, 12 | Under 4 minutes each |
| Research / quant | 8, 10, 11, 13, 14–17 | Under 5 minutes each |
Mastery tracker — tick a card when you've done it from memory, under the target time, twice on different days:
- [ ] Card 1 — OLS by hand
- [ ] Card 2 — Normal equation
- [ ] Card 3 — Least squares = MLE
- [ ] Card 4 — \text{TSS} = \text{ESS} + \text{RSS}, R^2 = r^2
- [ ] Card 5 — OLS is unbiased
- [ ] Card 6 — Variance and the sandwich
- [ ] Card 7 — Why n - p
- [ ] Card 8 — Gauss–Markov
- [ ] Card 9 — Omitted-variable bias
- [ ] Card 10 — Attenuation
- [ ] Card 11 — Ridge and lasso
- [ ] Card 12 — Bias–variance of prediction error
- [ ] Card 13 — LOOCV shortcut
- [ ] Card 14 — Fixed effects and attenuation
- [ ] Card 15 — Training-vs-test gap
- [ ] Card 16 — Moulton factor
- [ ] Card 17 — Non-collapsibility (probit and logit)