Week 11: Regression, part 3

PS 812 - Introduction to Statistical Methods in Political Science

Anton Strezhnev

University of Wisconsin-Madison

November 17, 2026

Welcome back!

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

Regression

Regression is a projection

Frisch-Waugh-Lovell

Testing more than one coefficient

  • Recall the party interaction model from last week

    \[Y_i = \beta_0 + \beta_1 \text{HS}_i + \beta_2 \text{Ind}_i + \beta_3 \text{Rep}_i + \beta_4 (\text{HS}_i \times \text{Ind}_i) + \beta_5 (\text{HS}_i \times \text{Rep}_i) + e_i\]

  • Does the slope on hostile sexism differ by party at all?

    \[H_0: \beta_4 = 0 \text{ and } \beta_5 = 0 \qquad H_1: \beta_4 \neq 0 \text{ or } \beta_5 \neq 0\]

  • Is hostile sexism related to the thermometer in any party?

    \[H_0: \beta_1 = \beta_4 = \beta_5 = 0\]

  • Each null puts several restrictions on the coefficients at once

Why not just use the individual \(t\)-tests?

  • “Reject if either \(t\)-test rejects” is a multiple testing problem

    • Two tests at \(\alpha = 0.05\): the chance that at least one rejects under the joint null is above 5%
  • The two estimates are correlated - we can and should incorporate that into the test.

  • The individual tests and the joint test can disagree

    • Here: \(t = 0.43\) for \(\hat{\beta}_4\) and \(t = 1.93\) for \(\hat{\beta}_5\)
    • Two “almost significant” coefficients can be jointly significant or not.

Linear hypotheses: \(\mathbf{R}\boldsymbol{\beta} = \mathbf{r}\)

  • We can write a joint hypothesis as a set of restrictions on the coefficients.

  • For a linear set of restrictions, we can express this as a matrix product:

    \[H_0: \underbrace{\mathbf{R}}_{q \times k}\ \underbrace{\boldsymbol{\beta}}_{k \times 1} = \underbrace{\mathbf{r}}_{q \times 1}\]

    • Each row of \(\mathbf{R}\) is one restriction: a linear combination of the coefficients
    • \(q\) is the number of restrictions
  • “No difference in slopes by party”: \(\beta_4 = \beta_5 = 0\)

    \[\mathbf{R} = \begin{pmatrix} 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix} \qquad \mathbf{r} = \begin{pmatrix} 0 \\ 0 \end{pmatrix}\]

Examples of \(\mathbf{R}\) and \(\mathbf{r}\)

  • No relationship with hostile sexism in any party, \(\beta_1 = \beta_4 = \beta_5 = 0\) (\(q = 3\))

    \[\mathbf{R} = \begin{pmatrix} 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix} \qquad \mathbf{r} = \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix}\]

  • The slope among Republicans is zero, \(\beta_1 + \beta_5 = 0\) (\(q = 1\))

    \[\mathbf{R} = \begin{pmatrix} 0 & 1 & 0 & 0 & 0 & 1 \end{pmatrix} \qquad \mathbf{r} = 0\]

  • Independents and Republicans have the same slope, \(\beta_4 = \beta_5\) (\(q = 1\))

    \[\mathbf{R} = \begin{pmatrix} 0 & 0 & 0 & 0 & 1 & -1 \end{pmatrix} \qquad \mathbf{r} = 0\]

