Algorithm Search⌘K

Algorithmcore

Inverse probability weighting

Also called IPW, inverse probability of treatment weighting, IPTW.

Weights each unit by one over the probability of the treatment it received, so the weighted sample mimics a randomized experiment.

Time
Θ(n) worst · best
Space
Θ(1) extra
Where
n = the number of units
Properties
deterministichajek form shift equivariantnot ht form shift equivariantneeds positivitysingle passunbiased with known propensity
Origin
Paul R. Rosenbaum, James M. Robins, 1987

Inverse probability weighting (IPW) estimates the average treatment effect τ=E[Y(1)−Y(0)]\tau = \mathbb{E}[Y(1) - Y(0)] from data in which the treatment was not assigned with equal chances. Each treated unit gets weight 1/e(Xi)1/e(X_i) and each control gets weight 1/(1−e(Xi))1/(1 - e(X_i)), where e(x)=Pr⁡[T=1∣X=x]e(x) = \Pr[T = 1 \mid X = x] is the propensity score. The weighted treated units then stand for the whole sample as if all had been treated, and the weighted controls stand for the whole sample as if none had been treated. Under ignorability, positivity and SUTVA, and with known propensities, the estimate is unbiased; this is the Horvitz-Thompson estimator applied once to each treatment arm. It takes one pass over the data.

In plain words

Suppose people with a mild illness got the new drug one time in four, and people with a severe illness three times in four. Then the treated group has too few mild cases. Each treated mild case had a one in four chance of being treated, so it stands in for four mild people. Each treated severe case stands in for four thirds of a severe person. After weighting, the treated group has the same mix of mild and severe cases as the full sample, and the same holds for the controls with weights one over the chance of no treatment. The difference of the weighted means compares like with like.

This only works if the treatment chance depends on things we measured, and if every kind of person had some chance of each treatment.

The problem

The two parts of the problem are kept apart: what the data can identify, and how to estimate it.

Identification. Each unit has potential outcomes Y(1)Y(1) and Y(0)Y(0), a treatment T∈{0,1}T \in \{0, 1\} and covariates XX measured before treatment. The units (Xi,Ti,Yi(0),Yi(1))(X_i, T_i, Y_i(0), Y_i(1)) are independent draws from one distribution. The estimand is τ=E[Y(1)−Y(0)]\tau = \mathbb{E}[Y(1) - Y(0)]. The assumptions are:

  1. Consistency and SUTVA. The observed outcome is Y=T Y(1)+(1−T) Y(0)Y = T\,Y(1) + (1 - T)\,Y(0): one version of each treatment, and no effect of other units' treatments.
  2. Ignorability. (Y(0),Y(1))⊥T∣X(Y(0), Y(1)) \perp T \mid X: given XX, the treatment does not depend on the potential outcomes.
  3. Positivity. 0<e(X)<10 < e(X) < 1 with probability 1.

Under these assumptions,

E[Y(1)]=E[T Ye(X)],E[Y(0)]=E[(1−T) Y1−e(X)],\mathbb{E}[Y(1)] = \mathbb{E}\left[\frac{T\,Y}{e(X)}\right], \qquad \mathbb{E}[Y(0)] = \mathbb{E}\left[\frac{(1 - T)\,Y}{1 - e(X)}\right],

so τ\tau is a function of the distribution of the observed (X,T,Y)(X, T, Y). Positivity can be checked in part from data: estimated propensities near 0 or 1 show where it fails or nearly fails. Ignorability cannot be checked from the observed data, and SUTVA is a claim about the design. Both rest on knowledge of how the treatment was assigned.

Estimation. The input is nn triples (Ti,Yi,ei)(T_i, Y_i, e_i) with ei=e(Xi)e_i = e(X_i). The propensity is known in a designed experiment with unequal assignment chances, and must be estimated in an observational study, for example by logistic regression. The output is two estimates of τ\tau:

τ^HT=1n∑i=1n(TiYiei−(1−Ti)Yi1−ei),τ^H=∑iTiYi/ei∑iTi/ei−∑i(1−Ti)Yi/(1−ei)∑i(1−Ti)/(1−ei).\hat\tau_{\mathrm{HT}} = \frac1n\sum_{i=1}^n\left(\frac{T_iY_i}{e_i} - \frac{(1 - T_i)Y_i}{1 - e_i}\right), \qquad \hat\tau_{\mathrm{H}} = \frac{\sum_i T_iY_i/e_i}{\sum_i T_i/e_i} - \frac{\sum_i (1 - T_i)Y_i/(1 - e_i)}{\sum_i (1 - T_i)/(1 - e_i)}.

The first is the Horvitz-Thompson form, and the second is the Hájek form, which divides each weighted sum by the sum of its weights instead of by nn.

The algorithm

  1. IPW-ATE(T, Y, e) ▷ n units; needs 0 < e_i < 1
  2. 1a1 ← 0; a0 ← 0; w1 ← 0; w0 ← 0
  3. 2for i ← 1 to n do
  4. 3if e_i ≤ 0 or e_i ≥ 1 then error "positivity fails"
  5. 4if T_i = 1 then a1 ← a1 + Y_i / e_i; w1 ← w1 + 1 / e_i
  6. 5else a0 ← a0 + Y_i / (1 - e_i); w0 ← w0 + 1 / (1 - e_i)
  7. 6τ_HT ← (a1 - a0) / n
  8. 7τ_H ← a1 / w1 - a0 / w0 ▷ needs w1 > 0 and w0 > 0
  9. 8return (τ_HT, τ_H)

Line L3 stops on a propensity of 0 or 1, where the weight is infinite or the unit can only ever be in one arm. Lines L4 and L5 build the weighted sums of each arm. With known propensities, w1w_1 and w0w_0 both have expectation nn, but in a given sample they differ from nn; line L6 divides by nn and line L7 divides by the sums.

Variance. Let ψi=TiYi/ei−(1−Ti)Yi/(1−ei)\psi_i = T_iY_i/e_i - (1 - T_i)Y_i/(1 - e_i), so that τ^HT\hat\tau_{\mathrm{HT}} is the mean of the ψi\psi_i. With known propensities, the ψi\psi_i are independent and identically distributed, and

vHT=Sψ2n,Sψ2=1n−1∑i=1n(ψi−τ^HT)2v_{\mathrm{HT}} = \frac{S_\psi^2}{n}, \qquad S_\psi^2 = \frac{1}{n - 1}\sum_{i=1}^n (\psi_i - \hat\tau_{\mathrm{HT}})^2

