Math for Causal Inference

Day 75. Bandwidth Selection & Bias Correction

The bandwidth trades bias against variance. The MSE-optimal bandwidth balances them so well that the bias is no longer negligible relative to the standard error, and conventional confidence intervals under-cover. Robust bias-corrected inference fixes this by subtracting an estimate of the bias and accounting for its uncertainty.

Video coming soon
Learning outcomes
  • ●Derive the MSE-optimal bandwidth and its n^(−1/5) rate.
  • ●Show that at the MSE-optimal bandwidth the bias is half the standard error, and compute the resulting coverage loss.
  • ●Explain robust bias-corrected (RBC) confidence intervals and why conventional standard errors are too small after bias correction.
  • ●Design a bandwidth robustness analysis for an RD study.
2-HOUR SESSION PLAN
Theory 25′Warm-up (1–5) 20′Proofs (6–10) 35′Applied (11–15) 25′Python & Lab 15′
Colab notebook (.ipynb) Jump to the simulator

Theory

The trade-off

For a local linear RD estimator with bandwidth hh and sample size nn,

Bias≈Bh2,Var⁡≈Vnh,\text{Bias} \approx Bh^2, \qquad \operatorname{Var} \approx \frac{V}{nh},

where BB depends on the curvature of E[Y∣X]E[Y \mid X] near the cutoff and VV on the outcome variance and the density of XX at cc.

MSE-optimal bandwidth

Minimising MSE(h)=B2h4+V/(nh)\text{MSE}(h) = B^2h^4 + V/(nh) gives

hMSE=(V4B2n)1/5∝n−1/5.h_{MSE} = \Big(\frac{V}{4B^2n}\Big)^{1/5} \propto n^{-1/5}.

Data-driven selectors (Imbens–Kalyanaraman; Calonico–Cattaneo–Titiunik, CCT) estimate BB (using a pilot local quadratic fit) and VV, then plug in. Different bandwidths can be used on each side.

The inference problem

At hMSEh_{MSE}, squared bias equals one quarter of the variance, so

BiasSE⁡=12.\frac{\text{Bias}}{\operatorname{SE}} = \frac12.

A conventional 95% interval τ^±1.96 SE⁡\hat\tau \pm 1.96\,\operatorname{SE} then covers only about 92% of the time, and less when bias is underestimated.

Fixes

  • Undersmoothing: use a smaller bandwidth than hMSEh_{MSE} so bias is negligible; the point estimate becomes noisier and the right amount of undersmoothing is unclear.
  • Robust bias correction (Calonico, Cattaneo and Titiunik, 2014): estimate the bias with a local quadratic fit (pilot bandwidth bb), subtract it, and compute a standard error that includes the variability of the bias estimate. With b=hb = h, the bias-corrected estimator coincides with the local quadratic estimator, and RBC inference is local quadratic inference at bandwidth hh.

Current practice: report the local linear estimate at hMSEh_{MSE} with the RBC confidence interval; show sensitivity to halving and doubling the bandwidth. Coverage-error-optimal bandwidths (smaller than hMSEh_{MSE}) are an alternative for inference.

Part 1 · Warm-up

Exercise 1 · An optimal bandwidth

With B=2B = 2, V=4V = 4 and n=1,000n = 1{,}000, compute hMSEh_{MSE}.

Show solution

Step 1. h=(4/(4×4×1,000))1/5=(1/4,000)1/5h = (4/(4 \times 4 \times 1{,}000))^{1/5} = (1/4{,}000)^{1/5}.

Step 2. ln⁡4,000≈8.29\ln 4{,}000 \approx 8.29; divided by 5: 1.66; e−1.66≈0.19e^{-1.66} \approx 0.19.

Answer: about 0.19 units of the running variable.

Exercise 2 · More data

If the sample grows 32-fold, how does hMSEh_{MSE} change?

Show solution

Step 1. h∝n−1/5h \propto n^{-1/5}; 32−1/5=1/232^{-1/5} = 1/2.

Answer: it halves.

Exercise 3 · Coverage at the optimum

With bias equal to half the SE, what is the coverage of a nominal 95% interval?

Show solution

Step 1. The t-statistic is N(0.5,1)N(0.5, 1) around the truth.

Step 2. Coverage =P(∣Z+0.5∣<1.96)=Φ(1.46)−Φ(−2.46)≈0.928−0.007=0.921= P(|Z + 0.5| < 1.96) = \Phi(1.46) - \Phi(-2.46) \approx 0.928 - 0.007 = 0.921.

Answer: about 92%.

Exercise 4 · Undersmoothing

To make the bias at most 10% of the SE, by what factor must the bandwidth shrink relative to hMSEh_{MSE}?

Show solution

Step 1. Bias/SE ∝h2⋅h1/2=h5/2\propto h^2 \cdot h^{1/2} = h^{5/2}.

Step 2. We need the ratio to fall from 0.5 to 0.1: factor 5, so hh shrinks by 52/5≈1.905^{2/5} \approx 1.90.

Answer: use roughly half the MSE-optimal bandwidth; the SE then rises by 1.9≈1.38\sqrt{1.9} \approx 1.38.