The sampling distribution of \(\mathbf{R}\hat{\boldsymbol{\beta}}\)

  • \(\mathbf{R}\hat{\boldsymbol{\beta}}\) is a linear function of an asymptotically normal vector, so it’s asymptotically normal too

    \[\mathbf{R}\hat{\boldsymbol{\beta}} \overset{a}{\sim} \mathcal{N}\big(\mathbf{R}\boldsymbol{\beta},\ \mathbf{R}\,\Var(\hat{\boldsymbol{\beta}})\,\mathbf{R}^\prime\big)\]

    • \(\mathbf{R}\,\Var(\hat{\boldsymbol{\beta}})\,\mathbf{R}^\prime\) is the \(q \times q\) variance-covariance matrix of the restricted combinations
  • Plug in our estimate (e.g. the HC0 robust variance), \(\widehat{\mathbf{V}} = \widehat{\Var}(\hat{\boldsymbol{\beta}})\)

  • Under \(H_0\), \(\mathbf{R}\hat{\boldsymbol{\beta}} - \mathbf{r}\) should be close to zero

The Wald statistic

  • Let’s construct a single statistic to build our test around.

  • Take squared distance from the null \(\mathbf{r}\), scaled by the variance-covariance matrix

    \[W = (\mathbf{R}\hat{\boldsymbol{\beta}} - \mathbf{r})^\prime\,\big(\mathbf{R}\widehat{\mathbf{V}}\mathbf{R}^\prime\big)^{-1}\,(\mathbf{R}\hat{\boldsymbol{\beta}} - \mathbf{r})\]

    • Without the middle matrix, this is just Euclidean distance
    • The inverse variance rescales each deviation by how noisy it is and uncorrelates them
    • The matrix version of “dividing by the variance” gives a squared Mahalanobis distance
  • With one restriction (\(q = 1\)), \(W\) is exactly \(T^2\) - our familiar univariate test statistic squared.

  • Large values of \(W\) are evidence against \(H_0\)

Why weight by the covariance?

Modelled after Blackwell (2025), Figure 8.1

The \(\chi^2_q\) distribution

  • Under \(H_0\), \(W \xrightarrow{d} \chi^2_q\): the sum of \(q\) independent squared standard normals
    • Standardizing by \((\mathbf{R}\widehat{\mathbf{V}}\mathbf{R}^\prime)^{-1}\) turns the \(q\) deviations into \(q\) uncorrelated normals with variance \(1\)
  • Reject at level \(\alpha\) when \(W > \chi^2_{q, 1 - \alpha}\). Our rejection region is one-sided since \(W \geq 0\) (qchisq(0.95, df = q))

Example: do the party interactions matter?

V_pint <- vcovHC(fit_pint, type = "HC0")       # robust variance-covariance matrix
b_pint <- coef(fit_pint)
se_pint <- sqrt(diag(V_pint))
round(cbind(estimate = b_pint, se = se_pint, t = b_pint / se_pint), 3)
                                estimate    se      t
(Intercept)                        0.950 0.489  1.942
hostile_sexism                    29.056 2.362 12.299
partyIndependent                  20.933 4.042  5.179
partyRepublican                   56.084 1.782 31.471
hostile_sexism:partyIndependent    4.118 9.502  0.433
hostile_sexism:partyRepublican     7.761 4.018  1.932
  • Neither interaction is individually significant at 5%, but \(\hat{\beta}_5\) is close
  • What about both together?

Wald tests by hand

R <- rbind(c(0, 0, 0, 0, 1, 0),                # hostile_sexism:partyIndependent
           c(0, 0, 0, 0, 0, 1))                # hostile_sexism:partyRepublican
r <- c(0, 0)

dev <- R %*% b_pint - r                        # q x 1 deviations from the null
W <- drop(t(dev) %*% solve(R %*% V_pint %*% t(R)) %*% dev)
c(W = W, critical = qchisq(0.95, df = 2), p = pchisq(W, df = 2, lower.tail = FALSE))
        W  critical         p 
3.7549954 5.9914645 0.1529724 
  • We fail to reject the null that the hostile sexism slope is the same in all three parties
  • But we do reject the null that hostile sexism is entirely unrelated to Trump support (\(H_0: \beta_1 = \beta_4 = \beta_5 = 0\))
