Week 10: Regression, part 2

PS 812 - Introduction to Statistical Methods in Political Science

Anton Strezhnev

University of Wisconsin-Madison

November 10, 2026

Welcome back!

\[ \newcommand{\Var}{\text{Var}} \newcommand{\Cov}{\text{Cov}} \newcommand{\Corr}{\text{Corr}} \newcommand{\indep}{\mathrel{\perp\mkern-10mu\perp}} \]

Ordinary Least Squares

OLS for estimating the CEF

  • We’ll show that under i.i.d. sampling, OLS is consistent for the Best Linear Predictor

    • The linear combination of \(X_i\) that minimizes the mean squared prediction error.
  • But we want to estimate the CEF \(\mathbb{E}[Y_i \mid \mathbf{X}_i]\)

    • When is OLS consistent for the conditional expectation function?
  • When the CEF is the BLP!

    \[\mathbb{E}[Y_i \mid \mathbf{X}_i] = \mathbf{X}_i^\prime\boldsymbol{\beta}\]

  • When is the CEF linear?

    • Saturated models: every covariate is discrete and there is a dummy for every combination of values (e.g. the three party categories)
    • Otherwise, linearity is an assumption about the functional form
    • Remember, this is linearity in parameters given a particular \(\mathbf{X}\)
      • Adding more terms to \(\mathbf{X}\) may make linearity more plausible!

Interpreting multiple regression coefficients

  • With a bivariate regression, interpreting the coefficient on \(X_i\) is straightforward

    \[\hat{\beta}_1 = \frac{\widehat{\Cov}(X_i, Y_i)}{\widehat{\Var}(X_i)}\]

  • The difference in the expectation of \(Y_i\) between respondents whose \(X_i\) differs by one unit

    \[ \begin{aligned} \mathbb{E}[Y_i \mid X_i = x + 1] - \mathbb{E}[Y_i \mid X_i = x] &= \big(\beta_0 + \beta_1 (x + 1)\big) - \big(\beta_0 + \beta_1 x\big) \\ &= \beta_1 \end{aligned} \]

Interpreting multiple regression coefficients

  • However, with a multivariate regression, the coefficient captures a different relationship.

  • The difference in the expected \(Y_i\) between respondents whose \(X_{i1}\) differs by one unit…

    • …holding the other covariates fixed.

    \[ \begin{aligned} &\mathbb{E}[Y_i \mid X_{i1} = x_1 + 1, X_{i2} = x_2, \dotsc, X_{i,k-1} = x_{k-1}] - \mathbb{E}[Y_i \mid X_{i1} = x_1, X_{i2} = x_2, \dotsc, X_{i,k-1} = x_{k-1}] \\ &\qquad = \big(\beta_0 + \beta_1 (x_1 + 1) + \beta_2 x_2 + \dotsc + \beta_{k-1} x_{k-1}\big) - \big(\beta_0 + \beta_1 x_1 + \beta_2 x_2 + \dotsc + \beta_{k-1} x_{k-1}\big) \\ &\qquad = \beta_1 \end{aligned} \]

    • We’ll often talk about interpreting \(\beta_1\) in terms of the relationships between \(X\) and \(Y\) after controlling for or conditioning on the other covariates
  • What is OLS actually doing?

    • We’re not physically controlling anything!
    • The Frisch-Waugh-Lovell theorem gives us a way of thinking about multivariate regression coefficients in terms of a residuals-on-residuals regression.

Frisch-Waugh-Lovell Theorem

  • Split the regressors into the one we care about, \(X_{i1}\), and everything else, \(\mathbf{X}_{i,-1}\) (which includes the intercept)

    \[Y_i = \hat{\beta}_1 X_{i1} + \mathbf{X}_{i,-1}^\prime\hat{\boldsymbol{\beta}}_{-1} + \hat{e}_i\]

  • Frisch-Waugh-Lovell (FWL): we can get the same \(\hat{\beta}_1\) from three regressions

    1. Regress \(Y_i\) on \(\mathbf{X}_{i,-1}\) and keep the residuals, \(\tilde{Y}_i\)
    2. Regress \(X_{i1}\) on \(\mathbf{X}_{i,-1}\) and keep the residuals, \(\tilde{X}_{i1}\)
    3. Regress \(\tilde{Y}_i\) on \(\tilde{X}_{i1}\).
  • The slope is exactly \(\hat{\beta}_1\)

    \[\hat{\beta}_1 = \frac{\widehat{\Cov}(\tilde{X}_{i1}, \tilde{Y}_i)}{\widehat{\Var}(\tilde{X}_{i1})}\]

What FWL tells us

  • \(\hat{\beta}_1\) only uses the variation in \(X_{i1}\) that is not linearly predicted by the other covariates to explain \(Y_i\)

  • “Controlling for” \(\mathbf{X}_{i,-1}\) means partialling out its linear relationship with both \(X_{i1}\) and \(Y_i\)

    • If \(X_{i1}\) is uncorrelated with the other covariates in the sample, then adding those covariates doesn’t change \(\hat{\beta}_1\)
  • Remember that the “partialling out” is linear

    • If \(\mathbf{X}_{i,-1}\) is related to \(X_{i1}\) or \(Y_i\) in a way that the linear regression does not capture, that relationship is still in the residuals and might be attributed to \(X_{i1}\).

Visualizing FWL