(divisor n−1n - 1) is an unbiased estimate of Var⁡[τ^HT]\operatorname{Var}[\hat\tau_{\mathrm{HT}}]. The Hájek form is an M-estimator, and its sandwich estimate is vH=1n2∑iϕi2v_{\mathrm{H}} = \frac{1}{n^2}\sum_i \phi_i^2 (divisor nn) with ϕi=nw1Ti(Yi−μ^1)ei−nw0(1−Ti)(Yi−μ^0)1−ei\phi_i = \frac{n}{w_1}\frac{T_i(Y_i - \hat\mu_1)}{e_i} - \frac{n}{w_0}\frac{(1 - T_i)(Y_i - \hat\mu_0)}{1 - e_i}, where μ^1=a1/w1\hat\mu_1 = a_1/w_1 and μ^0=a0/w0\hat\mu_0 = a_0/w_0. The interval τ^±z1−α/2v\hat\tau \pm z_{1 - \alpha/2}\sqrt{v} is a normal confidence interval of approximate level 1−α1 - \alpha. Both variance estimates treat ee as known; with an estimated propensity they are approximations (see the pitfalls).

Example

Eight patients have a stratum xx (0 for mild, 1 for severe), a treatment and an outcome. The design treated mild patients with probability 1/41/4 and severe patients with probability 3/43/4.

unit 1 2 3 4 5 6 7 8
xx 0 0 0 0 0 1 1 1
TT 1 1 0 0 0 1 1 0
YY 8 7 6 5 7 4 3 1
ee 1/4 1/4 1/4 1/4 1/4 3/4 3/4 3/4
weight 4 4 4/3 4/3 4/3 4/3 4/3 4

The naive difference of means is (8+7+4+3)/4−(6+5+7+1)/4=5.5−4.75=3/4(8 + 7 + 4 + 3)/4 - (6 + 5 + 7 + 1)/4 = 5.5 - 4.75 = 3/4. It compares a treated group that is half severe with a control group that is one quarter severe.

Lines L4 and L5 give a1=4⋅8+4⋅7+43⋅4+43⋅3=208/3a_1 = 4 \cdot 8 + 4 \cdot 7 + \tfrac43 \cdot 4 + \tfrac43 \cdot 3 = 208/3, w1=32/3w_1 = 32/3, a0=43(6+5+7)+4⋅1=28a_0 = \tfrac43(6 + 5 + 7) + 4 \cdot 1 = 28 and w0=8w_0 = 8. Line L6 gives τ^HT=(208/3−28)/8=26/3−7/2=31/6≈5.17\hat\tau_{\mathrm{HT}} = (208/3 - 28)/8 = 26/3 - 7/2 = 31/6 \approx 5.17. Line L7 gives τ^H=13/2−7/2=3\hat\tau_{\mathrm{H}} = 13/2 - 7/2 = 3. The two forms disagree because w1=32/3w_1 = 32/3 is not n=8n = 8: in this sample the treated weights add up to more than the sample, and the Horvitz-Thompson treated mean 26/326/3 is larger than every treated outcome.

With the empirical propensities instead, e^=2/5\hat e = 2/5 in the mild stratum (2 of 5 treated) and e^=2/3\hat e = 2/3 in the severe stratum (2 of 3), and both forms give 15/815/8. That is the stratified estimate: the mild stratum has mean difference 7.5−6=1.57.5 - 6 = 1.5, the severe stratum 3.5−1=2.53.5 - 1 = 2.5, and 58⋅1.5+38⋅2.5=15/8\tfrac58 \cdot 1.5 + \tfrac38 \cdot 2.5 = 15/8. The proofs show that this agreement is exact for every discrete XX.

The example has no known true effect; it shows the arithmetic. The tests check the general claims by exact enumeration.

Correctness

The proofs below establish, in exact arithmetic:

  • the loops compute the two formulas;
  • design-based unbiasedness: for fixed potential outcomes and any random assignment with known πi=Pr⁡[Ti=1]\pi_i = \Pr[T_i = 1] strictly between 0 and 1, E[τ^HT]\mathbb{E}[\hat\tau_{\mathrm{HT}}] equals the sample average treatment effect 1n∑i(Yi(1)−Yi(0))\frac1n\sum_i (Y_i(1) - Y_i(0)); for independent assignment the variance has a closed form;
  • identification and unbiasedness in the superpopulation: under consistency, ignorability and positivity, E[TY/e(X)]=E[Y(1)]\mathbb{E}[TY/e(X)] = \mathbb{E}[Y(1)] and E[(1−T)Y/(1−e(X))]=E[Y(0)]\mathbb{E}[(1 - T)Y/(1 - e(X))] = \mathbb{E}[Y(0)], so E[τ^HT]=τ\mathbb{E}[\hat\tau_{\mathrm{HT}}] = \tau, and vHTv_{\mathrm{HT}} is unbiased for its variance;
  • the Hájek form is consistent, by the law of large numbers;
  • under complete randomization both forms equal the difference in means;
  • with a discrete XX and the empirical propensities, both forms equal the stratified estimate, and the ATT form equals the stratified ATT.

The coverage of the normal intervals, the bias of the Hájek form in finite samples, and the behaviour with estimated propensities from a model are not proved here; the numbers on this page about them are measured by simulation.

Proof: The IPW estimates are unbiased with known propensities and equal the stratified estimate with empirical onesfull

Unit ii has treatment Ti∈{0,1}T_i \in \{0, 1\}, outcome YiY_i and propensity eie_i with 0<ei<10 < e_i < 1. Write ψi=TiYi/ei−(1−Ti)Yi/(1−ei)\psi_i = T_iY_i/e_i - (1 - T_i)Y_i/(1 - e_i). All arithmetic is exact.

Lemma 1 (the loops). IPW-ATE returns τ^HT=1n∑iψi\hat\tau_{\mathrm{HT}} = \frac1n\sum_i \psi_i and τ^H=a1/w1−a0/w0\hat\tau_{\mathrm{H}} = a_1/w_1 - a_0/w_0, with a1=∑iTiYi/eia_1 = \sum_i T_iY_i/e_i, w1=∑iTi/eiw_1 = \sum_i T_i/e_i, a0=∑i(1−Ti)Yi/(1−ei)a_0 = \sum_i (1 - T_i)Y_i/(1 - e_i) and w0=∑i(1−Ti)/(1−ei)w_0 = \sum_i (1 - T_i)/(1 - e_i).

Proof. Line L1 sets the four sums to 0. The loop L2 visits each unit once. Line L3 does not change the sums. For a treated unit, line L4 adds Yi/eiY_i/e_i to a1a_1 and 1/ei1/e_i to w1w_1, which are the terms TiYi/eiT_iY_i/e_i and Ti/eiT_i/e_i; the terms of a0a_0 and w0w_0 are 0 for this unit, and line L5 does not run. For a control the roles swap. So after the loop the four sums have the stated values. Line L6 returns (a1−a0)/n=1n∑iψi(a_1 - a_0)/n = \frac1n\sum_i\psi_i, and line L7 returns a1/w1−a0/w0a_1/w_1 - a_0/w_0. □\square