R3 <- rbind(c(0, 1, 0, 0, 0, 0), c(0, 0, 0, 0, 1, 0), c(0, 0, 0, 0, 0, 1))
dev3 <- R3 %*% b_pint
W3 <- drop(t(dev3) %*% solve(R3 %*% V_pint %*% t(R3)) %*% dev3)
c(W = round(W3, 1), critical = round(qchisq(0.95, df = 3), 2), p = format.pval(pchisq(W3, df = 3, lower.tail = FALSE)))
           W     critical            p 
     "292.6"       "7.81" "< 2.22e-16" 

Wald tests in R

  • marginaleffects::hypotheses() implements a variety of null hypothesis tests
    • Coefficient names are in joint
    • Select a variance estimator with vcov
library(marginaleffects)
hypotheses(fit_pint,
           joint = c("hostile_sexism:partyIndependent", "hostile_sexism:partyRepublican"),
           vcov = "HC0", joint_test = "chisq")


Joint hypothesis test:
hostile_sexism:partyIndependent = 0
hostile_sexism:partyRepublican = 0
 
 ChiSq Pr(>|ChiSq|) Df
  3.75        0.153  2
  • Careful: joint_test defaults to the \(F\) test, and vcov defaults to the classical variance.
  • vcov takes "HC0" through "HC3", a clustering formula for clustered SEs ~ state, or a matrix computed elsewhere (like sandwich).

Wald tests and \(F\)-tests

  • What regression software reports by default is an \(F\)-statistic

    \[F = \frac{W}{q}\]

    • Almost always using classical (homoskedastic) standard errors and compared against an \(F_{q,\, n-k}\) distribution
    • This test is exact only under homoskedastic, normal errors
  • In large samples \(q \cdot F_{q, n-k}\) and \(\chi^2_q\) are equivalent.

    • The \(F\) is a slightly more conservative small-sample correction
  • The \(F\)-test at the bottom of summary(lm()) tests that every coefficient except the intercept is zero

    • Rarely an interesting hypothesis!
fit_add <- lm(ft_trump ~ hostile_sexism + party, data = anes)
anova(fit_add, fit_pint)                       # classical F-test of the two interactions
Analysis of Variance Table

Model 1: ft_trump ~ hostile_sexism + party
Model 2: ft_trump ~ hostile_sexism * party
  Res.Df     RSS Df Sum of Sq      F Pr(>F)
1   4570 2314789                           
2   4568 2312595  2    2193.9 2.1668 0.1147

One restriction: \(W = T^2\)

  • With a single restriction, \(\mathbf{R}\) is a \(1 \times k\) row and \(r\) is a number, so \(W\) is a scalar

    \[W = \frac{(\mathbf{R}\hat{\boldsymbol{\beta}} - r)^2}{\mathbf{R}\widehat{\mathbf{V}}\mathbf{R}^\prime} = \left(\frac{\mathbf{R}\hat{\boldsymbol{\beta}} - r}{\widehat{SE}(\mathbf{R}\hat{\boldsymbol{\beta}})}\right)^2 = T^2\]

  • And \(\chi^2_1\) is the distribution of a squared standard normal

    • \(\chi^2_{1, 0.95} = 3.84 = 1.96^2\)
    • The Wald test with \(q = 1\) is the two-sided \(t\)-test
  • So the \(t\)-test works for any linear combination, with standard error

    \[\widehat{SE}(\mathbf{R}\hat{\boldsymbol{\beta}}) = \sqrt{\mathbf{R}\widehat{\mathbf{V}}\mathbf{R}^\prime} = \sqrt{\sum_j R_j^2 \widehat{\Var}(\hat{\beta}_j) + 2\sum_{j < l} R_j R_l \widehat{\Cov}(\hat{\beta}_j, \hat{\beta}_l)}\]

    • E.g. the sum of two coefficients. Don’t forget the covariance!

    \[\widehat{SE}(\hat{\beta}_1 + \hat{\beta}_5) = \sqrt{\widehat{\Var}(\hat{\beta}_1) + \widehat{\Var}(\hat{\beta}_5) + 2\,\widehat{\Cov}(\hat{\beta}_1, \hat{\beta}_5)}\]

