Tutorials › Marginal Structural Models › A Two-Decision Worked Example With Binary Treatment

Inverse Probability of Treatment Weights · Tutorial 125 of 501

A Two-Decision Worked Example With Binary Treatment

Learn to fit and apply two sequential binary-treatment probability models, calculate each subject’s weight from their observed path, and check whether the resulting weights are credible.

Advanced 12 min read

What You'll Learn

  • Specify the treatment history used in each of two sequential binary-treatment models.
  • Interpret fitted logistic models as probabilities for the decisions actually observed.
  • Calculate an unstabilized longitudinal weight from an individual treatment path.
  • Derive the sequential weighting identity and state its integrability conditions.
  • Diagnose extreme weights and distinguish an observed-decision probability from its complement.
  • Check the assumptions needed to interpret weighted outcomes causally.

Two Decisions, One Longitudinal Weight

With treatment measured at two decision times, a subject’s treatment path is a pair: first \(A_1\), then \(A_2\). The probability of the second decision can depend on what happened before it, including the first treatment and an intermediate covariate. A longitudinal treatment weight therefore uses two conditional probabilities, not one probability for the entire path.

This tutorial specifies and fits the two binary treatment models, then calculates the weight for each observed path. The weights below are unstabilized: they contain the reciprocal probabilities of the decisions actually observed, with no numerator factors.

Definition: For subject \(i\), let \(L_{0i}\) denote baseline covariates, \(A_{1i}\in\{0,1\}\) the first treatment, \(L_{1i}\) covariates measured after the first decision and before the second, and \(A_{2i}\in\{0,1\}\) the second treatment. Define \(q_{1i}=P(A_{1i}=1\mid L_{0i})\) and \(q_{2i}=P(A_{2i}=1\mid L_{0i},A_{1i},L_{1i})\). The probability assigned to the observed decision at time \(t\) is \(q_{ti}^{A_{ti}}(1-q_{ti})^{1-A_{ti}}\). The two-decision unstabilized treatment weight is \(W_i=\{q_{1i}^{A_{1i}}(1-q_{1i})^{1-A_{1i}}q_{2i}^{A_{2i}}(1-q_{2i})^{1-A_{2i}}\}^{-1}\).

The treatment history changes across decisions. The first model uses covariates available before \(A_1\), here \(L_0\). The second uses the history available before \(A_2\), here \((L_0,A_1,L_1)\). Including \(L_1\) in the second model is often important because it may predict both the next treatment and the outcome. It must be measured before the second decision; a later variable cannot be used to predict that decision.

Fitting the Sequential Probabilities

A common choice for binary treatment is logistic regression. For example, specify \(q_1(L_0)=\operatorname{expit}(\beta_{10}+\beta_{11}L_0)\) and \(q_2(L_0,A_1,L_1)=\operatorname{expit}(\beta_{20}+\beta_{21}A_1+\beta_{22}L_1+\beta_{23}L_0)\), where \(\operatorname{expit}(x)=1/(1+\exp(-x))\). The first model is fitted to the first treatment decisions. The second is fitted to the second decisions among subjects eligible for that decision, with their histories recorded before it.

For either model, the Bernoulli likelihood is the product of the fitted probability for each observed treatment value. For example, the first-decision log-likelihood is \(\ell_1(\beta_1)=\sum_{i=1}^n[A_{1i}\log q_1(L_{0i})+(1-A_{1i})\log\{1-q_1(L_{0i})\}]\). The second-decision likelihood has the same form with \(A_{2i}\) and \(q_2(L_{0i},A_{1i},L_{1i})\), summed over eligible subjects. Maximum likelihood estimates maximize the corresponding log-likelihoods. The resulting fitted probabilities are then evaluated at each subject’s observed history. A probability of 0.7 is not itself the factor used for everyone: it is used as the observed-decision probability only for a subject with \(A_t=1\); a subject with \(A_t=0\) uses \(1-0.7=0.3\).

The usual interpretation of fitted probabilities assumes the model represents the relevant conditional treatment probabilities adequately. For a causal interpretation of weighted outcomes, further assumptions are needed: consistency of observed and potential outcomes under the received treatment history; sequential exchangeability, meaning no unmeasured confounding of each decision and the relevant potential outcomes given the measured history; and positivity, meaning each treatment option under consideration has positive probability at histories that occur in the target population. The arithmetic definition of \(W_i\) alone does not establish those assumptions.

Worked Example: Evaluating Two Fitted Models

Suppose fitting the two logistic models gives the following illustrative coefficient estimates: \(q_1(L_0)=\operatorname{expit}(-0.4+0.8L_0)\) and \(q_2(L_0,A_1,L_1)=\operatorname{expit}(-0.6+0.5A_1+0.4L_1-0.3L_0)\). For a subject with \(L_0=0,A_1=1,L_1=1,A_2=1\), find both observed-decision probabilities and the weight.