Example: controlling for party

  • In our example, \(\mathbf{X}_{i,-1}\) is the intercept plus the Independent and Republican dummies

    • A regression on a full set of indicators predicts each category’s mean
  • So partialling out party just subtracts each respondent’s party mean

    \[\tilde{X}_{i1} = X_{i1} - \bar{X}_{\text{party}(i)} \qquad \tilde{Y}_i = Y_i - \bar{Y}_{\text{party}(i)}\]

  • \(\hat{\beta}_1\) is the slope using only the within-party variation

    • Differences in hostile sexism between the parties contribute nothing to \(\hat{\beta}_1\)

FWL in R

anes_p <- anes |> filter(!is.na(party))   # the same respondents in every regression

# The full regression
round(coef(lm(ft_trump ~ hostile_sexism + party, data = anes_p)), 2)
     (Intercept)   hostile_sexism partyIndependent  partyRepublican 
            0.06            32.67            22.03            58.82 
# Steps 1 and 2: partial party out of the outcome and out of hostile sexism
anes_p$y_tilde <- resid(lm(ft_trump ~ party, data = anes_p))
anes_p$x_tilde <- resid(lm(hostile_sexism ~ party, data = anes_p))

# Step 3: residuals on residuals
round(coef(lm(y_tilde ~ x_tilde, data = anes_p)), 2)
(Intercept)     x_tilde 
       0.00       32.67 

Interacting with partisanship

  • To let the slope on hostile sexism differ between parties too we add interactions

    • The products of \(X_i\) with each dummy

    \[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_i + \hat{\beta}_2 X_i^{\text{Ind}} + \hat{\beta}_3 X_i^{\text{Rep}} + \hat{\beta}_4 X_i X_i^{\text{Ind}} + \hat{\beta}_5 X_i X_i^{\text{Rep}}\]

  • Within each party, the fit is still a line in \(X_i\), but now each has its own intercept and slope

    \[\begin{aligned} \text{Democrats:} \quad & \hat{\beta}_0 + \hat{\beta}_1 X_i \\ \text{Independents:} \quad & (\hat{\beta}_0 + \hat{\beta}_2) + (\hat{\beta}_1 + \hat{\beta}_4) X_i \\ \text{Republicans:} \quad & (\hat{\beta}_0 + \hat{\beta}_3) + (\hat{\beta}_1 + \hat{\beta}_5) X_i \end{aligned}\]

  • \(\hat{\beta}_1\) is now the slope among Democrats (the baseline), and \(\hat{\beta}_4\), \(\hat{\beta}_5\) are differences in slopes relative to Democrats

  • With every interaction in, this is the same as fitting a separate OLS line within each party

Interacting with partisanship

# x * z in a formula adds x, z, and their product x:z
round(coef(lm(ft_trump ~ hostile_sexism * party, data = anes)), 2)
                    (Intercept)                  hostile_sexism                partyIndependent 
                           0.95                           29.06                           20.93 
                partyRepublican hostile_sexism:partyIndependent  hostile_sexism:partyRepublican 
                          56.08                            4.12                            7.76 
  • Slopes actually aren’t that different!

Interacting with education

  • Does the slope on hostile sexism differ by education?

    • Let \(X_i^{\text{Col}} = I(\text{college degree}_i)\) and add its product with \(X_i\)

    \[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_i + \hat{\beta}_2 X_i^{\text{Col}} + \hat{\beta}_3 X_i X_i^{\text{Col}}\]

  • Within each education group, the fit is a line in \(X_i\) with its own intercept and slope

    \[\begin{aligned} \text{No college degree:} \quad & \hat{\beta}_0 + \hat{\beta}_1 X_i \\ \text{College degree:} \quad & (\hat{\beta}_0 + \hat{\beta}_2) + (\hat{\beta}_1 + \hat{\beta}_3) X_i \end{aligned}\]

  • \(\hat{\beta}_1\) is the slope among respondents without a degree (the baseline), and \(\hat{\beta}_3\) is the difference in slopes for college graduates

Interacting with education

round(coef(lm(ft_trump ~ hostile_sexism * college, data = anes)), 2)
           (Intercept)         hostile_sexism                college hostile_sexism:college 
                 15.42                  79.18                 -14.47                  20.43 

A second continuous covariate

  • Racial resentment: a three question measure from Kinder and Sanders (1996), also averaged and re-scaled to \([0, 1]\)

    • Correlated with hostile sexism: \(r = 0.50\)
  • With two continuous covariates, the fit is a plane over \((X_{i1}, X_{i2})\)

    \[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_{i1} + \hat{\beta}_2 X_{i2}\]

round(coef(lm(ft_trump ~ hostile_sexism + racial_resentment, data = anes)), 2)
      (Intercept)    hostile_sexism racial_resentment 
            -9.29             50.18             60.49 
  • After partialling racial resentment out of both the outcome and hostile sexism, the slope on hostile sexism is 50.2, also down from the unconditional 94.0

In three dimensions

Interacting two continuous covariates

  • A linear interaction with two continuous covariates adds the product of hostile sexism and racial resentment to the equation.

    \[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_{i1} + \hat{\beta}_2 X_{i2} + \hat{\beta}_3 X_{i1} X_{i2}\]

  • Holding \(X_{i2}\) at a value \(x_2\), we’re still estimating a line for \(X_{i1}\), but its slope now depends on \(x_2\)

    \[\big[\hat{\beta}_0 + \hat{\beta}_1 (x_1 + 1) + \hat{\beta}_2 x_2 + \hat{\beta}_3 (x_1 + 1) x_2\big] - \big[\hat{\beta}_0 + \hat{\beta}_1 x_1 + \hat{\beta}_2 x_2 + \hat{\beta}_3 x_1 x_2\big] = \hat{\beta}_1 + \hat{\beta}_3 x_2\]

    • The marginal ‘effect’ of \(X_{i1}\) at \(X_{i2} = x_2\). (be careful though, this is just a slope - we’re not yet making a causal claim).
    • \(\hat{\beta}_1\) alone is the slope at \(X_{i2} = 0\) - sometimes this is meaningful, sometimes it isn’t!
