Tutorials › Marginal Structural Models › Super Learner Ensembles for Treatment Probabilities

Inverse Probability of Treatment Weights · Tutorial 111 of 501

Super Learner Ensembles for Treatment Probabilities

Learn to construct a cross-validated Super Learner for discrete treatment probabilities and turn its predictions into inverse-probability weights.

Advanced 12 min read

What You'll Learn

  • Define the cross-validated stacking objective for candidate treatment-probability models.
  • Explain when the ensemble-weight optimization has a solution and why it is convex.
  • Show how log loss evaluates probabilities for the treatment actually observed.
  • Calculate ordinary and stabilized inverse-probability weights from ensemble predictions.
  • Diagnose overfitting, poor overlap, and unreliable candidate predictions.
  • Distinguish Super Learner stacking from selecting one model or taking an unweighted average.

Why Stack Treatment-Probability Models?

Inverse-probability weighting depends on estimating the probability of the treatment actually received, conditional on the covariate and treatment history available at that decision. A single model can miss important structure: a linear predictor may be too restrictive, while a highly adaptive learner may be unstable in sparse regions. Super Learner stacking offers a principled way to combine a prespecified collection of candidate algorithms, using their out-of-fold predictions to choose combination weights.

The ensemble is a prediction procedure, not a guarantee of good overlap or causal identification. Its weights are chosen to predict treatment assignments under a specified loss. The causal interpretation of the resulting inverse-probability weights still requires the relevant identification assumptions, including consistency, sequential exchangeability, and positivity.

Definition: At decision time \(t\), let \(A_t\) be a discrete treatment and \(H_t\) the measured history available before that decision. The treatment mechanism is \(g_t(a\mid h)=P(A_t=a\mid H_t=h)\). A candidate learner \(m\) estimates this conditional probability; a convex ensemble combines candidate predictions using nonnegative weights that sum to one.

For a binary treatment, a candidate predicts \(p_i^{(m)}=P(A_i=1\mid H_i)\); its probability for the observed treatment is \(q_i^{(m)}=(p_i^{(m)})^{A_i}(1-p_i^{(m)})^{1-A_i}\). For a treatment with \(J\) categories, write \(p_{ij}^{(m)}=P(A_i=j\mid H_i)\), where each candidate's probabilities sum to one across categories. The observed-treatment probability is \(q_i^{(m)}=p_{i,A_i}^{(m)}\).

Cross-Validated Stacking

Partition the \(n\) observations into \(K\) folds. For each fold \(k\), fit every candidate algorithm using observations outside that fold, then predict treatment probabilities for observations in fold \(k\). Thus, \(p_{ij}^{(m,-k)}\) is candidate \(m\)'s prediction for category \(j\) on an observation not used to fit that fold-specific model. For binary treatment, the prediction for the observed treatment is \(q_i^{(m)}\) as defined above, using the corresponding fold-specific prediction.

Choose ensemble weights \(\alpha=(\alpha_1,\ldots,\alpha_M)\) from the probability simplex \(\mathcal{S}_M=\{\alpha_m\geq0:\sum_{m=1}^M\alpha_m=1\}\). The stacked prediction for category \(j\) is \(\hat p_{ij}=\sum_m\alpha_m p_{ij}^{(m,-k(i))}\). The usual selection criterion is the mean cross-validated negative log likelihood, also called multiclass log loss:

$$ \hat R_{\mathrm{CV}}(\alpha) = -\frac{1}{n}\sum_{i=1}^{n} \log\left\{\sum_{m=1}^{M}\alpha_m p_{i,A_i}^{(m,-k(i))}\right\}. $$

The selected weights minimize this criterion over \(\mathcal{S}_M\). After selection, the candidate algorithms are usually refitted on the full training data, and their full-data predictions are combined using the selected weights. For a new history \(h\), this gives \(\hat g(a\mid h)=\sum_m\hat\alpha_m\hat g_m(a\mid h)\). Because each component is a probability distribution and the weights are nonnegative and sum to one, the ensemble is also a probability distribution.

Result: Suppose every candidate assigns probability at least \(\epsilon>0\) to the treatment actually observed in every cross-validation prediction. Then \(\hat R_{\mathrm{CV}}\) is continuous and convex on \(\mathcal{S}_M\), and at least one minimizing ensemble weight vector exists.

Proof. For each observation \(i\), let \(c_{im}=p_{i,A_i}^{(m,-k(i))}\), so \(c_{im}\geq\epsilon\). The term in the objective is \(-\log(\sum_m\alpha_m c_{im})\). The argument of the logarithm is affine in \(\alpha\), is at least \(\epsilon\) on the simplex, and is at most one because it is a mixture of probabilities. The function \(-\log(x)\) is continuous and convex for \(x>0\). Its composition with a positive affine function is therefore continuous and convex in \(\alpha\); summing these terms preserves both properties. The simplex is compact and nonempty, so a continuous function on it attains its minimum. Convexity means any local minimum is global, although the minimizing weights need not be unique. \(\square\)