Testing a linear combination

  • The slope among Republicans is \(\beta_1 + \beta_5\), and the difference between Independents and Republicans is \(\beta_4 - \beta_5\)
lin_comb <- function(R, b, V) {
  est <- sum(R * b)                           # R b-hat
  se <- sqrt(drop(R %*% V %*% R))             # R V R', covariances included
  c(estimate = est, se = se, t = est / se, W = (est / se)^2,
    lower = est - qnorm(0.975) * se, upper = est + qnorm(0.975) * se)
}
round(rbind(
  republican_slope = lin_comb(c(0, 1, 0, 0, 0, 1), b_pint, V_pint),
  ind_minus_rep    = lin_comb(c(0, 0, 0, 0, 1, -1), b_pint, V_pint)
), 3)
                 estimate    se      t       W   lower  upper
republican_slope   36.818 3.250 11.329 128.348  30.448 43.187
ind_minus_rep      -3.643 9.761 -0.373   0.139 -22.774 15.488
hypotheses(fit_pint, hypothesis = "hostile_sexism + `hostile_sexism:partyRepublican` = 0", vcov = "HC0")

                                        Hypothesis Estimate Std. Error    z Pr(>|z|)    S 2.5 % 97.5 %
 hostile_sexism+`hostile_sexism:partyRepublican`=0     36.8       3.25 11.3   <0.001 96.4  30.4   43.2
  • The covariance term matters: \(\widehat{\Cov}(\hat{\beta}_1, \hat{\beta}_5) = -5.58\) is large and negative

The geometry of least squares

  • The column space of \(\mathbf{X}\) is every linear combination of its columns

    \[\mathcal{C}(\mathbf{X}) = \{\mathbf{X}\mathbf{b} : \mathbf{b} \in \mathbb{R}^k\}\]

    • Every possible vector of linear predictions of \(\mathbf{Y}\) from \(\mathbf{X}\)
  • \(\hat{\mathbf{Y}} = \mathbf{X}\hat{\boldsymbol{\beta}}\) is the point in \(\mathcal{C}(\mathbf{X})\) closest to \(\mathbf{Y}\): its projection

  • The shortest path from a point to a plane meets it at a right angle, so the residual is orthogonal to every column of \(\mathbf{X}\)

    \[\mathbf{X}^\prime\hat{\mathbf{e}} = \mathbf{X}^\prime(\mathbf{Y} - \mathbf{X}\hat{\boldsymbol{\beta}}) = \mathbf{0}\]

  • With an intercept: \(\sum_i \hat{e}_i = 0\) and \(\sum_i \hat{e}_i X_{ij} = 0\) for every covariate.

The hat matrix

  • Solving the normal equations and multiplying through by \(\mathbf{X}\)

    \[\hat{\mathbf{Y}} = \mathbf{X}\hat{\boldsymbol{\beta}} = \underbrace{\mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime}_{\mathbf{P}}\,\mathbf{Y}\]

  • \(\mathbf{P}\) is the \(n \times n\) projection matrix onto the column space of \(\mathbf{X}\)

    • Also called the hat matrix: it “puts the hat on” \(\mathbf{Y}\)
  • Multiplying any vector by \(\mathbf{P}\) gives its best linear prediction from \(\mathbf{X}\)

    • \(\mathbf{P}\mathbf{Z}\) = the fitted values from regressing \(\mathbf{Z}\) on \(\mathbf{X}\)