round(coef(lm(ft_trump ~ hostile_sexism * racial_resentment, data = anes)), 2)
                     (Intercept)                   hostile_sexism                racial_resentment 
                           -7.00                            41.42                            54.87 
hostile_sexism:racial_resentment 
                           17.33 

The interaction surface

Marginal effects plot

  • The slope on hostile sexism rises from 41.4 at the lowest racial resentment to 58.8 at the highest, a straight line with slope \(\hat{\beta}_3 = 17.3\)
    • The band is a 95% confidence interval (using robust HC0 SEs)
  • The gray bars show where the data are. Always plot the marginal effect against the distribution of the moderator

Careful with linear interactions!

  • \(\hat{\beta}_1 + \hat{\beta}_3 x_2\) assumes the slope on \(X_{i1}\) changes at a constant rate in \(X_{i2}\)
    • Where few respondents have a given \(X_{i2}\) (weak common support), the predicted marginal effect relies heavily on the functional form assumption!
  • Hainmueller et al. (2019) recommend a check that just uses bins of the effect modifier
    • Estimate separate slopes and intercepts within each bin
    • Think of what we did before: comparing the noisy binning approach with the efficient but potentially biased regression

Binned marginal effects

  • The bins differ from the linear interaction results!
    • The slope is steepest in the middle tercile (64.9) and flattest in the top one (39.8), where the linear interaction puts its largest slope (57.3)
    • The linear interaction forced a monotone pattern onto a hump
  • Likely because the thermometer is bounded:
    • Little room to move at either end, so the marginal “effects” get compressed at the tails.

Consistency of OLS

  • We’ve made a few regularity assumptions to ensure the BLP exists

  • What do we need to make OLS consistent for the BLP?

    • Just i.i.d. sampling from the target population
  • Write \(Y_i\) in terms of the projection error, \(Y_i = \mathbf{X}_i^\prime\boldsymbol{\beta} + e_i\), and substitute it into \(\hat{\boldsymbol{\beta}}\)

    \[ \begin{aligned} \hat{\boldsymbol{\beta}} &= \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\big(\mathbf{X}_i^\prime\boldsymbol{\beta} + e_i\big)\right) \\ &= \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)\boldsymbol{\beta} + \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i\right) \\ &= \boldsymbol{\beta} + \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i\right) \end{aligned} \]

Consistency of OLS

  • By the law of large numbers, each sample mean converges to its population mean

    \[\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime \xrightarrow{p} \mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime] \qquad \frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i \xrightarrow{p} \mathbb{E}[\mathbf{X}_i e_i] = \mathbf{0}\]

    • Last week we showed that the prediction errors are orthogonal to \(X_i\) for the BLP mechanically
  • The inverse is a continuous function, so by the continuous mapping theorem

    \[\hat{\boldsymbol{\beta}} \xrightarrow{p} \boldsymbol{\beta} + \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\,\mathbf{0} = \boldsymbol{\beta}\]

  • Really, we just need an LLN to apply to our sample plug-ins

    • So relaxations of i.i.d that still let us invoke LLN/CLT are fine
    • (e.g. clustered sampling, spatial correlation that dissipates over sufficient distances, etc…)

Asymptotic normality of OLS

  • For the sample mean, the CLT gave us \(\sqrt{n}(\hat{\mu} - \mu) \xrightarrow{d} \mathcal{N}(0, \sigma^2)\). The same idea applies to \(\hat{\boldsymbol{\beta}}\)

  • Multiply the decomposition by \(\sqrt{n}\)

    \[\sqrt{n}\big(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta}\big) = \underbrace{\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}}_{\xrightarrow{p}\ \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}} \ \underbrace{\sqrt{n}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i - \mathbf{0}\right)}_{\xrightarrow{d}\ \mathcal{N}(\mathbf{0},\ \boldsymbol{\Omega})}\]

  • A multivariate CLT applies to the sample mean of the i.i.d. \(\mathbf{X}_ie_i\) random vectors and

    \[\boldsymbol{\Omega} = \Var(\mathbf{X}_i e_i) = \mathbb{E}[e_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime]\]

  • By Slutsky’s theorem

\(\sqrt{n}\big(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta}\big) \xrightarrow{d} \mathcal{N}\Big(\mathbf{0},\ \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\,\boldsymbol{\Omega}\,\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\Big)\)

The asymptotic variance

  • Now let’s obtain \(\Var(\hat{\boldsymbol{\beta}})\) - the variance-covariance matrix of the sampling distribution of \(\hat{\boldsymbol{\beta}}\)

    • For a \(k \times k\) non-random matrix \(\mathbf{A}\) and a random vector \(\mathbf{Z}\), \(\Var(\mathbf{A}\mathbf{Z}) = \mathbf{A}\,\Var(\mathbf{Z})\,\mathbf{A}^\prime\)
      • This is the “matrix” equivalent of “squaring” a constant: \(\Var(aZ) = a^2\Var(Z)\)
  • Applying this to \(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta} = \frac{1}{\sqrt{n}} \cdot \sqrt{n}\big(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta}\big)\)

    \[\Var(\hat{\boldsymbol{\beta}}) = \frac{1}{n}\Var\Bigg(\underbrace{\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}}_{\mathbf{A}\ \xrightarrow{p}\ \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}} \ \underbrace{\sqrt{n}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i - \mathbf{0}\right)}_{\mathbf{Z}\ \xrightarrow{d}\ \mathcal{N}(\mathbf{0},\ \boldsymbol{\Omega})}\Bigg)\]

  • The result is a sandwich: two slices of bread around the filling

    \[\underbrace{\Var(\hat{\boldsymbol{\beta}})}_{k \times k} \approx \frac{1}{n} \underbrace{\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}}_{k \times k} \ \underbrace{\boldsymbol{\Omega}}_{k \times k} \ \underbrace{\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}}_{k \times k}\]