In practice, candidate predictions can be zero or numerically extremely small. The stated lower-bound condition is a convenient sufficient condition for the result; clipping probabilities to a prespecified small positive floor can enforce it. Clipping changes predictions and should be reported, not treated as an invisible numerical fix.

Why Use Log Loss?

Log loss evaluates the probability assigned to the treatment that actually occurred. It penalizes confident errors sharply: assigning probability \(0.01\) to the observed treatment incurs loss \(-\log(0.01)\), much larger than assigning probability \(0.4\). Under a correctly specified conditional probability target, its population optimum is the true treatment mechanism.

Result: Fix a history value \(h\) and suppose the true treatment probabilities are \(g_j=P(A=j\mid H=h)\). For any proposed probabilities \(q_j\) summing to one, with \(q_j>0\) whenever \(g_j>0\), the conditional expected log loss satisfies \[ -\sum_jg_j\log q_j = -\sum_jg_j\log g_j + \sum_{j:g_j>0}g_j\log\left(\frac{g_j}{q_j}\right). \] The final term is nonnegative and equals zero only when \(q_j=g_j\) for all \(j\) with positive \(g_j\).

Proof. Subtract the true-probability loss from the proposed loss and collect terms: \(\sum_{j:g_j>0}g_j\log(g_j/q_j)\). To show this is nonnegative, use \(\log x\leq x-1\) for \(x>0\), with equality only at \(x=1\). Applying it to \(x=q_j/g_j\) gives \[ \sum_{j:g_j>0}g_j\log\left(\frac{g_j}{q_j}\right) \geq \sum_{j:g_j>0}(g_j-q_j) = 1-\sum_{j:g_j>0}q_j \geq 0. \] Equality requires \(q_j=g_j\) on the support of \(g\), with no probability assigned outside that support. This proves the claim. \(\square\)

This result explains why log loss is a natural stacking criterion for probabilities, rather than a loss on hard treatment classifications. It does not imply that minimizing empirical cross-validated loss identifies the true mechanism in a finite sample, nor that low prediction loss ensures adequate positivity.

Worked Example: Finding the Stacking Weights

Suppose four out-of-fold observations have binary treatments \(A=(1,0,1,0)\). Candidate A predicts treatment-one probabilities \((0.9,0.1,0.5,0.5)\), while candidate B predicts \((0.5,0.5,0.1,0.9)\). For a candidate's observed-treatment probability, use \(p_i\) when \(A_i=1\) and \(1-p_i\) when \(A_i=0\).

The observed-treatment probabilities are therefore \((0.9,0.9,0.5,0.5)\) for A and \((0.5,0.5,0.9,0.9)\) for B. Let \(\alpha\) be the weight on A, so the weight on B is \(1-\alpha\). The mixture's observed-treatment probabilities are \((0.5+0.4\alpha,0.5+0.4\alpha,0.9-0.4\alpha,0.9-0.4\alpha)\). Its mean loss is \[ -\frac{1}{2}\left\{\log(0.5+0.4\alpha)+\log(0.9-0.4\alpha)\right\}. \]

The product inside the two logarithms is \((0.5+0.4\alpha)(0.9-0.4\alpha)=0.45+0.16\alpha-0.16\alpha^2\). This concave quadratic is maximized at \(\alpha=0.5\), so the mean negative log loss is minimized there. The ensemble assigns probability \(0.7\) to the observed treatment on every row, giving loss \(-\log(0.7)\approx0.3567\). Each candidate alone has mean loss \(-\{\log(0.9)+\log(0.5)\}/2\approx0.3993\).

For each row, the ensemble's treatment-one probabilities are \((0.7,0.3,0.3,0.7)\). Since every row has observed-treatment probability \(0.7\), the unstabilized inverse-probability weight is \(1/0.7\approx1.4286\) for each row. If the marginal probability of each treatment is \(0.5\), the corresponding stabilized weight is \(0.5/0.7\approx0.7143\).

From Ensemble Probabilities to Weights

For a single discrete treatment decision, the unstabilized weight for observation \(i\) is the reciprocal of the fitted probability of the treatment actually received. In a longitudinal setting, the denominator contribution at time \(t\) is \(\hat g_t(A_{it}\mid H_{it})\), and the unstabilized weight through time \(T\) is the product of the reciprocals of these contributions. A stabilized weight replaces each denominator factor with a specified numerator probability, often based on a reduced history:

$$ \hat W_i(T) = \prod_{t=0}^{T} \frac{\hat g^{\,\mathrm{num}}_t(A_{it}\mid \text{numerator history})} {\hat g^{\,\mathrm{den}}_t(A_{it}\mid H_{it})}. $$

The stacking procedure supplies the denominator predictions when it is used to estimate the treatment mechanism; the numerator is a separate modeling or marginal-probability choice. For a single decision, if the observed treatment is \(A_i=a\), calculate \(\hat g(a\mid H_i)\) first, then take its reciprocal (or divide the selected numerator probability by it). For multivalued treatment, use the probability for the observed category, not the probability of some other category.

Worked Example: A Three-Category Treatment