Properties of the hat matrix

  • Leaves \(\mathcal{C}(\mathbf{X})\) alone: anything already in the column space is its own projection

    \[\mathbf{P}\mathbf{X} = \mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\mathbf{X} = \mathbf{X}\]

  • Idempotent: projecting twice is the same as projecting once, \(\mathbf{P}\mathbf{P} = \mathbf{P}\)

    • Regressing the fitted values on \(\mathbf{X}\) returns the same fitted values
  • Symmetric: \(\mathbf{P}^\prime = \mathbf{P}\)

  • Trace (sum of the diagonals) equals the number of parameters \(k\)

    \[\text{tr}(\mathbf{P}) = \text{tr}\big(\mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\big) = \text{tr}\big((\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\mathbf{X}\big) = \text{tr}(\mathbf{I}_k) = k\]

The residual maker

  • The complement of \(\mathbf{P}\) is the annihilator or residual maker

    \[\mathbf{M} = \mathbf{I}_n - \mathbf{P} \qquad \mathbf{M}\mathbf{Y} = \mathbf{Y} - \hat{\mathbf{Y}} = \hat{\mathbf{e}}\]

  • It projects onto everything orthogonal to \(\mathcal{C}(\mathbf{X})\)

    • Annihilates \(\mathbf{X}\): \(\mathbf{M}\mathbf{X} = \mathbf{X} - \mathbf{P}\mathbf{X} = \mathbf{0}\)
    • Also symmetric and idempotent. \(\text{tr}(\mathbf{M}) = n - k\)
    • \(\mathbf{P}\mathbf{M} = \mathbf{0}\): the fitted values and the residuals are orthogonal
  • Regression splits the outcome into two perpendicular pieces

    \[\mathbf{Y} = \mathbf{P}\mathbf{Y} + \mathbf{M}\mathbf{Y} = \hat{\mathbf{Y}} + \hat{\mathbf{e}}\]

    • The part that’s explained by \(\mathbf{X}\) and the part that isn’t explained by \(\mathbf{X}\)

How well does the regression fit?

\(R^2\)

  • Without covariates, our best predictor is the mean. What’s left over is the total sum of squares

\[TSS = \sum_{i=1}^n (Y_i - \bar{Y})^2\]

  • With covariates, our best linear predictor is the OLS fit. What’s left over is the sum of squared residuals

    \[SSR = \sum_{i=1}^n (Y_i - \mathbf{X}_i^\prime\hat{\boldsymbol{\beta}})^2\]

  • The coefficient of determination (\(R^2\)) is the share of the prediction error removed by using \(\mathbf{X}_i\) over just the intercept.

    \[R^2 = \frac{TSS - SSR}{TSS} = 1 - \frac{SSR}{TSS}\]

  • \(0 \leq R^2 \leq 1\). Adding covariates is never worse than the mean (in-sample). And it can never explain more than what’s there to explain!

\(R^2\)

fit_full <- lm(ft_trump ~ hostile_sexism + racial_resentment + party, data = anes)
fits <- list(`HS` = fit_hs, `HS + RR` = fit_rr, `HS + RR + party` = fit_full, `HS x party` = fit_pint)
round(sapply(fits, \(f) c(R2 = summary(f)$r.squared, adj_R2 = summary(f)$adj.r.squared)), 3)
          HS HS + RR HS + RR + party HS x party
R2     0.252   0.415           0.684      0.671
adj_R2 0.252   0.415           0.684      0.671
  • Hostile sexism alone removes about 25% of the squared prediction error. Adding racial resentment and party brings it to 68%.
  • But \(R^2\) can never go down when we add a covariate, even pure noise
set.seed(812)
noise <- matrix(rnorm(nrow(anes) * 100), ncol = 100)    # 100 columns of random numbers
fit_noise <- lm(anes$ft_trump ~ anes$hostile_sexism + noise)
round(c(R2 = summary(fit_hs)$r.squared, R2_with_noise = summary(fit_noise)$r.squared), 4)
           R2 R2_with_noise 
       0.2522        0.2656 

What \(R^2\) does and doesn’t tell us

  • OLS minimizes SSR in the sample, so adding predictors can only improve the fit in-sample
    • Adjusted \(R^2 = 1 - \frac{SSR/(n-k)}{TSS/(n-1)}\) penalizes the \(R^2\) for each additional parameter, but it’s an ad-hoc correction.
    • Rather, we evaluate prediction quality by looking out of sample (e.g. leave-one-out cross-validation)
  • A low \(R^2\) does not mean the coefficients are wrong or uninteresting
    • Lots of \(Y\) varies for reasons unrelated to \(\mathbf{X}\). That’s fine if we care about \(\beta_j\)
  • A high \(R^2\) does not mean the CEF is linear, the model is “right,” or the coefficients are causal

“Better regressions most of the time”

“Better regressions most of the time”

Outliers, leverage, and influence

  • OLS minimizes squared residuals, so it works hardest to shrink the biggest ones

  • With an intercept, the fit always passes through the means: \(\bar{Y} = \bar{\mathbf{X}}^\prime\hat{\boldsymbol{\beta}}\)

    • Points near \(\bar{\mathbf{X}}\) can shift the line up or down but can’t tilt it much
    • Points far from \(\bar{\mathbf{X}}\) can move the “lever” a lot.
  • Influence consists of two elements:

    1. Leverage: \(\mathbf{X}_i\) is extreme - far from \(\bar{\mathbf{X}}\)
    2. An outlier: \(Y_i\) far from where the other observations would predict it to be

Leverage

  • The leverage of observation \(i\) is the \(i\)th diagonal of the hat matrix

    \[h_{ii} = \mathbf{X}_i^\prime(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}_i = [\mathbf{P}]_{ii}\]

  • Recall \(\hat{\mathbf{Y}} = \mathbf{P}\mathbf{Y}\), so every fitted value is a weighted sum of all the outcomes

    \[\hat{Y}_i = \sum_{j=1}^n h_{ij}Y_j = h_{ii}Y_i + \sum_{j \neq i} h_{ij} Y_j\]

    • \(h_{ij}\): how much \(Y_j\) moves the fitted value for \(i\)
    • \(h_{ii}\): how much \(Y_i\) moves its own fitted value
  • In a bivariate regression

    \[h_{ii} = \frac{1}{n} + \frac{(X_i - \bar{X})^2}{\sum_{j=1}^n (X_j - \bar{X})^2}\]

Properties of leverage

  • \(0 \leq h_{ii} \leq 1\), and \(h_{ii} \geq 1/n\)

  • Leverages sum to the number of regressors: \(\sum_{i} h_{ii} = \text{tr}(\mathbf{P}) = k\)

    • So the average leverage is \(k / n\)
  • \(h_{ii} = 1\): the fit passes exactly through \(Y_i\)

    • E.g. the only observation in a category that gets its own dummy

Where is leverage high?

Residuals at high-leverage points

  • A high-leverage point pulls the fit toward itself, so its own residual comes out small

  • Recall \(\hat{\mathbf{e}} = \mathbf{M}\mathbf{e}\). If the true errors were homoskedastic, \(\Var(e_i \mid \mathbf{X}) = \sigma^2\), then

    \[\Var(\hat{\mathbf{e}} \mid \mathbf{X}) = \mathbf{M}\sigma^2\mathbf{M}^\prime = \sigma^2\mathbf{M} \qquad \Var(\hat{e}_i \mid \mathbf{X}) = \sigma^2(1 - h_{ii})\]

    • The residuals are less variable than the errors - the variance is smaller for high-leverage points.
    • Where \(h_{ii} \to 1\), the residual is forced to zero!
  • So the residual \(\hat{e}_i\) understates how badly the fit predicts \(Y_i\)

    • Observation \(i\) helped choose its own fitted value. It’s an “in-sample” prediction

Leaving one observation out

  • Often we want to know how much the regression will change if we leave out a particular observation

    • Let \(\hat{\boldsymbol{\beta}}_{(-i)}\) be the estimated coefficients, leaving out observation \(i\)
    • The leave-one-out (LOO) prediction error is \(\tilde{e}_i = Y_i - \mathbf{X}_i^\prime\hat{\boldsymbol{\beta}}_{(-i)}\)
  • We don’t actually have to run \(n\) separate regressions. There’s a closed form expression in terms of the full fit \[\tilde{e}_i = \frac{\hat{e}_i}{1 - h_{ii}} \qquad \hat{\boldsymbol{\beta}} - \hat{\boldsymbol{\beta}}_{(-i)} = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}_i\tilde{e}_i\]

    • The LOO error inflates the residual by \(1 / (1 - h_{ii})\) - most of the impact is at high leverage
    • The coefficients move in proportion to the LOO error.
  • \(\sum_i \tilde{e}_i^2\) is an out-of-sample measure of fit.