The variance-covariance matrix

  • Written out, the variance-covariance matrix of \(\hat{\boldsymbol{\beta}}\) is

    \[\Var(\hat{\boldsymbol{\beta}}) = \begin{pmatrix} \Var(\hat{\beta}_0) & \Cov(\hat{\beta}_0, \hat{\beta}_1) & \cdots & \Cov(\hat{\beta}_0, \hat{\beta}_{k-1}) \\ \Cov(\hat{\beta}_1, \hat{\beta}_0) & \Var(\hat{\beta}_1) & \cdots & \Cov(\hat{\beta}_1, \hat{\beta}_{k-1}) \\ \vdots & \vdots & \ddots & \vdots \\ \Cov(\hat{\beta}_{k-1}, \hat{\beta}_0) & \Cov(\hat{\beta}_{k-1}, \hat{\beta}_1) & \cdots & \Var(\hat{\beta}_{k-1}) \end{pmatrix}\]

    • The standard error of \(\hat{\beta}_j\) is the square root of the corresponding diagonal entry

The filling

  • \(\mathbb{E}[\mathbf{X}_i e_i] = \mathbf{0}\), so \(\boldsymbol{\Omega}\) is the expectation of an outer product

    \[\boldsymbol{\Omega} = \Var(\mathbf{X}_i e_i) = \mathbb{E}\big[(\mathbf{X}_i e_i)(\mathbf{X}_i e_i)^\prime\big] - \underbrace{\mathbb{E}[\mathbf{X}_i e_i]\,\mathbb{E}[\mathbf{X}_i e_i]^\prime}_{\mathbf{0}} = \mathbb{E}[e_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime]\]

  • Each respondent contributes \(\mathbf{X}_i\mathbf{X}_i^\prime\) weighted by their squared error

    \[\small \underbrace{\mathbf{X}_i e_i}_{k \times 1} \quad \underbrace{(\mathbf{X}_i e_i)^\prime}_{1 \times k} = e_i^2 \begin{pmatrix} 1 \\ X_{i1} \\ \vdots \\ X_{i,k-1} \end{pmatrix} \begin{pmatrix} 1 & X_{i1} & \cdots & X_{i,k-1} \end{pmatrix} = \begin{pmatrix} e_i^2 & e_i^2 X_{i1} & \cdots & e_i^2 X_{i,k-1} \\ e_i^2 X_{i1} & e_i^2 X_{i1}^2 & \cdots & e_i^2 X_{i1} X_{i,k-1} \\ \vdots & \vdots & \ddots & \vdots \\ e_i^2 X_{i,k-1} & e_i^2 X_{i,k-1} X_{i1} & \cdots & e_i^2 X_{i,k-1}^2 \end{pmatrix}\]

Estimating the variance

  • Plug-in principle again: replace each expectation with a sample mean and each unobserved \(e_i\) with its residual \(\hat{e}_i = Y_i - \mathbf{X}_i^\prime\hat{\boldsymbol{\beta}}\)

    \[\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime = \frac{1}{n}\mathbf{X}^\prime\mathbf{X} \qquad \widehat{\boldsymbol{\Omega}} = \frac{1}{n}\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime\]

  • Plug these into the sandwich (the \(n\)’s cancel)

    \[\begin{aligned} \widehat{\Var}(\hat{\boldsymbol{\beta}}) &= \frac{1}{n}\left(\frac{1}{n}\mathbf{X}^\prime\mathbf{X}\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime\right)\left(\frac{1}{n}\mathbf{X}^\prime\mathbf{X}\right)^{-1} \\ &= (\mathbf{X}^\prime\mathbf{X})^{-1}\left(\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime\right)(\mathbf{X}^\prime\mathbf{X})^{-1} \end{aligned}\]

  • This is the heteroskedasticity-consistent (HC0) or Eicker-Huber-White estimator - usually called robust standard errors

Estimating the variance

  • You’ll often see the filling written as an equivalent matrix product involving a \(n \times n\) matrix \(\widehat{\mathbf{D}}\)

    \[\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime = \underbrace{\mathbf{X}^\prime}_{k \times n} \ \underbrace{\widehat{\mathbf{D}}}_{n \times n} \ \underbrace{\mathbf{X}}_{n \times k} = \begin{pmatrix} \mathbf{X}_1 & \mathbf{X}_2 & \cdots & \mathbf{X}_n \end{pmatrix} \begin{pmatrix} \hat{e}_1^2 & 0 & \cdots & 0 \\ 0 & \hat{e}_2^2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \hat{e}_n^2 \end{pmatrix} \begin{pmatrix} \mathbf{X}_1^\prime \\ \mathbf{X}_2^\prime \\ \vdots \\ \mathbf{X}_n^\prime \end{pmatrix}\]

  • Later on, we’ll connect this to the variance-covariance matrix of the errors in the classical regression setting

    • Off-diagonals are \(0\): under i.i.d. sampling, \(e_i\) and \(e_j\) are independent
    • Diagonals \(\sigma_i^2 = \mathbb{E}[e_i^2 \mid \mathbf{X}_i]\) can differ across respondents with different \(\mathbf{X}_i\)
    • The HC0 estimator plugs in \(\hat{e}_i^2\) for each \(\sigma_i^2\)