Design-based results

Here the potential outcomes Yi(1),Yi(0)Y_i(1), Y_i(0) of nn units are fixed numbers, and only the assignment vector (T1,…,Tn)(T_1, \ldots, T_n) is random, with a known distribution (the design). Let πi=Pr⁡[Ti=1]\pi_i = \Pr[T_i = 1], and assume 0<πi<10 < \pi_i < 1 for all ii. The observed outcome is Yi=TiYi(1)+(1−Ti)Yi(0)Y_i = T_iY_i(1) + (1 - T_i)Y_i(0) (consistency). The sample average treatment effect is τS=1n∑i(Yi(1)−Yi(0))\tau_S = \frac1n\sum_i (Y_i(1) - Y_i(0)).

Theorem 2 (unbiased for any design). With ei=πie_i = \pi_i, E[τ^HT]=τS\mathbb{E}[\hat\tau_{\mathrm{HT}}] = \tau_S.

Proof. Since Ti(1−Ti)=0T_i(1 - T_i) = 0, consistency gives TiYi=TiYi(1)T_iY_i = T_iY_i(1) and (1−Ti)Yi=(1−Ti)Yi(0)(1 - T_i)Y_i = (1 - T_i)Y_i(0). So ψi=TiYi(1)/πi−(1−Ti)Yi(0)/(1−πi)\psi_i = T_iY_i(1)/\pi_i - (1 - T_i)Y_i(0)/(1 - \pi_i), in which only TiT_i is random. With E[Ti]=πi\mathbb{E}[T_i] = \pi_i, E[ψi]=Yi(1)−Yi(0)\mathbb{E}[\psi_i] = Y_i(1) - Y_i(0). By linearity of expectation and Lemma 1, E[τ^HT]=1n∑i(Yi(1)−Yi(0))=τS\mathbb{E}[\hat\tau_{\mathrm{HT}}] = \frac1n\sum_i (Y_i(1) - Y_i(0)) = \tau_S. The proof uses only the marginal probabilities πi\pi_i, so it holds for every joint distribution of the assignment. □\square

Theorem 3 (variance under independent assignment). If the TiT_i are independent, then

Var⁡[τ^HT]=1n2∑i=1n(1−πiπiYi(1)2+πi1−πiYi(0)2+2Yi(1)Yi(0)).\operatorname{Var}[\hat\tau_{\mathrm{HT}}] = \frac{1}{n^2}\sum_{i=1}^n\left(\frac{1 - \pi_i}{\pi_i}Y_i(1)^2 + \frac{\pi_i}{1 - \pi_i}Y_i(0)^2 + 2Y_i(1)Y_i(0)\right).

Proof. The ψi\psi_i are independent, so Var⁡[τ^HT]=1n2∑iVar⁡[ψi]\operatorname{Var}[\hat\tau_{\mathrm{HT}}] = \frac{1}{n^2}\sum_i\operatorname{Var}[\psi_i]. Write a=Yi(1)a = Y_i(1), b=Yi(0)b = Y_i(0) and π=πi\pi = \pi_i. The variable ψi\psi_i is a/πa/\pi with probability π\pi and −b/(1−π)-b/(1 - \pi) with probability 1−π1 - \pi, so E[ψi2]=a2/π+b2/(1−π)\mathbb{E}[\psi_i^2] = a^2/\pi + b^2/(1 - \pi) and E[ψi]=a−b\mathbb{E}[\psi_i] = a - b. Then

Var⁡[ψi]=a2π+b21−π−a2+2ab−b2=1−ππa2+π1−πb2+2ab.□\operatorname{Var}[\psi_i] = \frac{a^2}{\pi} + \frac{b^2}{1 - \pi} - a^2 + 2ab - b^2 = \frac{1 - \pi}{\pi}a^2 + \frac{\pi}{1 - \pi}b^2 + 2ab. \qquad\square

Theorem 4 (complete randomization). If every assignment with P[T]>0P[T] > 0 treats exactly n1n_1 units, with 0<n1<n0 < n_1 < n, and ei=n1/ne_i = n_1/n for all ii, then τ^HT=τ^H=Yˉ1−Yˉ0\hat\tau_{\mathrm{HT}} = \hat\tau_{\mathrm{H}} = \bar Y_1 - \bar Y_0, the difference of the arm means, for every such assignment.

Proof. w1=n1⋅n/n1=nw_1 = n_1 \cdot n/n_1 = n and w0=(n−n1)⋅n/(n−n1)=nw_0 = (n - n_1)\cdot n/(n - n_1) = n, so the two forms coincide. And a1/n=nn1∑Ti=1Yi/n=Yˉ1a_1/n = \frac{n}{n_1}\sum_{T_i = 1}Y_i/n = \bar Y_1, and in the same way a0/n=Yˉ0a_0/n = \bar Y_0. □\square

Under complete randomization of n1n_1 of nn units, πi=n1/n\pi_i = n_1/n, so Theorem 2 shows that the difference in means is unbiased for τS\tau_S, the result proved on the randomized experiment page.

Superpopulation results

Here the units (Xi,Ti,Yi(0),Yi(1))(X_i, T_i, Y_i(0), Y_i(1)) are independent copies of (X,T,Y(0),Y(1))(X, T, Y(0), Y(1)), with e(x)=Pr⁡[T=1∣X=x]e(x) = \Pr[T = 1 \mid X = x], ei=e(Xi)e_i = e(X_i) and E∣Y(t)∣<∞\mathbb{E}|Y(t)| < \infty for t=0,1t = 0, 1. Assume consistency Y=TY(1)+(1−T)Y(0)Y = TY(1) + (1 - T)Y(0), ignorability (Y(0),Y(1))⊥T∣X(Y(0), Y(1)) \perp T \mid X, and positivity 0<e(X)<10 < e(X) < 1 with probability 1.

Theorem 5 (identification). E[TY/e(X)]=E[Y(1)]\mathbb{E}[TY/e(X)] = \mathbb{E}[Y(1)] and E[(1−T)Y/(1−e(X))]=E[Y(0)]\mathbb{E}[(1 - T)Y/(1 - e(X))] = \mathbb{E}[Y(0)]. Hence E[τ^HT]=τ=E[Y(1)−Y(0)]\mathbb{E}[\hat\tau_{\mathrm{HT}}] = \tau = \mathbb{E}[Y(1) - Y(0)].