Exercise 5 · Ingredients of RBC

List what is estimated in robust bias-corrected inference.

Show solution

Step 1. The local linear estimate τ^h\hat\tau_h with bandwidth hh.

Step 2. The bias B^\hat B from a local quadratic fit with pilot bandwidth bb.

Step 3. A standard error for τ^h−B^\hat\tau_h - \hat B that includes the variance of B^\hat B and its covariance with τ^h\hat\tau_h.

Part 2 · Proofs

Exercise 6 · Deriving the optimal bandwidth

Minimise B2h4+V/(nh)B^2h^4 + V/(nh) over h>0h > 0.

Show solution

Step 1. Derivative: 4B2h3−V/(nh2)=04B^2h^3 - V/(nh^2) = 0.

Step 2. h5=V/(4B2n)h^5 = V/(4B^2n), so h=(V/(4B2n))1/5h = (V/(4B^2n))^{1/5}.

Step 3. The second derivative 12B2h2+2V/(nh3)>012B^2h^2 + 2V/(nh^3) > 0: a minimum. ■\blacksquare

Exercise 7 · Bias is half the SE

Show that at hMSEh_{MSE}, Bias2=Var⁡/4\text{Bias}^2 = \operatorname{Var}/4.

Show solution

Step 1. From Exercise 6, 4B2h5=V/n4B^2h^5 = V/n, so B2h4=V/(4nh)B^2h^4 = V/(4nh).

Step 2. The left side is Bias2\text{Bias}^2; the right side is Var⁡/4\operatorname{Var}/4. ■\blacksquare

Exercise 8 · The convergence rate

Show that at hMSEh_{MSE} the root mean squared error is of order n−2/5n^{-2/5}, slower than the parametric n−1/2n^{-1/2}.

Show solution

Step 1. MSE=B2h4+V/(nh)\text{MSE} = B^2h^4 + V/(nh) with h∝n−1/5h \propto n^{-1/5}.

Step 2. B2h4∝n−4/5B^2h^4 \propto n^{-4/5} and V/(nh)∝n−1+1/5=n−4/5V/(nh) \propto n^{-1 + 1/5} = n^{-4/5}.

Step 3. RMSE∝n−2/5\text{RMSE} \propto n^{-2/5}. ■\blacksquare RD uses only data near the cutoff, so it learns more slowly than an experiment.

Exercise 9 · Why bias correction needs a new SE

Let τ^bc=τ^−B^\hat\tau_{bc} = \hat\tau - \hat B. Show Var⁡(τ^bc)=Var⁡(τ^)+Var⁡(B^)−2Cov⁡(τ^,B^)\operatorname{Var}(\hat\tau_{bc}) = \operatorname{Var}(\hat\tau) + \operatorname{Var}(\hat B) - 2\operatorname{Cov}(\hat\tau, \hat B) and explain why using SE⁡(τ^)\operatorname{SE}(\hat\tau) alone is wrong.

Show solution

Step 1. Variance of a difference.

Step 2. B^\hat B is estimated from the same (or overlapping) data with a curvature estimate, which is noisy: Var⁡(B^)\operatorname{Var}(\hat B) is not negligible in large samples when bb is of the same order as hh.

Answer: ignoring it understates uncertainty; RBC uses the full variance. ■\blacksquare

Exercise 10 · Choosing the bandwidth by eye

Explain why picking the bandwidth that gives the most significant estimate invalidates inference.

Show solution

Step 1. Estimates at different bandwidths are noisy, and some will be significant by chance.

Step 2. Choosing the most significant inflates the probability of rejecting a true null above 5% (specification searching).

Answer: pre-specify a data-driven bandwidth and report sensitivity across bandwidths, not the best one. ■\blacksquare

Part 3 · Applied

Exercise 11 · A scholarship RD bandwidth

A pilot local quadratic fit suggests B=0.5B = 0.5 (enrolment probability per squared score unit, in standardised score units), the variance constant is V=2V = 2, and there are n=5,000n = 5{,}000 students. Compute hMSEh_{MSE}, and the bandwidth after a 50% undersmoothing.

Show solution

Step 1. h=(2/(4×0.25×5,000))1/5=(2/5,000)1/5=(0.0004)0.2h = (2/(4 \times 0.25 \times 5{,}000))^{1/5} = (2/5{,}000)^{1/5} = (0.0004)^{0.2}.

Step 2. ln⁡0.0004≈−7.82\ln 0.0004 \approx -7.82; /5=−1.56/5 = -1.56; e−1.56≈0.21e^{-1.56} \approx 0.21.

Answer: hMSE≈0.21h_{MSE} \approx 0.21 sd of the score; undersmoothed about 0.10.

Exercise 12 · Coverage in a simulation

In the simulation below (true jump 5, curved regression function, 1,000 observations), compare the coverage of conventional local linear intervals with local quadratic (RBC with b=hb = h) intervals at bandwidths 0.15, 0.3 and 0.5.

Show solution

Step 1. Small hh: both cover about 92–93%; the local quadratic interval is wider.