HC0 by hand

  • The HC0 variance estimator is a \(k \times k\) sandwich

    \[\underbrace{\widehat{\Var}(\hat{\boldsymbol{\beta}})}_{k \times k} = \underbrace{(\mathbf{X}^\prime\mathbf{X})^{-1}}_{k \times k} \ \underbrace{\mathbf{X}^\prime\widehat{\mathbf{D}}\mathbf{X}}_{k \times k} \ \underbrace{(\mathbf{X}^\prime\mathbf{X})^{-1}}_{k \times k}\]

  • Let’s take a look at this with a complete regression with both attitude measures and the party dummies

fit_full <- lm(ft_trump ~ hostile_sexism + racial_resentment + party, data = anes)

X <- model.matrix(fit_full)           # n x k: intercept, two attitudes, two party dummies
dim(X)
[1] 4562    5
e_hat <- resid(fit_full)

bread <- solve(t(X) %*% X)            # (X'X)^{-1}, k x k
D <- diag(e_hat^2)                    # n x n, squared residuals on the diagonal
filling <- t(X) %*% D %*% X           # X'DX, k x k
V_hc0 <- bread %*% filling %*% bread  # k x k

round(sqrt(diag(V_hc0)), 3)           # standard errors: the square roots of the diagonal
      (Intercept)    hostile_sexism racial_resentment  partyIndependent   partyRepublican 
            0.559             2.026             1.573             1.841             1.042 

HC0 with sandwich

  • The sandwich package computes these for any lm() fit
library(sandwich)
V_sw <- vcovHC(fit_full, type = "HC0")
round(sqrt(diag(V_sw)), 3)
      (Intercept)    hostile_sexism racial_resentment  partyIndependent   partyRepublican 
            0.559             2.026             1.573             1.841             1.042 
  • Careful: the default in vcovHC is type = "HC3" which is a small-sample correction
    • “Robust” standard errors are consistent but not unbiased - in small samples they tend to be too small.
    • Many corrections proposed in the literature.
    • HC1 rescales HC0 by \(n/(n - k)\) (Stata’s , robust)
    • HC2 and HC3 rescale each \(\hat{e}_i^2\) by how much observation \(i\) pulls on its own fit

Confidence intervals and tests

  • Asymptotic normality lets us use the same approach to testing as before

    \[\frac{\hat{\beta}_j - \beta_j}{\widehat{SE}(\hat{\beta}_j)} \xrightarrow{d} \mathcal{N}(0, 1) \qquad \widehat{SE}(\hat{\beta}_j) = \sqrt{\big[\widehat{\Var}(\hat{\boldsymbol{\beta}})\big]_{jj}}\]

  • 95% confidence interval: \(\hat{\beta}_j \pm 1.96 \times \widehat{SE}(\hat{\beta}_j)\)

  • Test of \(H_0: \beta_j = 0\): \(t = \hat{\beta}_j / \widehat{SE}(\hat{\beta}_j)\), with two-sided p-value \(2\big(1 - \Phi(|t|)\big)\)

b <- coef(fit_full)
se_hc0 <- sqrt(diag(V_sw))
t_hc0 <- b / se_hc0
cbind(round(cbind(estimate = b, se = se_hc0,
                  lower = b - qnorm(0.975) * se_hc0, upper = b + qnorm(0.975) * se_hc0,
                  t = t_hc0), 3),
      p = signif(2 * pnorm(-abs(t_hc0)), 3))
                  estimate    se  lower  upper      t        p
(Intercept)         -4.325 0.559 -5.422 -3.229 -7.734 1.04e-14
hostile_sexism      24.153 2.026 20.183 28.123 11.924 8.85e-33
racial_resentment   19.623 1.573 16.541 22.706 12.476 1.01e-35
partyIndependent    19.423 1.841 15.815 23.032 10.550 5.10e-26
partyRepublican     53.285 1.042 51.242 55.328 51.125 0.00e+00

The sampling distribution of a line

Standard errors for a bivariate regression

  • With one regressor, the OLS slope is

    \[\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2} = \frac{\sum_{i=1}^n (X_i - \bar{X})\,Y_i}{\sum_{i=1}^n (X_i - \bar{X})^2}\]

  • Substitute \(Y_i = \beta_0 + \beta_1 X_i + e_i\). Because \(\sum_i (X_i - \bar{X}) = 0\) and \(\sum_i (X_i - \bar{X})X_i = \sum_i (X_i - \bar{X})^2\)

    \[\hat{\beta}_1 = \beta_1 + \frac{\sum_{i=1}^n (X_i - \bar{X})\,e_i}{\sum_{i=1}^n (X_i - \bar{X})^2}\]

Standard errors for a bivariate regression

  • Divide the top and the bottom by \(n\)

    \[\hat{\beta}_1 - \beta_1 = \frac{\overbrace{\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})\,e_i}^{\approx\ \frac{1}{n}\sum_{i=1}^n (X_i - \mu_X)\,e_i}}{\underbrace{\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})^2}_{\xrightarrow{p}\ \Var(X_i)}}\]

  • Since \(\bar{X} \xrightarrow{p} \mu_X\), the numerator behaves like a sample mean of the i.i.d. \((X_i - \mu_X)e_i\), which have mean \(0\) and variance \(\mathbb{E}[(X_i - \mu_X)^2 e_i^2]\)

  • The variance of a sample mean of \(n\) i.i.d. terms is \(\frac{1}{n}\) times the variance of one term

    • …and the denominator is (approximately) the constant \(\Var(X_i)\), so it comes out squared
  • And we get the sandwich estimator in scalar form:

    \[\Var(\hat{\beta}_1) \approx \frac{1}{n}\,\frac{\overbrace{\mathbb{E}\big[(X_i - \mu_X)^2 e_i^2\big]}^{\text{filling}}}{\underbrace{\Var(X_i)^2}_{\text{bread}}}\]

