Tutorials › Causal Inference › An End-to-End Analysis With Treatment and Censoring Weights

Marginal Structural Models · Tutorial 752 of 972

An End-to-End Analysis With Treatment and Censoring Weights

Work through a hypothetical two-time-point cohort analysis, from weight-model assumptions and construction to diagnostics, weighted estimation, and robust uncertainty for a marginal contrast.

Advanced 13 min read

What You'll Learn

  • Specify treatment and censoring probability models for a two-time-point longitudinal cohort.
  • Construct stabilized cumulative weights with numerators suited to a treatment-history-only marginal structural model.
  • Check weight distributions, effective sample size, and covariate balance in the weighted data.
  • Fit a weighted marginal structural model and calculate a treatment-history contrast.
  • Interpret robust confidence intervals and identify the assumptions needed for a causal interpretation.

Why an End-to-End Analysis Needs More Than a Regression

With longitudinal treatment, a covariate measured after one treatment can predict the next treatment and the outcome, while also being affected by earlier treatment. Ordinary adjustment for that covariate can therefore change the causal contrast being estimated. Marginal structural models (MSMs) address this setting by weighting observations to account for measured treatment-confounder histories, then fitting a model for outcomes across treatment histories. If people can leave follow-up before the outcome is observed, censoring must be addressed as well.

This tutorial follows a hypothetical cohort with two treatment times and a continuous outcome measured at the end of follow-up. The goal is an end-to-end analysis for the mean outcome under each treatment history. The weights and model below are one coherent strategy, not a substitute for defining the target population, timing, and causal assumptions in the study protocol.

Definition: Let \(V\) denote baseline covariates, \(L_t\) covariates measured before treatment at time \(t\), \(A_t\) treatment at time \(t\), and \(R_t=1\) indicate that a participant remains uncensored through time \(t\). Write \(\bar A_t=(A_1,\ldots,A_t)\) for the treatment history and \(\bar L_t=(L_1,\ldots,L_t)\) for the measured covariate history. Let \(Y\) be the outcome at the end of follow-up. An MSM specifies a population-level mean \(E(Y^{\bar a})\) as a function of treatment history \(\bar a\), where \(Y^{\bar a}\) is the potential outcome under that history.

For a treatment-history-only MSM, the stabilized-weight numerators below depend on prior treatment, but not on \(V\). This detail matters: numerator probabilities that depend on baseline covariates can retain or induce baseline-covariate differences across treatment histories. Alternatively, an analysis could include \(V\) in the MSM and standardize fitted means to a specified population distribution of \(V\); that is not the model used here.

Assumptions and Weight Models

Before estimating weights, the analysis needs a clear time order: measure \(V\), then at each time measure \(L_t\), assign \(A_t\), and determine whether the participant remains observed. The following assumptions support a causal interpretation of the weighted estimates.

  • Consistency: if a participant follows history \(\bar a\), their observed outcome equals \(Y^{\bar a}\).
  • Sequential exchangeability for treatment: among participants still observed at time \(t\), treatment \(A_t\) is independent of future potential outcomes conditional on the measured history \(V,\bar L_t,\bar A_{t-1}\). Unmeasured confounding would violate this condition.
  • Conditional independent censoring: given the measured covariate and treatment history, remaining uncensored is independent of the relevant future potential outcomes.
  • Positivity: each treatment and remaining-observed probability required by the target histories is positive for the histories occurring in the target population.
  • Correct probability models: the fitted treatment and censoring models adequately estimate the conditional probabilities used in the weights.

These are substantive and statistical conditions, not properties established simply by fitting logistic regressions. Diagnostics can reveal some problems, such as near-zero estimated probabilities or poor measured-covariate balance, but cannot verify exchangeability or rule out unmeasured confounding.

For binary treatment, one can estimate the treatment denominators with pooled logistic regressions, using the time-specific measured history to predict \(A_t\). The stabilized numerator model predicts \(A_t\) from \(\bar A_{t-1}\) only. For censoring, model the probability of remaining uncensored at each time among those uncensored at the start of that interval. The denominator includes measured covariates and treatment history; the numerator includes treatment history but not \(V\) or \(L_t\).

Definition: For a participant uncensored through time \(t\), the stabilized treatment and censoring weights through time \(t\) are $$ SW^A_t=\prod_{k=1}^{t} \frac{P(A_k\mid \bar A_{k-1})} {P(A_k\mid V,\bar L_k,\bar A_{k-1},R_{k-1}=1)} \qquad\text{and}\qquad SW^C_t=\prod_{k=1}^{t} \frac{P(R_k=1\mid R_{k-1}=1,\bar A_k)} {P(R_k=1\mid R_{k-1}=1,V,\bar L_k,\bar A_k)}. $$ The combined weight is \(SW_t=SW^A_tSW^C_t\). In each treatment probability, the probability is evaluated at the participant’s observed treatment value. For an outcome observed at the end of time 2, use the combined weight through time 2 among participants with \(R_2=1\).

