POSC 8410: Interactions

When the effect of X depends on Z

Will Horne

Back to the Start

On the first day of this course we looked at Bertrand and Mullainathan:

Name High quality Low quality
afam 6.70 6.19
cauc 10.79 8.50
  • A better résumé raised callbacks by 2.3 points for white-sounding names

  • And by 0.5 points for Black-sounding names

We said we would come back with the right tool.

The Model

Letting a Slope Depend on Something

\[Y = \beta_0 + \beta_1 X + \beta_2 Z + \beta_3 (X \times Z) + \varepsilon\]

Collect the \(X\) terms:

\[\frac{\partial Y}{\partial X} = \beta_1 + \beta_3 Z\]

  • The effect of \(X\) is now a function of \(Z\)

  • \(\beta_1\) is the effect of \(X\) when \(Z = 0\) — not “the” effect

  • \(\beta_3\) is how much that effect changes as \(Z\) goes up by one

This Is a Cross-Partial Derivative

\[\beta_3 = \frac{\partial^2 Y}{\partial X \, \partial Z}\]

Calculus again. The interaction is a second derivative: the rate at which one slope changes as the other variable moves.

It’s symmetric: \(\beta_3\) is also “how the effect of \(Z\) depends on \(X\).” The data cannot tell you which framing is the right one.

Fitting It

Code
summary(lm(cb ~ white * hq, data = resumes))$coefficients |> round(4)
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.0619     0.0078  7.9329   0.0000
white         0.0231     0.0110  2.0942   0.0363
hq            0.0052     0.0110  0.4694   0.6388
white:hq      0.0178     0.0156  1.1423   0.2534
  • white = 0.0231 - the race gap among low-quality résumés

  • hq = 0.0052 - the return to quality among Black-sounding names

  • white:hq = 0.0178 - how much larger the quality return is for white-sounding names

Recovering the Cells

  • Black, low: \(0.0619\)

  • Black, high: \(0.0619 + 0.0052 = 0.0671\)

  • White, low: \(0.0619 + 0.0231 = 0.0850\)

  • White, high: \(0.0619 + 0.0231 + 0.0052 + 0.0178 = 0.1080\)

A Trap: Reading Constituent Terms

Look again at hq = 0.0052:

  • It is not “the effect of résumé quality”

  • It is the effect of quality when white = 0 - that is, among Black-sounding names only

  • With an interaction in the model, every constituent term is a conditional effect at zero of the other variable

If the other variable has no meaningful zero, like income, age, ideology score, the constituent term is describing something not in the data

Centering Fixes the Interpretation

Subtract the mean from each variable before interacting:

Code
rc <- resumes |> mutate(wc = white - mean(white), hqc = hq - mean(hq))
round(coef(lm(cb ~ wc * hqc, data = rc)), 4)
(Intercept)          wc         hqc      wc:hqc 
     0.0805      0.0320      0.0141      0.0178 
Code
round(coef(lm(cb ~ white * hq, data = resumes)), 4)
(Intercept)       white          hq    white:hq 
     0.0619      0.0231      0.0052      0.0178 

What Changed and What Did Not

  • The interaction is identical: 0.0178 either way. Centering does not change it.

  • But white moved from 0.0231 to 0.0320: the average race gap across quality levels

  • And that 0.0320 is the coefficient from the model with no interaction at all

Centering only changes what “zero” means, and therefore what the constituent terms describe.

The Picture

Non-parallel lines are what an interaction looks like. Parallel lines mean no interaction.

But Look at the p-value

p-val

Code
summary(mi)$coefficients["white:hq", ] |> round(4)
  Estimate Std. Error    t value   Pr(>|t|) 
    0.0178     0.0156     1.1423     0.2534 
  • \(\hat{\beta}_3 = 0.0178\), standard error \(0.0156\), \(t = 1.14\), \(p = 0.25\)

  • We cannot reject the null that the interaction is zero

The descriptive pattern is striking, but the formal test does not support it. Why?

Why This Happens

  • The interaction is a difference between two differences

  • Each difference carries sampling error, and differencing them adds those errors

Code
se_main <- summary(lm(cb ~ white + hq, data = resumes))$coefficients["white", 2]
se_int  <- summary(mi)$coefficients["white:hq", 2]
round(c(main_effect_SE = se_main, interaction_SE = se_int, ratio = se_int / se_main), 4)
main_effect_SE interaction_SE          ratio 
        0.0078         0.0156         2.0000 