Standard errors for a bivariate regression

  • Plug-in: replace the expectations with sample means and \(e_i\) with \(\hat{e}_i\) (the \(n\)’s cancel)

    \[\begin{aligned} \widehat{\Var}(\hat{\beta}_1) &= \frac{1}{n}\,\frac{\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})^2\,\hat{e}_i^2}{\Big(\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})^2\Big)^2} \\ &= \frac{\sum_{i=1}^n (X_i - \bar{X})^2\,\hat{e}_i^2}{\Big(\sum_{i=1}^n (X_i - \bar{X})^2\Big)^2} \end{aligned}\]

    and \(\widehat{SE}(\hat{\beta}_1) = \sqrt{\widehat{\Var}(\hat{\beta}_1)}\)

  • Our standard error for the slope is smaller when we have…

    • …a larger \(n\)
    • …more spread in \(X_i\)
    • …smaller errors, especially far from \(\bar{X}\) since each \(\hat{e}_i^2\) is weighted by \((X_i - \bar{X})^2\)

Uncertainty about \(\hat{Y}\)

  • Given our standard errors for \(\hat{\beta}_0\) and \(\hat{\beta}_1\), we may want to know how precise our BLP estimate of \(Y\) is at a given \(x\)

    \[\hat{Y}(x) = \hat{\beta}_0 + \hat{\beta}_1 x\]

  • This is a sum of two random variables, so we need the full variance-covariance matrix of \(\hat{\boldsymbol{\beta}}\)

    \[\Var\bigg(\hat{Y}(x)\bigg) = \Var(\hat{\beta}_0) + x^2\,\Var(\hat{\beta}_1) + 2x\,\Cov(\hat{\beta}_0, \hat{\beta}_1)\]

    • Plug in the HC0 estimates of all three!
  • To get the intuition for how the variance changes, re-write the line as: \(\hat{Y}(x) = \bar{Y} + \hat{\beta}_1\,(x - \bar{X})\)

    • At \(\bar{X}\), we have uncertainty about \(\bar{Y}\)
    • And we have uncertainty about how the slope, which matters more as we move away from \(\bar{X}\)
    • So the sampling variance is smallest near \(\bar{X}\) and grows as we move away from it, giving a “bowtie” shape to the confidence intervals.

Confidence interval for the regression line

# HC0 vcov of the intercept and slope
V <- vcovHC(fit_hs, type = "HC0")
V
               (Intercept) hostile_sexism
(Intercept)      0.6418807      -1.362200
hostile_sexism  -1.3622003       4.614875
grid <- seq(0, 1, by = 0.01)
se_fit <- sqrt(V[1, 1] + grid^2 * V[2, 2] +
                2 * grid * V[1, 2])

line_ci <- tibble(x = grid,
                  fit = b_hs[1] + b_hs[2] * grid,
                  lower = fit - 1.96 * se_fit,
                  upper = fit + 1.96 * se_fit)
head(line_ci, 3)
# A tibble: 3 × 4
      x   fit lower upper
  <dbl> <dbl> <dbl> <dbl>
1  0     6.23  4.66  7.80
2  0.01  7.17  5.63  8.71
3  0.02  8.11  6.61  9.61

Comparing robust SEs with lm() defaults

  • coeftest() from lmtest will implement the tests with whatever variance covariance matrix we want to give it
library(lmtest)
coeftest(fit_full)                                           # lm() defaults

t test of coefficients:

                  Estimate Std. Error t value  Pr(>|t|)    
(Intercept)       -4.32538    0.70955 -6.0959 1.178e-09 ***
hostile_sexism    24.15327    1.85536 13.0181 < 2.2e-16 ***
racial_resentment 19.62334    1.41061 13.9112 < 2.2e-16 ***
partyIndependent  19.42301    1.41708 13.7064 < 2.2e-16 ***
partyRepublican   53.28474    0.85917 62.0190 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(fit_full, vcov = vcovHC(fit_full, type = "HC0"))    # robust (HC0)

t test of coefficients:

                  Estimate Std. Error t value  Pr(>|t|)    
(Intercept)       -4.32538    0.55927  -7.734 1.274e-14 ***
hostile_sexism    24.15327    2.02556  11.924 < 2.2e-16 ***
racial_resentment 19.62334    1.57288  12.476 < 2.2e-16 ***
partyIndependent  19.42301    1.84110  10.550 < 2.2e-16 ***
partyRepublican   53.28474    1.04225  51.125 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comparing robust SEs with lm() defaults

lm() default Robust (HC0)
(1) (2)
Intercept −4.33*** −4.33***
(0.71) (0.56)
Hostile sexism 24.15*** 24.15***
(1.86) (2.03)
Racial resentment 19.62*** 19.62***
(1.41) (1.57)
Independent 19.42*** 19.42***
(1.42) (1.84)
Republican 53.28*** 53.28***
(0.86) (1.04)
N 4,562 4,562
R² 0.68 0.68