Leverage and influence in action

Measuring influence: DFBETA and Cook’s distance

  • DFBETA: how much each coefficient moves when we drop observation \(i\)

    \[\text{DFBETA}_i = \hat{\boldsymbol{\beta}} - \hat{\boldsymbol{\beta}}_{(-i)} = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}_i\tilde{e}_i\]

    • One value per observation and coefficient. Divide by the coefficient’s SE for DFBETAS
  • How much does dropping \(i\) move its own fitted value?

    \[\hat{Y}_i - \mathbf{X}_i^\prime\hat{\boldsymbol{\beta}}_{(-i)} = \mathbf{X}_i^\prime(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}_i\tilde{e}_i = h_{ii}\,\tilde{e}_i\]

    • Influence = leverage \(\times\) outlier-ness = (Extreme in X) \(\times\) (Extreme relative to predicted Y)
  • Cook’s distance squares and standardizes this (Cook 1977)

    \[D_i = \frac{n - k}{k}\,\frac{h_{ii}\,\tilde{e}_i^2}{\sum_j \hat{e}_j^2}\]

Leaving one out, without refitting

  • What happens if we drop the most influential observation?
X <- model.matrix(fit_full)
e_hat <- resid(fit_full)
h <- hatvalues(fit_full)
i <- which.max(cooks.distance(fit_full))                 # the most influential respondent

