Ask Mallard
Analysis method

Marginal structural models with IPTW

5 min read

A marginal structural model uses treatment weights to compare treatment histories when earlier treatment changes later confounders.

Fit

When to use it, and when not to

Use it when

  • A measured marker both guides later treatment and responds to earlier treatment.
  • You can reconstruct treatment decisions and confounders before each decision.

Not when

Before you start

What you need

Decide these first
  1. Treatment histories and follow-uptargetDefine sustained or changing strategies and a shared time zero.
  2. Data before each treatment decisionRecord previous treatment and confounders measured before the current decision.
  3. Weight and outcome modelssummaryMeasureChoose the effect scale, numerator, denominator, censoring model and diagnostics before fitting.
It rests on these
  1. Measured history explains each treatment decision relevant to the outcome.How to check: This is sequential exchangeability. Use clinical knowledge to identify unmeasured reasons for treatment changes.
  2. Each strategy is possible within relevant measured histories.How to check: Inspect support over time. Extreme weights may expose sparse support; truncating weights trades bias against precision.
  3. Each strategy represents a well-defined treatment.How to check: Specify dose, timing and versions. Rule out interference or account for it in the design.
  4. Weight and outcome models are suitable.How to check: Check weighted balance at each visit, weight tails and effective sample size. Add censoring weights when dropout needs them.
  5. Choose a missing-data method because of a stated assumption.How to check: Missing completely at random (MCAR) means gaps depend on neither observed nor unseen data. Missing at random (MAR) means recorded data explain gaps. Under MAR, suitable multiple imputation may help; it is not inherently better. Missing not at random (MNAR) means unseen values still predict gaps. Under plausible MNAR, add a delta or tipping-point sensitivity analysis. Dropping people with missing exposure can cause selection bias.

Plain language

How it works

Inverse probability of treatment weights (IPTW) give more weight to histories that were unlikely given measured health. Multiply each visit’s probability ratio across visits. The denominator uses past treatment and confounders; a stabilized numerator uses a smaller history. If baseline covariates enter the numerator, include them in the outcome model and standardize as needed.

Fit the effect of the strategies

Fit the chosen marginal structural outcome model using these weights. Use patient-level robust uncertainty or a bootstrap that re-estimates weights. The final effect compares specified strategies under the assumptions. A weighted model does not make those assumptions true.

Why ordinary adjustment can fail
A causal diagram over two treatment decisions. An earlier laboratory value affects earlier treatment. Earlier treatment changes the later laboratory value, which then affects later treatment and also affects the outcome. Both treatments affect the outcome.Treatment-confounder feedback: one variable is both a confounder and on the causal pathLaboratory value,earlierTreatment,earlierLaboratory value,laterTreatment, laterOutcomeThe later value must be adjusted for, because it confounds later treatment, and must not be, because itcarries part of the earlier treatment's effect. No single regression does both.
Conceptual diagram. It shows the structure of the idea, not data from any study.

Worked example

A worked example

Invented for illustration
Setting
Treatment can change at each of two clinic visits.
Question
How much weight does one observed treatment history receive?
Approach
The observed treatment probabilities are 0.50 and 0.25 given full history. Numerator probabilities given past treatment alone are 0.50 and 0.50.
Result
The numerator product is 0.25; the denominator product is 0.125. The stabilized weight is 0.25 / 0.125 = 2.
What it means
This patient contributes twice the usual weight. It is a weight calculation, not a fitted treatment effect.

In practice

Recent studies PubMed search · not vetted

Searching PubMed…

Watch out

Common mistakes

The one to remember

Weights cannot recover unmeasured treatment decisions or create support for impossible treatment histories. A stable-looking weight distribution does not establish exchangeability.

  • Adjusting the final model for a treatment-affected confounder as if it were baseline.Instead: Use the time-ordered history in the weight model. Ensure the final model matches the causal contrast.
  • Ignoring untreated visits.Instead: Use the probability of the treatment actually observed, including no treatment.
  • Truncating extreme weights without reporting it.Instead: Report the thresholds and how estimates change under other choices.

Inside Mallard

How Mallard uses this

Plans do not link to this method yet. You can find it in Learn and the Atlas.

No Mallard code example points to this page.
Atlas node analysis.marginal_structural_iptw, the id a plan cue records.

Related Learn pages

Related designs and methods

Evidence

Sources & further reading

  1. Marginal structural models and causal inference in epidemiology (opens in a new tab) · Epidemiology · doi 10.1097/00001648-200009000-00011
  2. Marginal structural models to estimate the causal effect of zidovudine on the survival of HIV-positive men (opens in a new tab) · Epidemiology · doi 10.1097/00001648-200009000-00012
  3. Constructing inverse probability weights for marginal structural models (opens in a new tab) · Am J Epidemiol · doi 10.1093/aje/kwn164
Prepared with AI assistance for the owner-approved one-method wave 1. Indexed sources were checked by PMID, title, authors, year and DOI against PubMed on 2026-11-06. Record verification is not methodological approval. Robins and colleagues introduce the model and treatment weighting. Hernán and colleagues apply it to treatment-confounder feedback. Cole and Hernán explain assumptions, diagnostics and truncation.
Last source review: 2026-11-06
AI-generated educational content
Mallard uses reputable methodological and reporting sources, but this material may contain errors or omit important context. Verify important methodological decisions with the cited sources and, when appropriate, a qualified research methodologist or statistician.