Tutorials › Marginal Structural Models › Hand-Calculating Weights From Fitted Probabilities

Inverse Probability of Treatment Weights · Tutorial 124 of 501

Hand-Calculating Weights From Fitted Probabilities

You will calculate each person’s inverse probability weight from their fitted treatment probability and observed assignment, then check the result for coding and positivity problems.

Advanced 9 min read

What You'll Learn

  • Apply the inverse probability weight formula separately to treated and untreated observations.
  • Distinguish the probability of the treatment actually received from the probability of the other treatment.
  • Calculate individual weights from a table of fitted probabilities and observed assignments.
  • Check weights for coding errors and probabilities close to zero or one.
  • Interpret the weighted contribution of each treatment arm under the true treatment mechanism.

From Fitted Probability to Individual Weight

A treatment model produces a probability for each person, but a weight is calculated using both that probability and the person’s observed treatment assignment. For a binary treatment at one decision time, the relevant question is: how probable was the treatment this person actually received, given the covariates used in the treatment model? The inverse probability weight is the reciprocal of that probability.

Let \(A_i\) be person \(i\)’s observed treatment, coded \(1\) for treated and \(0\) for untreated. Let \(\hat e_i\) be the fitted probability of treatment, \(P(A_i=1\mid L_i)\), evaluated at that person’s covariates \(L_i\). The fitted probability of being untreated is \(1-\hat e_i\). The weight uses one of these two probabilities, according to the observed value of \(A_i\).

Definition: For a binary treatment at one decision time, the individual inverse probability of treatment weight is $$ \hat W_i=\frac{A_i}{\hat e_i}+\frac{1-A_i}{1-\hat e_i} = \begin{cases} 1/\hat e_i, & A_i=1,\\ 1/(1-\hat e_i), & A_i=0. \end{cases} $$ Here \(0<\hat e_i<1\). The numerator selects the reciprocal probability corresponding to the treatment actually observed.

This is an individual-level calculation. It does not multiply weights across decision times, add a numerator, or replace probabilities with odds. Each row in the treatment-model output gives one fitted probability; combine that value with the observed assignment for the same person.

Hand Calculation for Both Assignments

The calculation is easiest to audit by writing down the probability of the observed arm first. For a treated person that probability is \(\hat e_i\), so the weight is \(1/\hat e_i\). For an untreated person it is \(1-\hat e_i\), so the weight is \(1/(1-\hat e_i)\). The weight is not always the reciprocal of the fitted treatment probability: that is true only when the person is treated.

Worked Example: Calculating Four Individual Weights

Suppose a fitted treatment model gives the probabilities below. Calculate the weight for each person from the observed assignment.

PersonObserved \(A_i\)Fitted \(\hat e_i\)Probability of observed assignmentWeight \(\hat W_i\)
110.800.801.25
200.250.751.3333
300.600.402.50
410.400.402.50

For person 1, \(A_1=1\), so use the treatment probability: \(1/0.80=1.25\). For person 2, \(A_2=0\), so use the untreated probability: \(1/(1-0.25)=1/0.75=1.3333\) to four decimal places. For person 3, \(A_3=0\), giving \(1/(1-0.60)=1/0.40=2.50\). For person 4, \(A_4=1\), giving \(1/0.40=2.50\).

The last two people have the same weight for different reasons: person 3 had a fitted untreated probability of \(0.40\), while person 4 had a fitted treated probability of \(0.40\). The observed assignment determines which probability is used.

Worked Example: Checking the Untreated Denominator

A person is untreated, \(A_i=0\), and has fitted treatment probability \(\hat e_i=0.70\). A second person is treated, \(A_j=1\), with fitted treatment probability \(\hat e_j=0.20\). Find both weights and identify a tempting but incorrect calculation.

For the untreated person, the fitted probability of the observed assignment is \(1-0.70=0.30\). Thus \(\hat W_i=1/0.30=3.3333\) to four decimal places. Using \(1/0.70\) would invert the probability of treatment, even though treatment was not observed.

For the treated person, the fitted probability of the observed assignment is \(0.20\). Thus \(\hat W_j=1/0.20=5\). In this case, \(1/(1-0.20)\) would use the probability of the opposite assignment.

The audit is simple: state the observed assignment, name its fitted probability, then take the reciprocal. This makes the complement explicit for untreated observations.

Why the Reciprocal Has This Form

The formula has a direct probability interpretation. If treatment is assigned with probability \(e(L)\), then among people with the same covariates, the treated fraction is \(e(L)\) and the untreated fraction is \(1-e(L)\). Weighting each observed arm by the reciprocal of its assignment probability compensates, in expectation, for how often that arm occurs.

Result: Suppose \(A\) is binary, \(L\) denotes the covariates, and the true treatment probability is \(e(L)=P(A=1\mid L)\), with \(0<e(L)<1\). For either arm \(a\in\{0,1\}\), $$ E\left[\left.\frac{I(A=a)}{P(A=a\mid L)}\right|L\right]=1. $$ Consequently, for \(W=I(A=1)/e(L)+I(A=0)/(1-e(L))\), \(E[W\mid L]=2\).