For one observation, suppose three candidate models predict probabilities for treatment categories \(0,1,2\), respectively: A gives \((0.70,0.20,0.10)\), B gives \((0.40,0.40,0.20)\), and C gives \((0.20,0.30,0.50)\). Suppose cross-validated stacking chooses weights \((0.50,0.30,0.20)\).

The ensemble probabilities are calculated category by category: \(P(A=0)=0.50(0.70)+0.30(0.40)+0.20(0.20)=0.35+0.12+0.04=0.51\); \(P(A=1)=0.50(0.20)+0.30(0.40)+0.20(0.30)=0.10+0.12+0.06=0.28\); and \(P(A=2)=0.50(0.10)+0.30(0.20)+0.20(0.50)=0.05+0.06+0.10=0.21\). They sum to \(0.51+0.28+0.21=1\).

If this person received treatment \(2\), the relevant denominator probability is \(0.21\), so the unstabilized weight is \(1/0.21\approx4.762\). If the selected numerator probability for treatment \(2\) is \(0.30\), the stabilized weight is \(0.30/0.21\approx1.429\). Using \(0.51\), the probability of treatment \(0\), would be an incorrect weight because that was not the treatment received.

Worked Example: Comparing a Weak and a Strong Treatment Probability

Consider two people with binary treatment. The first receives treatment \(1\), for which the ensemble predicts probability \(0.8\). The second receives treatment \(0\), while the ensemble predicts probability \(0.9\) for treatment \(1\). Their observed-treatment probabilities are \(0.8\) and \(1-0.9=0.1\), respectively. Their unstabilized weights are \(1/0.8=1.25\) and \(1/0.1=10\).

If the marginal probability of either treatment is \(0.5\), their stabilized weights are \(0.5/0.8=0.625\) and \(0.5/0.1=5\). The second large weight signals that the observed treatment was assigned a low fitted probability given that person's history. Stabilization changes the scale but does not remove the small denominator or establish that the estimate is reliable.

Diagnostics, Alternatives, and Limitations

Inspect both the prediction procedure and the weights it creates. Useful checks include the distribution of predicted probabilities for observed treatments, the minimum and lower quantiles of those probabilities, the distribution of resulting weights, and effective sample size. For weights \(W_i\), a common effective-sample-size summary is \((\sum_i W_i)^2/\sum_i W_i^2\). A small value relative to \(n\) indicates that a few observations dominate weighted summaries. For longitudinal weights, inspect cumulative products as well as time-specific factors, since moderate factors can compound.

Compare cross-validated log loss across candidate learners and the ensemble, and check that fold construction respects the independent sampling units. Repeated observations from one person should not be split across training and validation folds as if independent. A large gap between training and out-of-fold performance suggests overfitting. Also check for near-zero probabilities and unstable weights; low average log loss can coexist with poor predictions in a clinically important subgroup. Weight truncation may reduce variance but changes the estimator and can introduce bias.

Stacking differs from selecting the single candidate with the smallest cross-validated loss: it optimizes over mixtures, which can outperform every candidate, as the first worked example shows. It also differs from an unweighted average, which fixes weights in advance rather than learning them from out-of-fold predictions. The advantage depends on the candidate library and the validation design. A misspecified or narrow library limits what the ensemble can achieve; a very large library can make weight selection noisy. The selected convex weights do not prove that the true treatment mechanism is in the library, and they do not correct structural positivity violations.

Common mistake: It is tempting to fit candidates on the full data, select weights by evaluating their predictions on those same observations, and call the resulting loss cross-validated. That is in-sample evaluation: the predictions have already used the outcomes being scored, so the loss can be optimistically biased. Generate out-of-fold predictions before optimizing stacking weights. Also, do not confuse this use of folds with cross-fitting for causal estimation; cross-fitting treatment-probability estimates is a distinct procedure.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. For a three-category treatment, why must the ensemble's probabilities sum to one if each candidate's probabilities sum to one and the ensemble weights lie on the simplex?
  2. For one observation with \(A_i=0\), a binary-treatment ensemble predicts \(P(A_i=1\mid H_i)=0.85\). What is the observed-treatment probability and the unstabilized weight?
  3. What property of the cross-validated stacking objective makes a global minimum attainable under the lower-bound condition in the theorem?
  4. Why can a low average cross-validated log loss fail to rule out problematic inverse-probability weights?

Solutions. (1) For each category \(j\), the ensemble probability is \(\sum_m\alpha_m p_{ij}^{(m)}\). Summing over categories gives \(\sum_m\alpha_m\sum_jp_{ij}^{(m)}=\sum_m\alpha_m=1\). (2) The observed-treatment probability is \(1-0.85=0.15\), so the unstabilized weight is \(1/0.15\approx6.67\). (3) The objective is continuous on the compact, nonempty simplex, so it attains a minimum; convexity additionally ensures any local minimum is global. (4) Average loss can hide poor predictions for a small subgroup or a few observations. A very small observed-treatment probability creates a large inverse weight even when overall predictive loss is low.

Clinical Biostats