Outcome: Trump thermometer. Democrats are the omitted party baseline. Standard errors in parentheses. Two-sided tests of H₀: βj = 0: * p < 0.05, ** p < 0.01, *** p < 0.001.

  • The estimates are identical. Only the standard errors change
  • The robust SEs are larger for every slope
    • 30% larger for the Independent dummy
  • Why are they larger?

T-stat looks too good.
Use robust standard errors—
significance gone.

— Keisuke Hirano

Homoskedasticity

  • The classical OLS model adds an assumption about the errors: homoskedasticity

    \[\mathbb{E}[e_i^2 \mid \mathbf{X}_i] = \sigma^2\]

    • The variance of the errors is constant at every value of the covariates
  • Under homoskedasticity, the filling simplifies by the law of iterated expectations

    \[\boldsymbol{\Omega} = \mathbb{E}[e_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime] = \mathbb{E}\big[\mathbb{E}[e_i^2 \mid \mathbf{X}_i]\,\mathbf{X}_i\mathbf{X}_i^\prime\big] = \sigma^2\,\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\]

  • And the sandwich reduces to…

    \[\Var(\hat{\boldsymbol{\beta}}) \approx \frac{1}{n}\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\,\sigma^2\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\,\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1} = \frac{\sigma^2}{n}\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\]

    \[\Var(\hat{\boldsymbol{\beta}}) \approx \frac{1}{n}\sigma^2\left(\frac{1}{n}\mathbf{X}^\prime\mathbf{X}\right)^{-1} = \sigma^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]

Is homoskedasticity plausible?

  • No! The residuals are far more spread out for Independents and Republicans than for Democrats
    • What we’d expect for a bounded thermometer: 75% of Democrats rate Trump at exactly 0
    • Can’t go any lower!

Estimating \(\sigma^2\)

  • A natural plug-in for \(\sigma^2\) is \(\frac{1}{n}\sum_{i=1}^n \hat{e}_i^2\).

    • But like the plug-in sample variance, it is biased downward: OLS picks \(\hat{\boldsymbol{\beta}}\) to make the residuals small in this sample
  • The unbiased estimator divides by \(n - k\), the number of observations minus the number of coefficients

    \[\hat{\sigma}^2 = \frac{1}{n - k}\sum_{i=1}^n \hat{e}_i^2\]

  • Related to our earlier results for the unbiased population variance estimator

    • There we divided by \(n-1\)
    • Here since each estimated coefficient “uses up” one degree of freedom, we divide by \(n-k\).
  • The classical OLS variance estimator is therefore

    \[\widehat{\Var}(\hat{\boldsymbol{\beta}}) = \hat{\sigma}^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]

  • Default for summary(lm())

Robust or classical?

  • HC standard errors are consistent whether or not the errors are homoskedastic
    • Classical standard errors are only consistent under homoskedasticity
  • If homoskedasticity does hold, the classical estimator is more precise.
    • But it’s rarely a credible assumption!
  • In practice: default to robust standard errors
    • In 813, we’ll talk more about the HC2 correction (default in lm_robust() in the estimatr package).
    • “Agnostic” regression

The classical linear model

  • Many textbooks start from a much stronger set of assumptions. Conditional on the \(n \times k\) matrix \(\mathbf{X}\)

    1. Linearity: \(\mathbf{Y} = \mathbf{X}\boldsymbol{\beta} + \mathbf{e}\) with \(\mathbb{E}[\mathbf{e} \mid \mathbf{X}] = \mathbf{0}\). The CEF is linear
    2. Full rank: \(\mathbf{X}^\prime\mathbf{X}\) is invertible
    3. Spherical errors: \(\Var(\mathbf{e} \mid \mathbf{X}) = \sigma^2\mathbf{I}_n\). Homoskedastic and uncorrelated across observations
    4. (Sometimes) Normality: \(\mathbf{e} \mid \mathbf{X} \sim \mathcal{N}(\mathbf{0}, \sigma^2\mathbf{I}_n)\)
  • The benefit of this is that we get exact finite-sample results instead of asymptotic approximations

    • Under 1-3, OLS is unbiased and its variance is exactly the classical formula

    \[\mathbb{E}[\hat{\boldsymbol{\beta}} \mid \mathbf{X}] = \boldsymbol{\beta} \qquad \Var(\hat{\boldsymbol{\beta}} \mid \mathbf{X}) = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\,\underbrace{\Var(\mathbf{e} \mid \mathbf{X})}_{\sigma^2\mathbf{I}_n}\,\mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1} = \sigma^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]

  • Our “agnostic” approach so far needed only i.i.d. sampling and the regularity conditions

    • OLS estimates the BLP, whatever the CEF looks like, and the robust variance is valid for asymptotic inference on the BLP

SEs and assumptions about the error variances

  • With a linear CEF, the “filling” of the sandwich variance can be written in terms of the variance-covariance matrix of the errors \(\boldsymbol{\Sigma} = \Var(\mathbf{e} \mid \mathbf{X})\)

    \[\Var(\hat{\boldsymbol{\beta}} \mid \mathbf{X}) = (\mathbf{X}^\prime\mathbf{X})^{-1}\,\mathbf{X}^\prime\boldsymbol{\Sigma}\mathbf{X}\,(\mathbf{X}^\prime\mathbf{X})^{-1}\]

  • Each standard error estimator assumes a different \(\boldsymbol{\Sigma}\)

Homoskedastic

\[\small \begin{pmatrix} \sigma^2 & 0 & \cdots & 0 \\ 0 & \sigma^2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma^2 \end{pmatrix}\]

  • Constant variance + no cross-unit covariance
  • Plug in \(\hat{\sigma}^2\): classical

Heteroskedastic