The numerator terms retain dependence on treatment history. Thus weighting aims to remove dependence of treatment on the time-varying covariates in the denominator, conditional on the history retained in the numerator; it does not make treatment independent of every measured predictor. Likewise, censoring weighting adjusts for measured predictors of remaining observed that appear in its denominator. The numerator choice is aligned with the treatment-history-only target model.

Worked Example: Constructing One Participant’s Cumulative Weight

Worked Example: Constructing One Participant’s Cumulative Weight

Suppose the fitted treatment and censoring models in a hypothetical cohort give the probabilities below for one participant who has \(A_1=1\), \(A_2=0\), and remains uncensored at both times. These values are illustrative model predictions, not observed study results.

At time 1, the numerator probability of \(A_1=1\) is \(0.50\), and the denominator probability given this participant’s measured history is \(0.40\). At time 2, conditional on \(A_1=1\), the numerator probability of \(A_2=0\) is \(0.60\), and the denominator probability is \(0.70\). Therefore,

$$ SW^A_2=\frac{0.50}{0.40}\times\frac{0.60}{0.70} =1.25\times0.8571=1.071. $$

For remaining uncensored, suppose the time-1 numerator and denominator probabilities are \(0.95\) and \(0.90\), respectively. At time 2, conditional on the treatment history, they are \(0.90\) and \(0.80\). Then

$$ SW^C_2=\frac{0.95}{0.90}\times\frac{0.90}{0.80} =1.0556\times1.125=1.188. $$

The combined weight is \(1.071\times1.188=1.272\), to three significant figures. This participant contributes about 1.27 times the influence of a weight-1 participant to the weighted estimating equation, subject to the chosen outcome model. The calculation assumes the fitted probabilities are valid and nonzero; a single finite weight does not establish that positivity or model specification is satisfactory.

From Probability Models to a Weighted Analysis

A useful justification for the product form is to consider one treatment time. Within a measured history, the observed treatment probability in the denominator is multiplied by the ratio of the numerator probability to that denominator. The resulting treatment probability is proportional to

$$ P(A_t\mid V,\bar L_t,\bar A_{t-1}) \frac{P(A_t\mid\bar A_{t-1})} {P(A_t\mid V,\bar L_t,\bar A_{t-1})} =P(A_t\mid\bar A_{t-1}). $$

The same cancellation applies successively across times, conditional on the history reached at each time. Censoring ratios analogously replace the measured-history-dependent probability of remaining observed with the numerator probability, conditional on treatment history. This explains the weighting construction: measured histories in the denominators are reweighted out, while the numerator histories remain. The argument depends on valid conditional probabilities and support; it does not by itself prove that the measured histories suffice for causal exchangeability.

After calculating weights for every eligible outcome record, fit the prespecified MSM by weighted estimating equations. For a continuous outcome and two binary treatments, a saturated treatment-history model is

$$ E(Y^{a_1,a_2})= \beta_0+\beta_1a_1+\beta_2a_2+\beta_{12}a_1a_2. $$

“Saturated” here means that this model assigns a separate mean to each of the four treatment histories. For a binary outcome, a link appropriate to the target effect scale can be used instead; the link and interpretation must be stated before estimation. The weights alone do not determine the effect scale.

Worked Example: Checking the Weights and Balance

Worked Example: Checking the Weights and Balance

Suppose five hypothetical participants have final combined weights \(0.5, 0.8, 1.0, 1.2,\) and \(6.5\). Their sum is \(10.0\), and their squared weights sum to

$$ 0.5^2+0.8^2+1.0^2+1.2^2+6.5^2 =0.25+0.64+1.00+1.44+42.25=45.58. $$

The weight-based effective sample size is

$$ ESS=\frac{(\sum_i SW_i)^2}{\sum_i SW_i^2} =\frac{10.0^2}{45.58}=2.194. $$

Although there are five records, this weight concentration corresponds to an effective sample size of about 2.19. The value is a diagnostic summary, not a literal count of independent participants or a replacement for robust uncertainty estimation. The largest weight, \(6.5\), should prompt examination of the fitted probability models, the relevant covariate histories, and empirical support for the histories represented by that record.

Balance should also be examined after weighting. For illustration, suppose a time-varying confounder has weighted means \(4.8\) and \(4.7\) in two treatment groups being compared, with pooled standard deviation \(2.0\). The standardized mean difference is

$$ SMD=\frac{4.8-4.7}{2.0}=0.05. $$

This small difference suggests good balance for that measured covariate in this particular comparison. In a longitudinal analysis, balance checks should reflect the relevant time and prior-treatment strata, and should cover important measured denominator covariates rather than only one variable. A small standardized difference is reassuring for measured balance, but it cannot establish exchangeability or correct model specification.