At the first decision, the linear predictor is \(-0.4+0.8(0)=-0.4\). Therefore \(q_1=\operatorname{expit}(-0.4)=0.4013\). Since \(A_1=1\), the first observed-decision probability is 0.4013.

At the second decision, the linear predictor is \(-0.6+0.5(1)+0.4(1)-0.3(0)=0.3\). Thus \(q_2=\operatorname{expit}(0.3)=0.5744\). Since \(A_2=1\), the second observed-decision probability is 0.5744. The path probability used in the denominator is \(0.4013\times0.5744\), approximately 0.2305, so the weight is approximately \(1/0.2305=4.338\). The subject receives a relatively large weight because the fitted models assign a modest probability to receiving both observed treatments.

Why the Product of Reciprocals Is the Relevant Weight

At each decision, the fitted model assigns a probability to the treatment that the subject actually received. The chain rule for conditional probabilities says that the probability of the observed two-decision path, conditional on the measured history as it unfolds, is the product of those two conditional probabilities. The weight is the reciprocal of that product.

Result: If \(A_1\) and \(A_2\) are binary and the sequential conditional probabilities are \(q_1=P(A_1=1\mid L_0)\) and \(q_2=P(A_2=1\mid L_0,A_1,L_1)\), then the conditional probability assigned to an observed path \((a_1,a_2)\) is \([q_1^{a_1}(1-q_1)^{1-a_1}][q_2^{a_2}(1-q_2)^{1-a_2}]\). Its reciprocal is exactly the two-decision unstabilized weight for that path.

To verify this, first condition on \(L_0,A_1,L_1\). By definition of \(q_2\), \(P(A_2=a_2\mid L_0,A_1,L_1)=q_2^{a_2}(1-q_2)^{1-a_2}\). The first decision has conditional probability \(P(A_1=a_1\mid L_0)=q_1^{a_1}(1-q_1)^{1-a_1}\). Applying the chain rule gives the product for the observed path. Taking its reciprocal gives the defined weight, provided both factors are positive. \(\square\)

A second way to see what the weight accomplishes is to consider a fixed path \((a_1,a_2)\). The next identity describes the treatment-selection cancellation for covariates \(L_0,L_1\). It is an algebraic identity under the true conditional treatment probabilities, not a claim that fitted probabilities are known exactly.

Result: Assume the true sequential probabilities are positive for the specified decisions on the histories being considered. For any nonnegative measurable \(h(L_0,L_1)\), $$ E\left[ \frac{\mathbb{1}(A_1=a_1,A_2=a_2)h(L_0,L_1)} {q_1(a_1\mid L_0)q_2(a_2\mid L_0,A_1,L_1)} \right] = E_{L_0}\left[E\{h(L_0,L_1)\mid L_0,A_1=a_1\}\right], $$ where \(q_t(a_t\mid\cdot)\) denotes the conditional probability of the specified treatment value. The equality holds as an extended-expectation identity. For signed \(h\), require \(E_{L_0}[E\{|h(L_0,L_1)|\mid L_0,A_1=a_1\}]<\infty\); then both sides are defined as ordinary expectations and the equality holds.

For the proof, condition first on \(L_0,A_1,L_1\). The conditional expectation of \(\mathbb{1}(A_2=a_2)/q_2(a_2\mid L_0,A_1,L_1)\) is 1, because the conditional probability of \(A_2=a_2\) is the denominator. The left side therefore reduces to the expectation of \(\mathbb{1}(A_1=a_1)h(L_0,L_1)/q_1(a_1\mid L_0)\). Conditioning next on \(L_0\), the conditional expectation of \(\mathbb{1}(A_1=a_1)h(L_0,L_1)/q_1(a_1\mid L_0)\) is \(E\{h(L_0,L_1)\mid L_0,A_1=a_1\}\), again because the event has conditional probability \(q_1(a_1\mid L_0)\). Taking expectation over \(L_0\) gives the right side. For nonnegative \(h\), conditional expectations and iterated integration are valid even if the value is infinite. For signed \(h\), the stated absolute-integrability condition makes the positive and negative parts finite, so the same conditioning argument applies to each part and their difference is defined. \(\square\)

In applications, the probabilities are estimated rather than known. The fitted-weight calculation is a plug-in version of this identity; finite-sample balance is not guaranteed. For outcome analyses, causal interpretation additionally relies on the consistency, sequential exchangeability, and positivity assumptions stated above.

Calculating Every Subject’s Weight

Using the fitted models from the first example, the following four subjects have different observed histories. The table reports the model probabilities and selects either \(q_t\) or \(1-q_t\) according to each observed treatment.

Worked Example: Four Observed Treatment Paths

For each subject, calculate the probability of the observed first decision, the probability of the observed second decision, and the reciprocal of their product.