Proof. By consistency TY=TY(1)TY = TY(1). Ignorability gives T⊥Y(1)∣XT \perp Y(1) \mid X, so E[T ∣Y(1)∣∣X]=E[T∣X] E[∣Y(1)∣∣X]=e(X) E[∣Y(1)∣∣X]\mathbb{E}[T\,|Y(1)| \mid X] = \mathbb{E}[T \mid X]\,\mathbb{E}[|Y(1)| \mid X] = e(X)\,\mathbb{E}[|Y(1)| \mid X]. Since 1/e(X)1/e(X) is a function of XX, by the tower property of conditional expectation, E[T∣Y(1)∣/e(X)]=E[E[∣Y(1)∣∣X]]=E∣Y(1)∣<∞\mathbb{E}[T|Y(1)|/e(X)] = \mathbb{E}[\mathbb{E}[|Y(1)| \mid X]] = \mathbb{E}|Y(1)| < \infty, so TY/e(X)TY/e(X) is integrable. The same steps without absolute values give

E[TY(1)e(X)]=E[E[T∣X] E[Y(1)∣X]e(X)]=E[E[Y(1)∣X]]=E[Y(1)].\mathbb{E}\left[\frac{TY(1)}{e(X)}\right] = \mathbb{E}\left[\frac{\mathbb{E}[T \mid X]\,\mathbb{E}[Y(1) \mid X]}{e(X)}\right] = \mathbb{E}\big[\mathbb{E}[Y(1) \mid X]\big] = \mathbb{E}[Y(1)].

Positivity makes the division by e(X)e(X) valid with probability 1. The control arm is the same with 1−T1 - T, Y(0)Y(0) and 1−e(X)1 - e(X). So E[ψi]=τ\mathbb{E}[\psi_i] = \tau for each ii, and E[τ^HT]=τ\mathbb{E}[\hat\tau_{\mathrm{HT}}] = \tau by linearity. □\square

Theorem 6 (unbiased variance estimate). If also E[ψ2]<∞\mathbb{E}[\psi^2] < \infty, then Var⁡[τ^HT]=Var⁡[ψ]/n\operatorname{Var}[\hat\tau_{\mathrm{HT}}] = \operatorname{Var}[\psi]/n, and vHT=Sψ2/nv_{\mathrm{HT}} = S_\psi^2/n, with Sψ2S_\psi^2 the sample variance of ψ1,…,ψn\psi_1, \ldots, \psi_n with divisor n−1n - 1 (n≥2n \ge 2), satisfies E[vHT]=Var⁡[τ^HT]\mathbb{E}[v_{\mathrm{HT}}] = \operatorname{Var}[\hat\tau_{\mathrm{HT}}].

Proof. The ψi\psi_i are independent and identically distributed, since each is the same function of one unit's data. The variance of their mean is Var⁡[ψ]/n\operatorname{Var}[\psi]/n, and the sample variance with divisor n−1n - 1 is unbiased for Var⁡[ψ]\operatorname{Var}[\psi]. □\square

Theorem 7 (the Hájek form is consistent). τ^H→τ\hat\tau_{\mathrm{H}} \to \tau with probability 1 as n→∞n \to \infty.

Proof. By Theorem 5 with YY replaced by the constant 1, E[T/e(X)]=1\mathbb{E}[T/e(X)] = 1. By the strong law of large numbers, a1/n→E[Y(1)]a_1/n \to \mathbb{E}[Y(1)] and w1/n→1w_1/n \to 1 with probability 1, so a1/w1=(a1/n)/(w1/n)→E[Y(1)]a_1/w_1 = (a_1/n)/(w_1/n) \to \mathbb{E}[Y(1)]. In the same way a0/w0→E[Y(0)]a_0/w_0 \to \mathbb{E}[Y(0)]. For all large nn, w1>0w_1 > 0 and w0>0w_0 > 0, so line L7 is defined. □\square

Theorem 7 is a limit statement. It gives no bound on the bias of τ^H\hat\tau_{\mathrm{H}} at a fixed nn, and the coverage of the normal intervals is not proved here.

Empirical propensities with a discrete covariate

Theorem 8 (equal to the stratified estimate). Let XX take finitely many values. For each value xx, let nxn_x be the number of units with Xi=xX_i = x, n1xn_{1x} the number of those treated, n0x=nx−n1xn_{0x} = n_x - n_{1x}, and Yˉ1x\bar Y_{1x} and Yˉ0x\bar Y_{0x} the mean outcomes of the treated and the controls with Xi=xX_i = x. Assume 0<n1x<nx0 < n_{1x} < n_x for every xx that occurs. With e^i=n1x/nx\hat e_i = n_{1x}/n_x for each unit with Xi=xX_i = x,

τ^HT=τ^H=∑xnxn(Yˉ1x−Yˉ0x).\hat\tau_{\mathrm{HT}} = \hat\tau_{\mathrm{H}} = \sum_x \frac{n_x}{n}\left(\bar Y_{1x} - \bar Y_{0x}\right).

The ATT form Yˉtreated−∑Ti=0e^i1−e^iYi/∑Ti=0e^i1−e^i\bar Y_{\text{treated}} - \sum_{T_i = 0}\frac{\hat e_i}{1 - \hat e_i}Y_i \big/ \sum_{T_i = 0}\frac{\hat e_i}{1 - \hat e_i} equals ∑xn1xn1(Yˉ1x−Yˉ0x)\sum_x \frac{n_{1x}}{n_1}(\bar Y_{1x} - \bar Y_{0x}), where n1=∑xn1xn_1 = \sum_x n_{1x}.

Proof. The assumption gives 0<e^i<10 < \hat e_i < 1. Group the sums by the value of XX. The treated units with Xi=xX_i = x contribute nxn1x∑Yi=nxYˉ1x\frac{n_x}{n_{1x}}\sum Y_i = n_x\bar Y_{1x} to a1a_1 and n1x⋅nxn1x=nxn_{1x}\cdot\frac{n_x}{n_{1x}} = n_x to w1w_1. So a1=∑xnxYˉ1xa_1 = \sum_x n_x\bar Y_{1x} and w1=∑xnx=nw_1 = \sum_x n_x = n. In the same way, 1/(1−e^i)=nx/n0x1/(1 - \hat e_i) = n_x/n_{0x} gives a0=∑xnxYˉ0xa_0 = \sum_x n_x\bar Y_{0x} and w0=nw_0 = n. Since w1=w0=nw_1 = w_0 = n, the two forms agree, and both equal 1n∑xnx(Yˉ1x−Yˉ0x)\frac1n\sum_x n_x(\bar Y_{1x} - \bar Y_{0x}).