\[\small \begin{pmatrix} \sigma_1^2 & 0 & \cdots & 0 \\ 0 & \sigma_2^2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma_n^2 \end{pmatrix}\]

  • Non-constant variance + no cross-unit covariance
  • Plug in \(\hat{e}_i^2\): HC

Clustered

\[\small \left(\begin{array}{ccc|ccc|c} \sigma_1^2 & \sigma_{12} & \cdots & 0 & 0 & \cdots & \cdots \\ \sigma_{12} & \sigma_2^2 & \cdots & 0 & 0 & \cdots & \cdots \\ \vdots & \vdots & \ddots & \vdots & \vdots & & \\ \hline 0 & 0 & \cdots & \sigma_j^2 & \sigma_{jk} & \cdots & \cdots \\ 0 & 0 & \cdots & \sigma_{jk} & \sigma_k^2 & \cdots & \cdots \\ \vdots & \vdots & & \vdots & \vdots & \ddots & \\ \hline \vdots & \vdots & & \vdots & \vdots & & \ddots \end{array}\right)\]

  • Arbitrary correlation within clusters but none across
  • Plug in \(\hat{e}_i\hat{e}_j\) within clusters: cluster-robust

The Gauss-Markov theorem

  • Under assumptions 1-3, OLS is the Best Linear Unbiased Estimator (BLUE)

    • Linear: \(\tilde{\boldsymbol{\beta}} = \mathbf{C}\mathbf{Y}\) for some \(k \times n\) matrix \(\mathbf{C}\) that depends only on \(\mathbf{X}\). OLS has \(\mathbf{C} = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\)
    • Unbiased: \(\mathbb{E}[\tilde{\boldsymbol{\beta}} \mid \mathbf{X}] = \mathbf{C}\mathbf{X}\boldsymbol{\beta} = \boldsymbol{\beta}\) for every \(\boldsymbol{\beta}\), which requires \(\mathbf{C}\mathbf{X} = \mathbf{I}_k\)
    • Best: no other linear unbiased estimator has a smaller variance for any coefficient (or linear combination of coefficients)
  • Proof sketch: write an alternative estimator that deviates from OLS: \(\mathbf{C} = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime + \mathbf{D}\).

    • Unbiasedness requires \(\mathbf{D}\mathbf{X} = \mathbf{0}\), so the cross terms drop out

    \[\small \Var(\tilde{\boldsymbol{\beta}} \mid \mathbf{X}) = \sigma^2\mathbf{C}\mathbf{C}^\prime = \sigma^2\big[(\mathbf{X}^\prime\mathbf{X})^{-1} + \underbrace{(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\mathbf{D}^\prime}_{\mathbf{0}} + \underbrace{\mathbf{D}\mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1}}_{\mathbf{0}} + \mathbf{D}\mathbf{D}^\prime\big] = \Var(\hat{\boldsymbol{\beta}} \mid \mathbf{X}) + \sigma^2\mathbf{D}\mathbf{D}^\prime\]

    • The \(j\)th diagonal entry of \(\mathbf{D}\mathbf{D}^\prime\) is a sum of squares, \(\sum_i D_{ji}^2 \geq 0\), so every coefficient’s variance can only go up

What BLUE does and doesn’t buy us

  • “Best” only among estimators that are linear in \(\mathbf{Y}\) and unbiased
    • A biased estimator can have a lower mean squared error (e.g. a penalized regression)
  • It depends on homoskedasticity:
    • Weighted least squares, which down-weights the noisier observations, can do better if we know the form of the heteroskedasticity
    • And the classical standard errors are wrong
  • It needs a linear CEF for unbiasedness
    • Without it, OLS is still consistent for the BLP, but the finite-sample results no longer hold

Hierarchy of assumptions

Compute
\(\hat{\boldsymbol{\beta}}\)
Consistent
for the BLP
Asymptotic
inference on the BLP(robust SEs)
Unbiased
for the CEF
BLUE(classical SEs) Exact
finite-sample inference(\(t_{n-k}\))
No perfect collinearity ✓ ✓ ✓ ✓ ✓ ✓
i.i.d. sampling + regularity conditions ✓ ✓ ✓ ✓ ✓
Linear CEF, \(\mathbb{E}[e_i \mid \mathbf{X}_i] = 0\) ✓ ✓ ✓
Homoskedasticity, \(\Var(e_i \mid \mathbf{X}_i) = \sigma^2\) ✓ ✓
Normal errors ✓
  • Very little gets us the BLP and valid (asymptotic) inference on it: i.i.d. sampling, robust standard errors and a CLT
  • Saying anything about the CEF itself requires it to be linear (in whatever \(\mathbf{X}\) we provide).
  • Homoskedasticity and normality get efficiency and exact small-sample inference, but they’re rarely credible

Next week

  • Wrapping up inference for regression

    • Wald tests of several coefficients at once
  • More regression mechanics

    • Regression as a linear smoother of \(\mathbf{Y}\)
    • Regression as a kind of “weighting” estimator
    • Leverage and influential observations
    • Diagnosing your regression
  • Problem Set 5 due Tuesday, November 17

  • Second Midterm Exam on Wednesday, November 18

References

Hainmueller, Jens, Jonathan Mummolo, and Yiqing Xu. 2019. “How Much Should We Trust Estimates from Multiplicative Interaction Models? Simple Tools to Improve Empirical Practice.” Political Analysis 27 (2): 163–92. https://doi.org/10.1017/pan.2018.46.
Kinder, Donald R., and Lynn M. Sanders. 1996. Divided by Color: Racial Politics and Democratic Ideals. University of Chicago Press.