The interaction’s standard error is twice the main effect’s. Since precision scales with \(\sqrt{n}\), detecting an interaction of similar size needs roughly four times the sample.

How Underpowered Was It?

Suppose the observed cell rates are the truth, so the interaction really is 1.8 points. Re-run the experiment 2,000 times:

Show the simulation
set.seed(8410)
p_cell <- fitted(mi)   # each résumé's true callback chance = its cell's observed rate
sims <- map_dfr(1:2000, function(r) {
  cb_sim <- rbinom(nrow(resumes), 1, p_cell)   # same résumés, fresh callbacks
  co <- summary(lm(cb_sim ~ white * hq, data = resumes))$coefficients["white:hq", ]
  tibble(est = co[1], sig = co[4] < 0.05)
})

ggplot(sims, aes(100 * est, fill = sig)) +
  geom_histogram(binwidth = 0.4, boundary = 0) +
  geom_vline(xintercept = 100 * coef(mi)["white:hq"], linewidth = 1) +
  scale_fill_manual(values = c(`FALSE` = "grey75", `TRUE` = "#F66733"),
                    labels = c("not significant", "p < 0.05"), name = NULL) +
  labs(x = "Estimated interaction (percentage points)", y = "Replications") +
  theme_minimal(base_size = 14) +
  theme(legend.position = "top")
  • Power is 21%: most replications miss an interaction that is really there

  • The significant ones average 2.2 times the truth: the exaggeration problem from earlier

How Many Résumés Would It Take?

  • With 4,870 résumés: 98% power for the race gap, 21% for the interaction

  • 80% power for the interaction takes about 29,000 résumés, 6 times the study. Twice the standard error alone means four times the sample; the smaller effect does the rest

The General Rule

  • Interactions are chronically underpowered

  • A study sized to detect a main effect is usually not powered to detect moderation of it

  • So null interactions are weak evidence of homogeneity: absence of evidence, not evidence of absence

And the flip side: significant interactions in small samples are often noise.

So What Do We Say?

  • Report the estimate and its interval: the difference in returns is 1.8 points, 95% CI roughly \(-1.3\) to \(4.8\)

  • State plainly that the data are consistent with anything from a small reverse pattern to a large one

  • Do not write “the effect was larger for white applicants”

  • Do not write “there was no difference” either

“Our point estimate suggests a larger return for white-sounding names, but the interaction is imprecisely estimated” is a more honest sentence.

A Continuous Moderator

Does a Record Mean the Same at Every Age?

The COMPAS defendants from earlier: does each prior arrest predict rearrest within two years equally at every age?

Code
mc <- lm(two_year_recid ~ priors * age, data = compas)
# Robust SEs: a 0/1 outcome cannot have constant error variance
mc_rob <- lmtest::coeftest(mc, vcov = sandwich::vcovHC(mc, type = "HC1"))
round(mc_rob[, 1:3], 5)   # estimates, robust SEs, t values
            Estimate Std. Error   t value
(Intercept)  0.63915    0.02000  31.95755
priors       0.04669    0.00374  12.48738
age         -0.00864    0.00052 -16.66274
priors:age  -0.00039    0.00009  -4.23644
  • priors:age is negative and precise (\(t\) = -4.2): the older the defendant, the less a prior arrest predicts

  • One prior arrest adds 3.9 points to the chance of rearrest at age 20, but 2.4 at age 60

  • priors on its own is the effect at age 0: the constituent-term trap again

Plot the Marginal Effect

Each point on the line is \(\hat{\beta}_1 + \hat{\beta}_3 Z\) at that age, with its own 95% interval. The rug along the bottom shows each defendant’s age.

Why the Interval Is Not Just the Coefficient’s

  • At age \(Z\) the marginal effect is \(\hat{\beta}_1 + \hat{\beta}_3 Z\) — a sum of two estimates

  • Its variance is \(\text{Var}(\hat{\beta}_1) + Z^2\,\text{Var}(\hat{\beta}_3) + 2Z\,\text{Cov}(\hat{\beta}_1, \hat{\beta}_3)\)