To prove the result, condition on \(L\). For \(a=1\), \(I(A=1)\) is one with conditional probability \(e(L)\) and zero otherwise. Therefore, $$ E\left[\left.\frac{I(A=1)}{e(L)}\right|L\right] =\frac{P(A=1\mid L)}{e(L)} =\frac{e(L)}{e(L)}=1. $$ For \(a=0\), the corresponding conditional probability is \(1-e(L)\), and $$ E\left[\left.\frac{I(A=0)}{1-e(L)}\right|L\right] =\frac{P(A=0\mid L)}{1-e(L)} =\frac{1-e(L)}{1-e(L)}=1. $$ Adding the two conditional expectations gives \(E[W\mid L]=1+1=2\). The positivity condition ensures both denominators are nonzero. \(\square\)

This is a statement about the true probability mechanism and conditional expectations. It does not say that a finite sample’s treated and untreated weight totals will each be identical, nor does it say that substituting arbitrary fitted probabilities makes the identity exact. If fitted probabilities differ from the true probabilities, the conditional expectation for the treated contribution is \(e(L)/\hat e(L)\), not necessarily one.

Worked Example: A Small Table and Its Weight Totals

Consider five people with the following observed assignments and fitted probabilities. Calculate their weights and sum the weights within each observed arm.

Person\(A_i\)\(\hat e_i\)Calculation\(\hat W_i\)
110.80\(1/0.80\)1.25
200.80\(1/0.20\)5.00
310.30\(1/0.30\)3.3333
400.30\(1/0.70\)1.4286
510.50\(1/0.50\)2.00

The treated weight total is \(1.25+3.3333+2.00=6.5833\), to four decimal places. The untreated weight total is \(5.00+1.4286=6.4286\). Their closeness in this particular table is not a required check: the result above concerns conditional expectations under the true probability mechanism, not equality of finite-sample totals. The table’s main arithmetic check is that every denominator is the probability of that person’s observed arm.

Assumptions, Checks, and Common Errors

Computing a number from a fitted probability requires only that the probability corresponds to the correct person and treatment definition, and that the observed-arm probability is positive. Interpreting the weights as supporting a causal analysis requires more. In the usual single-decision setting, treatment must be well defined and consistently recorded; relevant confounding must be addressed by the treatment model under the intended causal assumptions; and positivity must hold, meaning both treatment options have positive probability at covariate patterns in the target population. Calculation alone does not establish those causal conditions.

A useful first diagnostic is a row-by-row check of \(\hat e_i\), \(A_i\), the observed-arm probability, and the resulting weight. Probabilities must lie between zero and one, and the observed-arm probability must not be zero. A fitted probability near one for an untreated person, or near zero for a treated person, produces a large weight because the observed assignment was considered unlikely by the model. Such values warrant investigation; they can reflect limited overlap, model misspecification, data errors, or a genuinely unusual assignment.

  • Using \(\hat e_i\) for everyone. This gives the correct reciprocal for treated people, but not for untreated people. For \(A_i=0\), use \(1-\hat e_i\).
  • Using the probability of the opposite arm. The denominator is the probability of the observed assignment, not the alternative assignment.
  • Reading a large weight as proof of a calculation error. The reciprocal may be correct even when it is large. It signals that the observed assignment had low fitted probability and deserves a positivity and data-quality check.
  • Assuming fitted probabilities guarantee the expectation identity. The identity is exact when the denominators are the true conditional assignment probabilities. Estimated or misspecified probabilities need not have that property.

An unweighted analysis uses no such correction and can retain differences in the covariate distribution between treatment groups. The inverse probability calculation instead assigns larger weight to people whose observed assignment was less probable given their covariates. It is distinct from using treatment odds: for an untreated person, the required denominator is \(1-\hat e_i\), not a treatment-odds expression. These weights are also not a guarantee of balance or valid causal conclusions; the treatment model, overlap, and other causal assumptions still matter.

Key takeaway: For every person, identify the observed treatment first. Use \(1/\hat e_i\) if treated and \(1/(1-\hat e_i)\) if untreated. Then inspect the observed-arm probability, especially when it is close to zero.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A treated person has fitted treatment probability \(0.40\). What is the weight?
  2. An untreated person has fitted treatment probability \(0.40\). What is the weight?
  3. For an untreated person with fitted probability \(0.90\), explain why the weight is large and calculate it.
  4. Under the true treatment mechanism, what is \(E[I(A=0)/(1-e(L))\mid L]\), and what assumption makes the expression defined?

Solutions. (1) The person is treated, so the weight is \(1/0.40=2.5\). (2) The person is untreated, so the observed-arm probability is \(1-0.40=0.60\), and the weight is \(1/0.60=1.6667\) to four decimal places. (3) The fitted untreated probability is \(1-0.90=0.10\), so the weight is \(1/0.10=10\). It is large because the model assigned low probability to the observed untreated assignment. (4) The conditional expectation is \((1-e(L))/(1-e(L))=1\); it is defined when \(e(L)<1\), with positivity requiring both \(e(L)>0\) and \(e(L)<1\) for both arms.

Clinical Biostats