For the ATT, a control with Xi=xX_i = x has weight e^i/(1−e^i)=n1x/n0x\hat e_i/(1 - \hat e_i) = n_{1x}/n_{0x}. The controls with Xi=xX_i = x contribute n1xYˉ0xn_{1x}\bar Y_{0x} to the weighted sum and n1xn_{1x} to the sum of weights, so the control term is ∑xn1xYˉ0x/n1\sum_x n_{1x}\bar Y_{0x}/n_1. The treated mean is ∑xn1xYˉ1x/n1\sum_x n_{1x}\bar Y_{1x}/n_1. Their difference is the stated sum. □\square

Cost. The loop L2 to L5 runs nn times and does a constant number of comparisons, divisions and additions per pass; lines L6 to L8 take constant time. So the time is Θ(n)\Theta(n) in every case, and the extra space is the four sums, Θ(1)\Theta(1). The loop is over a finite range, so the procedure terminates. ■\blacksquare

Complexity

Each pass of the loop L2 to L5 does a comparison and two divisions and two additions, so the estimate takes Θ(n)\Theta(n) time in both the best and the worst case, and Θ(1)\Theta(1) extra space for the four sums. The estimate can run on a stream. The variance estimates take a second pass, because ψi\psi_i and ϕi\phi_i use the estimate; a single pass with running sums of ψi\psi_i and ψi2\psi_i^2 also works for vHTv_{\mathrm{HT}}, at some cost in rounding error. Estimating the propensity, for example by logistic regression, is a separate cost and usually the larger one.

Properties

  • Unbiased with known propensities. The Horvitz-Thompson form is unbiased for the ATE under ignorability and positivity, and for the sample ATE in a randomized design with known, unequal assignment chances. No model for the outcome is needed.
  • The Hájek form stays in range. μ^1=a1/w1\hat\mu_1 = a_1/w_1 is a weighted average of the treated outcomes, so it lies between their minimum and maximum. The Horvitz-Thompson mean a1/na_1/n need not: in the example it is 26/326/3, above the largest treated outcome 8.
  • Shift equivariance. Adding a constant cc to every outcome adds 0 to τ^H\hat\tau_{\mathrm{H}} but adds c(w1−w0)/nc(w_1 - w_0)/n to τ^HT\hat\tau_{\mathrm{HT}}. In the example, adding 3 to every outcome raises τ^HT\hat\tau_{\mathrm{HT}} by 3⋅(32/3−8)/8=13 \cdot (32/3 - 8)/8 = 1.
  • Complete randomization. If ei=n1/ne_i = n_1/n for every unit, then w1=w0=nw_1 = w_0 = n, and both forms are the difference in means of the randomized experiment.
  • Stratification. With a discrete XX and e^(x)\hat e(x) the treated share of stratum xx, both forms equal ∑xnxn(Yˉ1x−Yˉ0x)\sum_x \frac{n_x}{n}(\bar Y_{1x} - \bar Y_{0x}), the stratified estimate, as in the example. The tests check this exactly on 500 random tables.
  • Large weights. The variance of ψi\psi_i contains E[Y(1)2/e(X)]+E[Y(0)2/(1−e(X))]\mathbb{E}[Y(1)^2/e(X)] + \mathbb{E}[Y(0)^2/(1 - e(X))], which grows without bound as ee approaches 0 or 1, even when positivity holds.

Variants and improvements

  • Weighting for the effect on the treated. The ATT E[Y(1)−Y(0)∣T=1]\mathbb{E}[Y(1) - Y(0) \mid T = 1] keeps the treated units with weight 1 and gives each control weight ei/(1−ei)e_i/(1 - e_i), which turns the control group into a copy of the treated group's covariate mix. The Hájek form is Yˉtreated−∑Ti=0ei1−eiYi/∑Ti=0ei1−ei\bar Y_{\text{treated}} - \sum_{T_i = 0} \frac{e_i}{1 - e_i}Y_i \big/ \sum_{T_i = 0}\frac{e_i}{1 - e_i}. It needs only e(X)<1e(X) < 1, not e(X)>0e(X) > 0.
  • Stabilized weights. Multiplying the treated weights by Pr⁡[T=1]\Pr[T = 1] and the control weights by Pr⁡[T=0]\Pr[T = 0] keeps the weights near 1 on average. In a weighted regression of YY on TT this does not change the estimate, which is the Hájek form; it matters in models with more terms, such as marginal structural models.
  • Trimming. Crump, Hotz, Imbens and Mitnik (2009) drop units whose estimated propensity is outside [β,1−β][\beta, 1 - \beta], with β\beta chosen from the data and often near 0.1. The estimand changes to the ATE of the units that remain, and the report must say so.
  • Estimated propensities. Hirano, Imbens and Ridder (2003) show that weighting by a suitably flexible nonparametric estimate of ee gives an estimator with the smallest possible asymptotic variance among regular estimators of the ATE, smaller than weighting by the true ee.
  • Doubly robust estimators. Augmented IPW adds an outcome regression and stays consistent if either the propensity model or the outcome model is right. TMLE and double machine learning build on the same estimating function.
  • Other uses of the weight. The same weight appears in importance sampling, in off-policy evaluation of a new policy from logged actions, and in analysis of data missing at random (see missing-data mechanisms).

When to use it

Use IPW when the treatment chances are known from the design, or can be estimated well from measured covariates, and ignorability is credible. It gives one effect estimate for the whole population without a model for the outcome, and it extends to time-varying treatments where regression adjustment fails. Prefer the Hájek form in practice. Check overlap first: if many units have estimated propensities near 0 or 1, the weights are unstable, and propensity score matching for the ATT, trimming, or a doubly robust method is a better choice. When ignorability is in doubt, follow the estimate with a sensitivity analysis.

