Estimate · Chapter 3 of 12
Least squares and projection
Objective: Derive least squares, interpret residualization, and distinguish a projection coefficient from a causal effect.
What changes when experience enters the training regression?
OLS · Projection · FWL · Omitted variables
Before you begin: Averages, basic algebra, and expectation and conditional expectation (chapters 1 and 2). Optional derivations use derivatives and matrices.
About 30 minutes, plus the exercises.
Least squares
Least squares minimizes the sum of squared residuals. Interpreting the fitted coefficients requires assumptions about how the data were generated.
The six-person example below can be followed with averages and arithmetic. The derivative and matrix steps explain why its calculation generalizes; readers new to those tools can return to them after working through the numbers.
For observations , a regression with an intercept chooses to minimize
Differentiate with respect to and . At the optimum,
The first equation gives . Substituting it into the second gives
provided training varies in the sample. These residual properties follow from the optimization. They cannot serve as evidence that the error in a causal model is unrelated to training. The exogeneity panel of the OLS assumptions lab simulates the slope when the error is correlated with the regressor.
A six-person example
All numbers below are synthetic. Here is training hours, indicates prior experience, and is output in arbitrary units.
| Employee | Training | Experience | Output |
|---|---|---|---|
| A | 0 | 0 | 1 |
| B | 1 | 0 | 0 |
| C | 2 | 0 | 5 |
| D | 2 | 1 | 8 |
| E | 3 | 1 | 7 |
| F | 4 | 1 | 12 |
The overall means are and . The centered cross-product is 29 and the centered training sum of squares is 10. Regressing output on training alone produces a slope of .
Now remove each experience group’s mean from both variables. The group training means are 1 and 3; output means are 2 and 9. The residualized observations are
Their cross-product is 8 and the training sum of squares is 4. The adjusted slope is .
This is the training coefficient from regressing output jointly on an intercept, training, and experience. Residualizing makes the comparison visible: within each experience group, how do deviations in training line up with deviations in output?
The general projection
Put the outcome in an -vector and the regressors, including any intercept, in an matrix . If has full column rank,
The fitted vector lies in the space spanned by the columns of . The residual is perpendicular to that space. Adding a regressor enlarges the available space, so in-sample squared error cannot increase. This says nothing by itself about prediction on new data.
In a population, let be a random -vector. With finite second moments and nonsingular , the best linear predictor minimizes and satisfies
The conditional mean may still be nonlinear. Orthogonality to the chosen regressors is weaker than .
The OLS assumptions lab simulates each classical assumption separately. Its correct-specification panel fits a straight line to a curved conditional mean, and its collinearity panel shows what happens to the coefficients as the full-rank condition above nearly fails.
The residualization theorem
Partition the design into a variable of interest and controls , including an intercept if needed. Define
Assume has full rank and . For a proposed coefficient on , fitting the controls leaves residual . Minimizing its squared length gives
Since is symmetric and idempotent, this is the regression of residualized on residualized . This algebraic result is the Frisch–Waugh–Lovell theorem. It requires no causal assumptions.
Where an omitted variable enters
Suppose a substantive model is
Then the population slope from omitting is
The extra term requires both an output relationship and a training relationship for . In the six-person construction, with . The residual vector has zero sample covariance with and . The short slope is therefore exactly .
Knowing the construction lets us interpret the coefficient. With actual company records, that construction is unknown. Experience may be insufficient to address self-selection. A variable measured after training may be a mediator, which carries part of training’s effect to output, or a collider, which is caused both by training and by something else that affects output. Chapter 6 shows how adjusting for either changes the comparison. More controls do not automatically produce a better causal argument.
Reproduce the adjustment
# Standard Python.
d = [0, 1, 2, 2, 3, 4]
k = [0, 0, 0, 1, 1, 1]
y = [1, 0, 5, 8, 7, 12]
def demean_by_group(values):
means = {
g: sum(v for v, h in zip(values, k) if h == g)
/ k.count(g)
for g in set(k)
}
return [v-means[g] for v, g in zip(values, k)]
rd, ry = demean_by_group(d), demean_by_group(y)
print(sum(a*b for a, b in zip(rd, ry))
/ sum(a*a for a in rd)) # 2.0
Exercises
1. Does a regression fitted without an intercept necessarily have residuals that sum to zero?
Work through the solution
No. Residuals are orthogonal to the included columns. Without a constant column, orthogonality to the vector of ones is not generally imposed. For example, fitting to and gives and residuals , which sum to 0.2.
2. Let be uniform on and . What does the population linear projection with an intercept predict? Is its residual conditionally mean zero?
Work through the solution
Symmetry gives , so the slope is zero. The intercept is . The residual is , with . But , generally nonzero. The projection is the best available straight line, although the conditional mean is a curve.
Further reading
Bruce Hansen’s Econometrics develops population projection, least squares, and their sampling theory. Angrist and Pischke’s Mostly Harmless Econometrics resources provide a route from regression arguments to inspectable empirical applications.
Write the claim and the assumption doing the most work. Saved only in this browser on this device; avoid sensitive information. Private browsing or clearing site data can erase it.
Notes are optional.
“Explored” records your choice, not a score or a claim of mastery.