dfbeta_formula <- solve(t(X) %*% X) %*% X[i, ] * e_hat[i] / (1 - h[i])
fit_drop <- lm(formula(fit_full), data = anes[-as.integer(names(i)), ])
round(cbind(formula = dfbeta_formula[, 1], refit = coef(fit_full) - coef(fit_drop),
            built_in = dfbeta(fit_full)[i, ]), 4)
                  formula   refit built_in
(Intercept)        0.0455  0.0455   0.0455
hostile_sexism    -0.0220 -0.0220  -0.0220
racial_resentment -0.1209 -0.1209  -0.1209
partyIndependent   0.2964  0.2964   0.2964
partyRepublican    0.0489  0.0489   0.0489

Influence in the running example

  • No single respondent moves \(\hat{\beta}_{HS}\) by more than 0.30, against a robust SE of 2.03. The largest Cook’s distance is 0.010
  • With \(n\) in the thousands and bounded regressors, no one point can matter much. Influence is more of a small-sample and heavy-tailed \(X\) problem.

Leverage and robust SEs: HC1, HC2, HC3

  • The HC0 “filling” plugs in \(\hat{e}_i^2\) for \(\sigma_i^2\), but residuals at high-leverage points are too small

    • So HC0 standard errors tend to be too small in small samples
  • The usual corrections (MacKinnon and White 1985)

    \[\text{HC1}: \frac{n}{n-k}\hat{e}_i^2 \qquad \text{HC2}: \frac{\hat{e}_i^2}{1 - h_{ii}} \qquad \text{HC3}: \frac{\hat{e}_i^2}{(1 - h_{ii})^2}\]

    • HC2 undoes the \((1 - h_{ii})\) shrinkage. It’s unbiased under homoskedasticity
    • HC3 plugs in the squared leave-one-out errors - most conservative.
  • In large samples without massively high-leverage points, they’re all basically the same