Subject\(L_0,A_1,L_1,A_2\)First observed probabilitySecond observed probability\(W_i\)
1\(0,1,1,1\)\(\operatorname{expit}(-0.4)=0.4013\)\(\operatorname{expit}(0.3)=0.5744\)\(1/(0.4013\times0.5744)=4.338\)
2\(0,0,0,0\)\(1-\operatorname{expit}(-0.4)=0.5987\)\(1-\operatorname{expit}(-0.6)=0.6457\)\(1/(0.5987\times0.6457)=2.587\)
3\(1,1,0,0\)\(\operatorname{expit}(0.4)=0.5987\)\(1-\operatorname{expit}(-0.4)=0.5987\)\(1/(0.5987\times0.5987)=2.790\)
4\(1,0,1,1\)\(1-\operatorname{expit}(0.4)=0.4013\)\(\operatorname{expit}(-0.5)=0.3775\)\(1/[(1-\operatorname{expit}(0.4))\operatorname{expit}(-0.5)]\approx6.600\)

For subject 2, the unrounded probabilities are approximately 0.5986877 and 0.6456563. Their product is approximately 0.3865465, and its reciprocal is approximately 2.5870, which rounds to 2.587. The table values are rounded for display; calculations should use full precision until the final reported weight.

Worked Example: The Complement for an Untreated Second Decision

Keep subject 1’s history through \(L_1\), but suppose the observed second treatment is \(A_2=0\), not \(A_2=1\). The fitted second-treatment probability remains \(\operatorname{expit}(0.3)=0.5744\). The observed second-decision probability is its complement, \(1-0.5744=0.4256\). The first observed-decision probability is still 0.4013, so \(W=1/(0.4013\times0.4256)\approx1/0.1708=5.855\). Using 0.5744 for the second factor would answer a different question: it would use the probability of receiving treatment when the subject actually did not receive it. The treatment path, not merely the fitted probability of treatment, determines which factor enters the weight.

Diagnostics, Alternatives, and Limitations

The main practical warning is positivity. If a fitted observed-decision probability is near zero at either time, its reciprocal is large, and multiplying the two reciprocals can produce an especially large weight. Inspect the distribution of weights and the fitted probabilities separately at both decision times. Check for probabilities near zero or one in histories represented by only a few subjects, and compare covariate-history support across treatment decisions. Extreme weights can indicate genuine limited overlap, sparse histories, model misspecification, or some combination of these.

A useful descriptive check is the effective sample size, \(n_{\mathrm{eff}}=(\sum_i W_i)^2/\sum_i W_i^2\). If a few weights dominate, this quantity can be much smaller than the number of subjects. It is a warning about the concentration of weighted information, not a proof that the model is wrong or a replacement for examining histories and model fit. Predicted probabilities should also be checked for calibration and sensible variation across the histories used to fit each decision model.

The unweighted comparison of outcomes across observed treatment paths does not correct for treatment selection. Conditional outcome regression is a major alternative approach: it models the outcome given treatment and covariates, whereas inverse probability weighting models the treatment assignment and reweights observations. The approaches rely on different modeling choices and assumptions; neither automatically resolves unmeasured confounding or lack of overlap. In particular, a weight cannot create information for a treatment decision that is essentially absent in a covariate history.

Finally, these calculations assume the subject has an observed, eligible decision at both times and that the histories used in the second model precede \(A_2\). If treatment eligibility, censoring, or missing treatment records alter who contributes at the second decision, the analysis must represent that structure rather than silently treating missing decisions as zero. The two-factor formula is specific to two sequential binary decisions; it is not a formula for multivalued or continuous treatment.

Common mistake: Multiplying the fitted probabilities of treatment at both times, regardless of observed treatment, is not the observed-path probability. For a decision with \(A_t=0\), use \(1-q_t\), not \(q_t\). The correction is to evaluate the probability of each decision actually observed and take the reciprocal of their product.

Check Your Understanding

Answer each question, then compare your work with the solutions below.

  1. At the first decision, a fitted probability is \(q_1=0.25\), and the observed treatment is \(A_1=0\). What probability enters the weight?
  2. Suppose a subject’s observed-decision probabilities are 0.8 at time 1 and 0.5 at time 2. Calculate the two-decision weight.
  3. Why can using \(q_2=P(A_2=1\mid L_0,A_1,L_1)\) alone be wrong when the observed second treatment is zero?
  4. State one assumption needed for a causal interpretation of weighted outcomes, beyond fitting the two probability models.
  5. If a history has a fitted probability of the observed decision near zero, what happens to its weight, and what concern does this raise?

Solutions. (1) The observed decision is zero, so use \(1-q_1=1-0.25=0.75\). (2) The product is \(0.8\times0.5=0.4\); the reciprocal weight is \(1/0.4=2.5\). (3) \(q_2\) is the probability of treatment, not the probability of every possible observed decision. When \(A_2=0\), the correct factor is \(1-q_2\). (4) One valid answer is sequential exchangeability: conditional on measured history at each decision, treatment assignment is independent of the relevant potential outcomes. Consistency and positivity are also required. (5) Its reciprocal becomes large, potentially making the product weight extreme. This signals a possible positivity or overlap problem, sparse histories, or model misspecification and should prompt examination of the fitted probabilities and observed histories.

Clinical Biostats