Pitfalls

  • Weights near the positivity limit. In a simulation with XX uniform on [0,1][0, 1], e(x)=β+(1−2β)xe(x) = \beta + (1 - 2\beta)x, effect 0.5+x0.5 + x (true ATE 1), n=200n = 200 and 2000 repetitions (seed 2026), β=0.2\beta = 0.2 gave a standard deviation of 0.278 for the Horvitz-Thompson form and 0.191 for the Hájek form, with interval coverage 0.953 and 0.946. With β=0.01\beta = 0.01 the standard deviations rose to 0.367 and 0.277, the Hájek mean was 1.046 instead of 1, and its 95% interval covered only 0.90 of the time. These numbers are measured, not proved.
  • Estimated propensities treated as known. Plugging e^\hat e into vHTv_{\mathrm{HT}} or vHv_{\mathrm{H}} ignores the estimation step. For the ATE with a correctly specified parametric model fitted by maximum likelihood, Lunceford and Davidian (2004) show that this overstates the variance. In a simulation with 3 strata (e=0.2,0.5,0.8e = 0.2, 0.5, 0.8), n=300n = 300, empirical propensities and 2000 repetitions (seed 77), the nominal 95% Hájek interval covered 0.998 of the time. For the ATT the plug-in variance is not always conservative.
  • A wrong propensity model. IPW is unbiased only with the right ee. A logistic model with missing terms leaves imbalance in XX. Check balance: compare the weighted means of each covariate in the two arms, as the propensity score page explains.
  • Good prediction is not the goal. A covariate that predicts TT but not YY, such as an instrument, makes the weights more extreme and adds variance, and it can amplify the bias from an unmeasured confounder. Choose XX for confounding, not for the fit of the treatment model.
  • Weighting cannot fix unmeasured confounding. If ignorability fails, the weighted arms still differ in the unmeasured variable, and the estimate is biased by an amount the data cannot reveal.
  • The Horvitz-Thompson form out of range. The treated mean a1/na_1/n can lie above every treated outcome, as in the example, and for a binary outcome it can be above 1. Use the Hájek form, or report both.
  • Mixing estimands. Weights 1/e1/e and 1/(1−e)1/(1 - e) target the ATE, weights 11 and e/(1−e)e/(1 - e) target the ATT, and trimmed weights target a subpopulation. State which one the analysis reports.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

inverse_probability_weighting.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/inverse-probability-weighting/. The authors are listed in prov/GVS3R2.jsonl.

"""Inverse probability weighting estimates of the average treatment effect.

Unit i has a treatment t[i] in {0, 1}, an outcome y[i] and a propensity e[i],
the probability that unit i is treated given its covariates. The propensities
are inputs: known from the design, or estimated beforehand (for example by
empirical_propensity for a discrete covariate, or by a logistic regression).
With Fraction or int inputs every result except the interval is exact.
"""

import math
from collections.abc import Hashable, Sequence
from statistics import NormalDist
from typing import NamedTuple


class IPWEstimate(NamedTuple):
    ht: object  # the Horvitz-Thompson form (a1 - a0) / n
    hajek: object  # the normalized (Hajek) form a1 / w1 - a0 / w0
    mu1_ht: object
    mu0_ht: object
    mu1_hajek: object
    mu0_hajek: object


def _check(t: Sequence, y: Sequence, e: Sequence) -> None:
    if not (len(t) == len(y) == len(e)):
        raise ValueError("t, y and e must have the same length")
    if len(t) == 0:
        raise ValueError("no units")
    for ti in t:
        if ti not in (0, 1):
            raise ValueError("every treatment must be 0 or 1")


def ipw_ate(t: Sequence[int], y: Sequence, e: Sequence) -> IPWEstimate:
    """Horvitz-Thompson and Hajek IPW estimates of the ATE. Cost: Theta(n) time, O(1) extra space.

    Precondition: 0 < e[i] < 1 for every unit (positivity). The Hajek form also
    needs at least one treated and one control unit; if an arm is empty its
    Hajek mean is None.
    """
    _check(t, y, e)
    n = len(t)
    a1 = a0 = w1 = w0 = 0  # @line L1
    for ti, yi, ei in zip(t, y, e):  # @line L2
        if ei <= 0 or ei >= 1:  # @line L3
            raise ValueError(f"positivity fails: propensity {ei!r} is not strictly between 0 and 1")
        if ti == 1:  # @line L4
            a1 = a1 + yi / ei
            w1 = w1 + 1 / ei
        else:  # @line L5
            a0 = a0 + yi / (1 - ei)
            w0 = w0 + 1 / (1 - ei)
    mu1_ht, mu0_ht = a1 / n, a0 / n
    tau_ht = (a1 - a0) / n  # @line L6
    mu1_h = a1 / w1 if w1 else None
    mu0_h = a0 / w0 if w0 else None
    tau_h = mu1_h - mu0_h if w1 and w0 else None  # @line L7
    return IPWEstimate(tau_ht, tau_h, mu1_ht, mu0_ht, mu1_h, mu0_h)  # @line L8


def ipw_variance(t: Sequence[int], y: Sequence, e: Sequence) -> tuple:
    """Variance estimates of the two IPW estimates, treating e as known. Cost: Theta(n).

    Returns (v_ht, v_hajek). v_ht is S^2 / n, where S^2 is the sample variance
    (divisor n - 1) of psi_i = t y / e - (1 - t) y / (1 - e); it is unbiased for
    the variance of the HT estimate over iid units with known e. v_hajek is the
    sandwich estimate (divisor n) of the M-estimator that defines the Hajek form.
    With estimated propensities both are approximations (see the page).
    """
    est = ipw_ate(t, y, e)
    n = len(t)
    if n < 2:
        raise ValueError("need at least two units")
    psi = [ti * yi / ei - (1 - ti) * yi / (1 - ei) for ti, yi, ei in zip(t, y, e)]
    v_ht = sum((p - est.ht) ** 2 for p in psi) / ((n - 1) * n)
    if est.hajek is None:
        return v_ht, None
    w1 = sum(ti / ei for ti, ei in zip(t, e))
    w0 = sum((1 - ti) / (1 - ei) for ti, ei in zip(t, e))
    phi = [ti * (yi - est.mu1_hajek) / ei * n / w1 - (1 - ti) * (yi - est.mu0_hajek) / (1 - ei) * n / w0
           for ti, yi, ei in zip(t, y, e)]
    v_h = sum(f * f for f in phi) / (n * n)
    return v_ht, v_h


def ipw_interval(t: Sequence[int], y: Sequence, e: Sequence, alpha: float = 0.05, form: str = "hajek") -> tuple:
    """Normal (Wald) interval tau-hat -/+ z_(1 - alpha/2) sqrt(v). Asymptotic coverage only."""
    est = ipw_ate(t, y, e)
    v_ht, v_h = ipw_variance(t, y, e)
    tau, v = (est.ht, v_ht) if form == "ht" else (est.hajek, v_h)
    if tau is None:
        raise ValueError("an arm is empty")
    z = NormalDist().inv_cdf(1 - alpha / 2)
    half = z * math.sqrt(float(v))
    return float(tau) - half, float(tau) + half


def ipw_att(t: Sequence[int], y: Sequence, e: Sequence):
    """Hajek IPW estimate of the ATT: treated mean minus the control mean weighted by e / (1 - e).

    Needs e[i] < 1 for the controls and at least one unit in each arm. Cost: Theta(n).
    """
    _check(t, y, e)
    s1 = n1 = s0 = w0 = 0
    for ti, yi, ei in zip(t, y, e):
        if ti == 1:
            s1, n1 = s1 + yi, n1 + 1
        else:
            if ei <= 0 or ei >= 1:
                raise ValueError(f"positivity fails: propensity {ei!r} is not strictly between 0 and 1")
            w = ei / (1 - ei)
            s0, w0 = s0 + w * yi, w0 + w
    if n1 == 0 or w0 == 0:
        raise ValueError("an arm is empty")
    return s1 / n1 - s0 / w0