round(sapply(c("HC0", "HC1", "HC2", "HC3"), \(t) sqrt(diag(vcovHC(fit_full, type = t)))[2:3]), 4)
                     HC0    HC1    HC2    HC3
hostile_sexism    2.0256 2.0267 2.0277 2.0298
racial_resentment 1.5729 1.5737 1.5743 1.5758

Regression as a linear smoother

  • \(\hat{\mathbf{Y}} = \mathbf{P}\mathbf{Y}\): every fitted value is a weighted sum of the outcomes.

    \[\hat{Y}(\mathbf{x}) = \sum_{j=1}^n w_j(\mathbf{x})\, Y_j \qquad w_j(\mathbf{x}) = \mathbf{x}^\prime(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}_j\]

  • Our earlier Nadaraya-Watson estimator had the same form, with kernel weights

    \[\hat{Y}(x) = \sum_{j=1}^n w_j(x)\, Y_j \qquad w_j(x) = \frac{K_h(X_j - x)}{\sum_{l} K_h(X_l - x)}\]

  • Both are linear smoothers: \(\hat{\mathbf{Y}} = \mathbf{S}\mathbf{Y}\) for some \(n \times n\) matrix \(\mathbf{S}\) built from \(\mathbf{X}\)

    • In both cases, the weights sum to 1
    • \(\text{tr}(\mathbf{S})\) measures how flexible the fit is: the effective number of parameters (\(k\) for OLS)

The weights behind a fitted value

Comparing to kernel regression

  • Kernel weights are local: only respondents near \(x\) count
    • Few respondents near \(x = 1\), so each gets a lot of weight: the fit there is noisy
  • OLS weights are global and linear in \(X_j\)
    • At \(\bar{X}\), everyone counts equally: the fitted value is just \(\bar{Y}\)
    • Away from \(\bar{X}\), the respondents farthest from the mean on the same side count most…
    • … and those on the other side get negative weight
  • Bias-variance trade-off:
    • OLS borrows strength from the whole sample (low variance), but its prediction at \(x\) relies on observations nowhere near \(x\)

The coefficient as a weighted sum of outcomes

  • The coefficients are linear in \(\mathbf{Y}\) too. By FWL, for the coefficient on \(X_{i1}\)

    \[\hat{\beta}_1 = \frac{\sum_i \tilde{X}_{i1} Y_i}{\sum_i \tilde{X}_{i1}^2} = \sum_{i=1}^n \omega_i Y_i \qquad \omega_i = \frac{\tilde{X}_{i1}}{\sum_j \tilde{X}_{j1}^2}\]

    • \(\tilde{X}_{i1}\): the residual from regressing \(X_{i1}\) on the other covariates
    • The weights sum to zero and \(\sum_i \omega_i X_{i1} = 1\): a “contrast” of outcomes
  • Respondents whose \(X_{i1}\) is well predicted by the controls (\(\tilde{X}_{i1} \approx 0\)) contribute nothing

Next week

  • Second Midterm Exam tomorrow, Wednesday, November 18

  • Missing data

    • What happens when some observations are missing from our data
    • Bounds on the true sample mean
    • Weighting estimators under various assumptions on the missingness process
  • Survey weighting

    • Stratified and clustered sampling from a target population
    • Post-stratification to adjust for non-representative samples.

References

Cook, R. Dennis. 1977. “Detection of Influential Observation in Linear Regression.” Technometrics 19 (1): 15–18. https://doi.org/10.1080/00401706.1977.10489493.
MacKinnon, James G., and Halbert White. 1985. “Some Heteroskedasticity-Consistent Covariance Matrix Estimators with Improved Finite Sample Properties.” Journal of Econometrics 29 (3): 305–25. https://doi.org/10.1016/0304-4076(85)90158-7.