That covariance term is why you cannot eyeball it from a regression table. It is an off-diagonal entry of the matrix we derived earlier, \(\hat{\sigma}^2(\mathbf{X}'\mathbf{X})^{-1}\), which R stores as vcov():

Code
X <- model.matrix(mc)
all.equal(vcov(mc), sigma(mc)^2 * solve(t(X) %*% X))
[1] TRUE

Robust standard errors keep that same \((\mathbf{X}'\mathbf{X})^{-1}\) on both sides of a correction for unequal variances, like bread around a filling. That is why the package is called sandwich.

Brambor, Clark and Golder

The Reading makes three demands that are routinely violated:

  1. Include all the constituent terms. Fitting \(X \times Z\) without \(X\) and \(Z\) constrains the model in ways nobody intends. (R handle this by default)

  2. Do not read significance off the interaction coefficient alone. The marginal effect can be significant where the interaction is not, and vice versa.

  3. Plot the marginal effect with its confidence interval, across observed values of \(Z\).

Is the Effect Really Linear?

The Assumption Inside \(\beta_3\)

  • \(\hat{\beta}_1 + \hat{\beta}_3 Z\) is a straight line in \(Z\). The plot we just drew could not have come out any other shape

  • So the model assumes the effect changes at a constant rate: a year of age matters as much at 20 as at 60

  • And it draws that line across all of \(Z\), including where there are almost no data

Hainmueller, Mummolo and Xu (2019) replicated 46 interactions from 22 top-journal articles: these two assumptions, linearity and common support, often fail. Their package interflex checks both.

Check 1: Binning

Cut age into thirds, estimate the effect of priors separately within each, and compare with the line:

Code
library(interflex)
bins <- interflex(estimator = "binning", data = compas,
                  Y = "two_year_recid", D = "priors", X = "age",
                  nbins = 3, vcov.type = "robust",
                  Ylabel = "rearrest", Dlabel = "priors", Xlabel = "age",
                  theme.bw = TRUE, bin.labs = FALSE)
bins$figure

Reading the Bins

  • If the line were right, all three red estimates would sit on it

  • The middle and oldest thirds do: 3.6 and 2.8 points per prior arrest, against 3.4 and 2.8 on the line

  • The youngest third (ages 18 to 27) does not: 5.5 points, against 3.7 on the line

  • A Wald test of the line against the bins: \(p\) < 0.001

The interaction is real, but the line has the wrong shape. It understates how much a record predicts for the youngest defendants.

Check 2: A Kernel Estimate

Estimate the effect at each age using mostly the defendants near that age, so the curve can bend:

Code
set.seed(8410)
kern <- interflex(estimator = "kernel", data = compas,
                  Y = "two_year_recid", D = "priors", X = "age",
                  bw = 2.68,   # interflex's cross-validated bandwidth, fixed here to save time
                  vcov.type = "robust", nboots = 200,
                  Ylabel = "rearrest", Dlabel = "priors", Xlabel = "age", theme.bw = TRUE)
kern$figure

What the Curve Shows

  • One prior arrest adds about 6.3 points to the chance of rearrest at 21, 3.0 at 37, and 2.8 at 50

  • So the moderation happens almost entirely in the twenties. After the late thirties the effect barely moves

  • Past 60 the band balloons: only 3.2% of defendants are over 60, and 29 are over 70

That last point is common support. The straight line still reports an effect at 90, but that number comes from the model’s shape, not from 90-year-olds.

In Your Own Work

  • Plot the marginal effect with the moderator’s distribution underneath, and interpret it only where there are data

  • Run the binning check. If the bins fall off the line, be transparent

  • If the effect bends, let the model bend.

  • None of this rescues an underpowered interaction. Flexible estimators need more data, not less

You Try

  1. Fit cb ~ white * city. Does the race gap differ between Boston and Chicago? Report the estimate and interval.

  2. Double the true interaction in the power simulation (raise the white, high-quality cell by 1.8 points). What is the power now?

  3. Re-run the binning check with nbins = 4. Does the youngest group still fall off the line?

  4. A paper reports a significant interaction in a subgroup of 40 observations. What would you want to know before believing it?

For Next Time

  • Read: Gelman, Hill and Vehtari, Ch. 11 (remainder)

  • Next class: model fit and diagnostics — \(R^2\) and its limits, residual plots, and influential observations