def empirical_propensity(x: Sequence[Hashable], t: Sequence[int]) -> list:
    """For a discrete covariate, e-hat(x) = (treated with value x) / (units with value x), as Fractions.

    Cost: Theta(n) expected with hashing. Values can be 0 or 1 when a stratum has
    only one arm; ipw_ate then reports the failure of positivity.
    """
    from fractions import Fraction

    tot: dict = {}
    tr: dict = {}
    for xi, ti in zip(x, t):
        tot[xi] = tot.get(xi, 0) + 1
        tr[xi] = tr.get(xi, 0) + ti
    return [Fraction(tr[xi], tot[xi]) for xi in x]
test_inverse_probability_weighting.py 209 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/inverse-probability-weighting/. The authors are listed in prov/GVS3R2.jsonl.

import itertools
import math
import random
from fractions import Fraction as Fr

import pytest

from inverse_probability_weighting import empirical_propensity, ipw_ate, ipw_att, ipw_interval, ipw_variance

# The worked example of the page: x is the stratum, e the known design propensity.
EX_X = [0, 0, 0, 0, 0, 1, 1, 1]
EX_T = [1, 1, 0, 0, 0, 1, 1, 0]
EX_Y = [8, 7, 6, 5, 7, 4, 3, 1]
EX_E = [Fr(1, 4)] * 5 + [Fr(3, 4)] * 3


def stratified(x, t, y, weight="all"):
    """Oracle: the subclassification estimate, sum over strata of (share) times (mean difference)."""
    out, total = Fr(0), 0
    for v in sorted(set(x)):
        idx = [i for i in range(len(x)) if x[i] == v]
        tr = [y[i] for i in idx if t[i] == 1]
        co = [y[i] for i in idx if t[i] == 0]
        size = len(idx) if weight == "all" else len(tr)
        out += size * (Fr(sum(tr), len(tr)) - Fr(sum(co), len(co)))
        total += size
    return out / total


def test_worked_example():
    est = ipw_ate(EX_T, EX_Y, EX_E)
    assert est.mu1_ht == Fr(26, 3) and est.mu0_ht == Fr(7, 2)
    assert est.ht == Fr(31, 6)
    assert est.mu1_hajek == Fr(13, 2) and est.mu0_hajek == Fr(7, 2)
    assert est.hajek == 3
    eh = empirical_propensity(EX_X, EX_T)
    assert eh == [Fr(2, 5)] * 5 + [Fr(2, 3)] * 3
    emp = ipw_ate(EX_T, EX_Y, eh)
    assert emp.ht == emp.hajek == Fr(15, 8) == stratified(EX_X, EX_T, EX_Y)
    assert ipw_att(EX_T, EX_Y, eh) == 2 == stratified(EX_X, EX_T, EX_Y, "treated")
    # the naive difference of means
    assert Fr(8 + 7 + 4 + 3, 4) - Fr(6 + 5 + 7 + 1, 4) == Fr(3, 4)


def test_positivity_and_shape_errors():
    with pytest.raises(ValueError):
        ipw_ate([1, 0], [1, 2], [Fr(1, 2), 1])
    with pytest.raises(ValueError):
        ipw_ate([1, 0], [1, 2], [0, Fr(1, 2)])
    with pytest.raises(ValueError):
        ipw_ate([1, 2], [1, 2], [Fr(1, 2), Fr(1, 2)])
    with pytest.raises(ValueError):
        ipw_ate([], [], [])
    with pytest.raises(ValueError):
        ipw_att([0, 0], [1, 2], [Fr(1, 2), Fr(1, 2)])
    one_arm = ipw_ate([1, 1], [3, 5], [Fr(1, 2), Fr(1, 4)])
    assert one_arm.hajek is None and one_arm.ht == Fr(3 * 2 + 5 * 4, 2)


def bernoulli_design(pi):
    """Every assignment vector with its probability under independent Bernoulli(pi_i) assignment."""
    for t in itertools.product((0, 1), repeat=len(pi)):
        p = Fr(1)
        for ti, q in zip(t, pi):
            p *= q if ti else 1 - q
        yield t, p


def test_ht_unbiased_and_variance_exact_bernoulli():
    rng = random.Random(20261114)
    for _ in range(60):
        n = rng.randint(1, 7)
        y0 = [rng.randint(-5, 9) for _ in range(n)]
        y1 = [rng.randint(-5, 9) for _ in range(n)]
        pi = [Fr(rng.randint(1, 9), 10) for _ in range(n)]
        sate = Fr(sum(y1) - sum(y0), n)
        mean = var2 = Fr(0)
        for t, p in bernoulli_design(pi):
            y = [y1[i] if t[i] else y0[i] for i in range(n)]
            tau = ipw_ate(t, y, pi).ht
            mean += p * tau
            var2 += p * tau * tau
        assert mean == sate
        var = var2 - mean * mean
        closed = sum(a * a * (1 - q) / q + b * b * q / (1 - q) + 2 * a * b for a, b, q in zip(y1, y0, pi)) / (n * n)
        assert var == closed


def test_complete_randomization_forms_agree_and_unbiased():
    rng = random.Random(7)
    for _ in range(40):
        n = rng.randint(2, 8)
        n1 = rng.randint(1, n - 1)
        y0 = [Fr(rng.randint(0, 20), 2) for _ in range(n)]
        y1 = [Fr(rng.randint(0, 20), 2) for _ in range(n)]
        e = [Fr(n1, n)] * n
        total, count = Fr(0), 0
        for treated in itertools.combinations(range(n), n1):
            t = [1 if i in treated else 0 for i in range(n)]
            y = [y1[i] if t[i] else y0[i] for i in range(n)]
            est = ipw_ate(t, y, e)
            dm = sum(y1[i] for i in treated) / n1 - sum(y0[i] for i in range(n) if i not in treated) / (n - n1)
            assert est.ht == est.hajek == dm
            total += est.ht
            count += 1
        assert total / count == (sum(y1) - sum(y0)) / n


def test_unequal_marginals_fixed_size_design_unbiased():
    """A design that is not Bernoulli: draw the treated set from a list of sets with given probabilities."""
    rng = random.Random(99)
    for _ in range(40):
        n = rng.randint(3, 6)
        sets = [s for k in range(1, n) for s in itertools.combinations(range(n), k)]
        w = [rng.randint(1, 5) for _ in sets]
        design = {s: Fr(wi, sum(w)) for s, wi in zip(sets, w)}
        pi = [sum((p for s, p in design.items() if i in s), Fr(0)) for i in range(n)]
        if any(q in (0, 1) for q in pi):
            continue
        y0 = [rng.randint(0, 9) for _ in range(n)]
        y1 = [rng.randint(0, 9) for _ in range(n)]
        mean = Fr(0)
        for s, p in design.items():
            t = [1 if i in s else 0 for i in range(n)]
            y = [y1[i] if t[i] else y0[i] for i in range(n)]
            mean += p * ipw_ate(t, y, pi).ht
        assert mean == Fr(sum(y1) - sum(y0), n)