Step 2. At h=0.5h = 0.5, the local linear estimate is biased (about +0.5) and its interval covers only about 86%.

Step 3. The local quadratic interval keeps coverage near 94% at every bandwidth.

Answer: robust bias correction protects inference when the bandwidth is large enough for bias to matter.

Exercise 13 · A bandwidth robustness table

For an RD on the effect of a pension eligibility age on retirement, outline a robustness table.

Show solution

Step 1. Rows: hMSEh_{MSE}, hMSE/2h_{MSE}/2, 2hMSE2h_{MSE}, and the coverage-error-optimal bandwidth.

Step 2. Columns: point estimate, RBC 95% CI, number of observations on each side.

Step 3. Also: local quadratic fits, triangular versus uniform kernel.

Answer: stable estimates across rows support the result; strong sensitivity signals curvature or too few observations near the cutoff.

Exercise 14 · Different bandwidths on each side

Mortality data around a very-low-birth-weight cutoff have many more observations above than below the threshold, and curvature differs. Why might separate bandwidths help?

Show solution

Step 1. Each side's MSE depends on its own density, variance and curvature.

Step 2. Separate bandwidths use more data where it is plentiful and the function is flat, less where it curves.

Answer: lower overall MSE for the jump estimate; CCT-style selectors provide side-specific bandwidths.

Exercise 15 · Few observations near the cutoff

An RD on a school-entry age cutoff has only 60 children within a month of the cutoff. What alternative to continuity-based inference is appropriate?

Show solution

Step 1. Asymptotic local polynomial inference may be unreliable with so few observations.

Step 2. Local randomisation: treat children born within a narrow window as if randomly assigned, check covariate balance, and use Fisher randomisation inference (Day 37).

Answer: a local-randomisation analysis in a small window, reported alongside the continuity-based estimate.

Verify in Python

import numpy as np
from scipy.stats import norm

print("Ex 1 h_MSE:", round((4 / (4 * 4 * 1000)) ** .2, 3), " Ex 11:", round((2 / (4 * .25 * 5000)) ** .2, 3),
      " Ex 3 coverage:", round(norm.cdf(1.96 - .5) - norm.cdf(-1.96 - .5), 3), " Ex 4 factor:", round(5 ** .4, 2))

rng = np.random.default_rng(75)
mu0 = lambda x: 50 + 8 * x + 30 * x ** 2 - 20 * x ** 3
def side(x, y, h, p):
    w = np.clip(1 - np.abs(x) / h, 0, None); m = w > 0
    X = np.column_stack([x[m] ** k for k in range(p + 1)]); W = w[m]
    A = np.linalg.inv(X.T @ (W[:, None] * X)); b = A @ (X.T @ (W * y[m])); r = y[m] - X @ b
    V = A @ (X.T @ ((W ** 2 * r ** 2)[:, None] * X)) @ A                    # heteroskedasticity-robust
    return b[0], V[0, 0]
def rd(x, y, h, p):
    r = x >= 0
    a, va = side(x[r], y[r], h, p); b, vb = side(-x[~r], y[~r], h, p)
    return a - b, np.sqrt(va + vb)
print("  h   LL bias  LL sd  LL cover | LQ bias  LQ sd  LQ cover")
for h in (.15, .3, .5):
    out = {1: [], 2: []}; cov = {1: 0, 2: 0}
    for _ in range(1000):
        x = rng.uniform(-1, 1, 1000); y = mu0(x) + 5 * (x >= 0) + rng.normal(0, 3, 1000)
        for p in (1, 2):
            t, s = rd(x, y, h, p); out[p].append(t); cov[p] += abs(t - 5) < 1.96 * s
    print(f"{h:4.2f}  {np.mean(out[1]) - 5:7.2f}  {np.std(out[1]):5.2f}  {cov[1] / 1000:7.3f} | "
          f"{np.mean(out[2]) - 5:7.2f}  {np.std(out[2]):5.2f}  {cov[2] / 1000:7.3f}")

Key takeaways

  • The MSE-optimal bandwidth shrinks like n^(−1/5) and leaves a bias equal to half the standard error.
  • Conventional intervals at that bandwidth under-cover; robust bias-corrected intervals subtract the estimated bias and account for its variance.
  • Pre-specify a data-driven bandwidth, report RBC intervals, and show sensitivity to the bandwidth.

Simulation Lab: Bandwidth & Robust Bias Correction

Open full screen →

Bias, SD and RMSE across bandwidths, and coverage of conventional versus robust bias-corrected intervals.

0120.20.40.60.8bandwidth hlocal linear60%80%100%0.20.40.60.8bandwidth hcoverage of 95% CI
|bias| / conventional coverageSDRMSErobust bias-corrected coverage
RMSE-best bandwidth
0.40
coverage there: conventional / RBC
90% / 96%

120 simulated RD studies at each bandwidth (true jump 5). Left: bias, SD and RMSE of the local linear estimate; the RMSE is smallest at an intermediate bandwidth. Right: coverage of conventional local linear 95% intervals versus robust bias-corrected intervals (local quadratic at the same bandwidth). Raise curvature to see conventional coverage collapse at wide bandwidths.

Day 74Day 76