Inspect the distribution of treatment, censoring, and combined weights, including upper quantiles and maxima, and calculate effective sample size. Review estimated probabilities near zero, histories with little or no support, and weighted covariate balance. If weights are truncated, report the truncation rule and assess how conclusions change; truncation trades reduced instability for potential bias. It does not repair a structural positivity violation.

Worked Example: Fitting the MSM and Reporting a Contrast

Worked Example: Fitting the MSM and Reporting a Contrast

Suppose a hypothetical weighted analysis of a continuous outcome measured in points produces the following sums of weights and weighted outcome sums among participants observed at the final time. These are summaries of a larger cohort; they are not raw sample sizes.

Treatment history \((A_1,A_2)\)Sum of weightsWeighted outcome sumWeighted mean
(0, 0)1001,20012
(1, 0)8080010
(0, 1)756759
(1, 1)603606

For history \((1,1)\), for example, the weighted mean is \(360/60=6\) points. The other cell means are \(12,10,\) and \(9\) points. In the saturated model, the estimated intercept is the \((0,0)\) mean, \(\hat\beta_0=12\). The two single-treatment coefficients are

$$ \hat\beta_1=10-12=-2,\qquad \hat\beta_2=9-12=-3. $$

The interaction coefficient makes the fitted mean for \((1,1)\) equal 6:

$$ \hat\beta_{12}=6-(12-2-3)=-1. $$

Thus the estimated mean difference for sustained treatment \((1,1)\) versus no treatment \((0,0)\) is \(\hat\beta_1+\hat\beta_2+\hat\beta_{12}=-6\) points. Under the assumptions stated above and the specified target population, the estimate says the mean outcome under \((1,1)\) is 6 points lower than under \((0,0)\). It is not a claim that every participant’s outcome would be 6 points lower.

Use a robust sandwich covariance estimator for the weighted estimating equations, with clustering at the participant level when the analysis data contain repeated rows per participant. Suppose the robust covariance submatrix for \((\hat\beta_1,\hat\beta_2,\hat\beta_{12})\) has diagonal entries \(0.64,0.81,0.49\), and off-diagonal entries \(0.05,0.02,0.01\). For contrast vector \(c=(1,1,1)\), the estimated variance is

$$ \widehat{\operatorname{Var}}(\hat\beta_1+\hat\beta_2+\hat\beta_{12}) =c^\mathsf{T}\widehat Vc =0.64+0.81+0.49+2(0.05+0.02+0.01)=2.10. $$

The robust standard error is \(\sqrt{2.10}=1.449\) points. Using a normal approximation, the 95% confidence interval is

$$ -6\pm1.96(1.449)=[-8.84,-3.16]\text{ points}. $$

This interval is a range of values compatible with the data and the fitted analysis under repeated-sampling assumptions; it is not a 95% probability statement about this fixed contrast. The interval excludes zero, indicating evidence against a zero mean contrast at the conventional two-sided 5% level, conditional on the model and causal assumptions. Robust standard errors address specified forms of variance misspecification and within-participant dependence; they do not correct confounding, positivity violations, or incorrect weights.

Common Pitfall: Treating Stabilization as a Causal Guarantee

A common mistake is to assume that any stabilized weights make treatment independent of all measured covariates, then fit a treatment-only outcome model. That conclusion does not follow when numerator probabilities retain baseline covariates. In the analysis here, the treatment and censoring numerators depend on prior treatment history but not on \(V\); the denominators include \(V\) and time-varying covariates needed for adjustment. This numerator choice is paired with a treatment-history-only MSM. A different numerator specification may require including baseline covariates in the MSM and standardizing its predictions over the target distribution.

A second mistake is to interpret a weighted regression coefficient as causal merely because its standard error is robust. The causal interpretation requires consistency, sequential exchangeability, positivity, adequate probability models, and a correctly specified or sufficiently flexible MSM for the target contrast. Report the numerator and denominator histories, the weight diagnostics, the outcome-model scale, the robust variance method, and the target treatment histories so that the analysis can be evaluated as a whole.

Key takeaway: An end-to-end weighted MSM analysis links its target contrast to the numerator specification, denominator histories, censoring process, diagnostics, and outcome model. Weight construction, model fitting, and robust inference are separate steps, and none can replace the causal assumptions that connect the weighted estimate to potential outcomes.

Check Your Understanding

Use these questions to check both the calculations and the reasoning behind the analysis.

  1. Why do the numerator probabilities for the treatment-history-only MSM described here omit baseline \(V\), even though \(V\) appears in the treatment denominators?
  2. A participant’s treatment weight factors are \(0.8/0.5\) and \(0.7/0.9\). Calculate the cumulative treatment weight to three significant figures.
  3. What does an effective sample size much smaller than the observed cohort size suggest, and what does it not establish?
  4. For the saturated MSM, how would you calculate the mean contrast for history \((1,0)\) versus \((0,0)\)?
  5. Name two causal assumptions that cannot be confirmed merely by observing acceptable weight distributions and post-weighting balance.
Clinical Biostats