def test_discrete_x_empirical_propensity_equals_stratified():
    rng = random.Random(31)
    done = 0
    while done < 500:
        n = rng.randint(4, 30)
        k = rng.randint(1, 4)
        x = [rng.randrange(k) for _ in range(n)]
        t = [rng.randint(0, 1) for _ in range(n)]
        if any(len({t[i] for i in range(n) if x[i] == v}) < 2 for v in set(x)):
            continue
        y = [Fr(rng.randint(-40, 40), rng.randint(1, 4)) for _ in range(n)]
        eh = empirical_propensity(x, t)
        est = ipw_ate(t, y, eh)
        s = stratified(x, t, y)
        assert est.ht == s and est.hajek == s
        assert ipw_att(t, y, eh) == stratified(x, t, y, "treated")
        done += 1


def test_variance_ht_is_sample_variance_of_psi():
    t, y, e = EX_T, EX_Y, EX_E
    psi = [Fr(ti * yi) / ei - Fr((1 - ti) * yi) / (1 - ei) for ti, yi, ei in zip(t, y, e)]
    m = sum(psi) / len(psi)
    s2 = sum((p - m) ** 2 for p in psi) / (len(psi) - 1)
    v_ht, v_h = ipw_variance(t, y, e)
    assert v_ht == s2 / len(psi)
    assert v_h > 0


def simulate(rng, n):
    """A superpopulation with a known propensity; the true ATE is 1."""
    t, y, e = [], [], []
    for _ in range(n):
        x = rng.random()
        ei = 0.2 + 0.6 * x
        ti = 1 if rng.random() < ei else 0
        y0 = 2 * x + rng.gauss(0, 1)
        y1 = y0 + 0.5 + x  # effect 0.5 + x, mean 1
        t.append(ti)
        y.append(y1 if ti else y0)
        e.append(ei)
    return t, y, e


def test_monte_carlo_bias_and_coverage():
    rng = random.Random(123)
    r, n = 600, 200
    cover = {"ht": 0, "hajek": 0}
    s_ht = s_h = 0.0
    for _ in range(r):
        t, y, e = simulate(rng, n)
        est = ipw_ate(t, y, e)
        s_ht += est.ht
        s_h += est.hajek
        for form in cover:
            lo, hi = ipw_interval(t, y, e, 0.05, form)
            cover[form] += lo <= 1.0 <= hi
    # the HT form is unbiased; the Hajek form has bias of order 1/n
    assert abs(s_ht / r - 1.0) < 0.06
    assert abs(s_h / r - 1.0) < 0.06
    tol = 4 * math.sqrt(0.05 * 0.95 / r) + 0.01
    for form in cover:
        assert abs(cover[form] / r - 0.95) < tol, (form, cover[form] / r)


def test_float_inputs_match_fractions():
    rng = random.Random(5)
    for _ in range(200):
        n = rng.randint(2, 12)
        t = [rng.randint(0, 1) for _ in range(n)]
        y = [rng.randint(-9, 9) for _ in range(n)]
        e = [Fr(rng.randint(1, 19), 20) for _ in range(n)]
        a = ipw_ate(t, y, e)
        b = ipw_ate(t, [float(v) for v in y], [float(v) for v in e])
        assert math.isclose(float(a.ht), b.ht, rel_tol=1e-12, abs_tol=1e-12)
        if a.hajek is not None:
            assert math.isclose(float(a.hajek), b.hajek, rel_tol=1e-12, abs_tol=1e-12)

History

The weight 1/πi1/\pi_i comes from survey sampling, where Horvitz and Thompson (1952) proved that it makes the estimated total unbiased for any design. Rosenbaum (1987) used weighting by the inverse of an estimated propensity score, in his words model-based direct adjustment, to estimate causal effects from observational data. Robins, Rotnitzky and Zhao (1994) built a general theory of inverse probability weighted estimating equations for missing data, which also gave the augmented, doubly robust form. Hirano, Imbens and Ridder (2003) showed that weighting by an estimated propensity score can be efficient. Lunceford and Davidian (2004) compared weighting with stratification and gave sandwich variances, and Crump, Hotz, Imbens and Mitnik (2009) gave a rule for trimming units with poor overlap.

References

  1. D. G. Horvitz and D. J. Thompson, A generalization of sampling without replacement from a finite universe, Journal of the American Statistical Association 47(260), 1952, pp. 663 to 685 (the weight one over the inclusion probability and the unbiasedness of the weighted total)
  2. Paul R. Rosenbaum, Model-based direct adjustment, Journal of the American Statistical Association 82(398), 1987, pp. 387 to 394 (weighting by the inverse of the estimated propensity score)
  3. James M. Robins, Andrea Rotnitzky and Lue Ping Zhao, Estimation of regression coefficients when some regressors are not always observed, Journal of the American Statistical Association 89(427), 1994, pp. 846 to 866 (inverse probability weighted estimating equations and their augmented form)
  4. Keisuke Hirano, Guido W. Imbens and Geert Ridder, Efficient estimation of average treatment effects using the estimated propensity score, Econometrica 71(4), 2003, pp. 1161 to 1189 (weighting by a nonparametric estimate of the propensity score reaches the efficiency bound)
  5. Jared K. Lunceford and Marie Davidian, Stratification and weighting via the propensity score in estimation of causal treatment effects, a comparative study, Statistics in Medicine 23(19), 2004, pp. 2937 to 2960 (the weighted estimators, their sandwich variances, and the effect of estimating the propensity score)
  6. Richard K. Crump, V. Joseph Hotz, Guido W. Imbens and Oscar A. Mitnik, Dealing with limited overlap in estimation of average treatment effects, Biometrika 96(1), 2009, pp. 187 to 199 (trimming units with propensity scores near 0 or 1)
  7. Guido W. Imbens and Donald B. Rubin, Causal Inference for Statistics, Social, and Biomedical Sciences, Cambridge University Press, 2015, Chapter 12 (unconfounded treatment assignment) and Chapter 14 (assessing overlap)
  8. Miguel A. Hernán and James M. Robins, Causal Inference, What If, Chapman and Hall/CRC, 2020, Chapter 2 (randomized experiments and weighting) and Chapter 12 (IP weighting)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example