Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 37 ยท Matching and Weighting

Inverse Probability Weighting

Learn inverse probability weighting: build a pseudo-population balanced on covariates, estimate the ATE, stabilize and trim weights, and bootstrap the standard error in Python.

Matching throws away control units that never get picked. Inverse probability weighting (IPW) keeps everyone and instead gives each unit a weight so that the weighted treated and control groups look alike. It uses the same propensity score but in a smoother way, and it estimates the average treatment effect (ATE) for the whole population directly.

The idea

Suppose a young customer has a 10% chance of getting a coupon and an old customer has a 60% chance. In the data, treated customers are mostly old and the controls mostly young. To fix this, upweight the units that were unlikely to get the treatment they actually got: a treated unit with score 0.1 stands in for ten similar units, most of which were not treated.

The weight is

  • treated: w = 1 / e(X)
  • control: w = 1 / (1 - e(X))

After weighting, covariates are balanced between the two groups, and the weighted difference in means estimates the ATE:

ATE = mean(T*Y / e) - mean((1-T)*Y / (1-e))

This is the Horvitz-Thompson form. A common refinement divides by the sum of weights in each group (the Hajek or normalized version), which is more stable.

Python IPW estimate of the ATE

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both IPW versions land near 2.0. Look at the weight range: weights of 20 or more mean a few units dominate the answer.

Why extreme weights hurt

A unit with a score of 0.01 who was treated gets a weight of 100. One such unit can move the estimate and blow up its variance. Extreme weights usually point to an overlap problem: this kind of unit almost never gets treated, so the data tells you very little about them. Practical remedies:

  • Stabilized weights. Multiply by the marginal treatment probability: P(T=1)/e for treated, P(T=0)/(1-e) for controls. The mean weight is near 1 and the variance drops, and the estimate of the ATE is unchanged in expectation.
  • Trimming. Drop units with scores outside, say, [0.05, 0.95].
  • Truncation. Cap weights at a percentile such as the 99th.

These trade a little bias for a lot of stability.

Standard errors by bootstrap

The weights are estimated, so the usual formulas that treat them as fixed are wrong. The cleanest fix is to bootstrap the whole pipeline: resample units, refit the score model, recompute weights and the estimate.

Python Stabilized, trimmed weights with bootstrap standard error

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

An interval that covers the true value 2.0 is what you hope to see. Note that a bootstrap resample reruns the logistic regression every time, so the uncertainty from estimating the score is included.

IPW versus matching

Matching IPW
Usual target ATT ATE (ATT with other weights)
Uses all units No, drops unmatched controls Yes
Sensitive to Caliper, distance Extreme scores
Standard errors Bootstrap / special formulas Bootstrap / sandwich

For the ATT, weight treated units by 1 and controls by e/(1-e): controls that resemble the treated get large weights.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What weight does a control unit receive in ATE-style IPW?

    Controls are weighted by the inverse of the probability of the treatment they actually received, 1 - e(X).
  2. 2. Why do very large weights signal trouble?

    Scores near 0 or 1 give huge weights; those units are rarely seen in the other group, so the data says little about them.
  3. 3. How should you estimate the standard error when the propensity model is fitted from the same data?

    The score is estimated, so resampling the full procedure captures that extra uncertainty.
  4. 4. What does stabilizing weights do?

    Stabilized weights have mean near 1 and lower variance, with the same target effect.

Summary

  • IPW weights each unit by the inverse of the probability of the treatment it received, creating a balanced pseudo-population.
  • It estimates the ATE using all units; for the ATT, give controls the weight e/(1-e).
  • Extreme weights come from poor overlap; stabilize, trim or truncate them.
  • Bootstrap the whole pipeline for honest standard errors.

Next: Balance Diagnostics and Overlap