Tutorials › Causal Inference › Fitting Marginal Structural Models With Weighted Estimating Equations

Marginal Structural Models · Tutorial 737 of 972

Fitting Marginal Structural Models With Weighted Estimating Equations

See how to fit a marginal structural model by weighting each person’s estimating-equation contribution and interpret the resulting parameters on the model’s marginal scale.

Advanced 9 min read

What You'll Learn

  • Define a marginal structural model for potential-outcome means across treatment histories.
  • Write a weighted estimating equation and explain the role of cumulative weights.
  • Derive the weighted least-squares solution for a linear marginal structural model.
  • Calculate weighted means and model coefficients from hypothetical data.
  • Interpret treatment-history coefficients as marginal contrasts under the stated model.
  • Recognize why a weighted fit is not ordinary conditional outcome regression.

Why Fit a Weighted Marginal Structural Model?

With longitudinal treatment, a person’s treatment at a later visit may depend on health measured after earlier treatment. That health can predict the outcome and be affected by earlier treatment. Ordinary regression that conditions on such variables can therefore fail to target the desired treatment-history effect. Marginal structural models (MSMs) provide a way to model population-average potential outcomes, while inverse-probability weights reweight observed treatment histories to address measured time-varying confounding under the required assumptions.

Fitting the MSM means choosing its parameters so a set of weighted estimating equations is satisfied. The weights affect each person’s contribution to those equations; they are not simply extra covariates in the outcome model. For a linear MSM, this procedure is weighted least squares. The resulting coefficients describe contrasts in marginal potential-outcome means, not conditional associations among people with the same observed covariates.

Definition: Let \(A_i=(A_{i1},\ldots,A_{iT})\) be person \(i\)’s observed treatment history, and let \(Y_i\) be the observed outcome. For a treatment history \(a=(a_1,\ldots,a_T)\), write \(Y_i^a\) for the outcome that would be observed for person \(i\) under that history. A marginal structural model specifies the population mean \(E[Y^a]\) as a function \(m(a;\beta)\) of the history and parameters \(\beta\). “Marginal” indicates that the mean averages over the target population’s covariate distribution rather than conditioning on a person’s observed covariate history.

From Cumulative Weights to an Estimating Equation

A longitudinal weight combines contributions across visits. For example, let \(q_{it}\) denote person \(i\)’s treatment-weight factor at visit \(t\), and let \(c_{it}\) denote a censoring-weight factor when censoring is being addressed. A cumulative weight for a person with the relevant observed follow-up can be written

$$ W_i=\prod_{t=1}^{T}q_{it}c_{it}. $$

The factors are determined by the chosen treatment and censoring weight models; they are not fitted as outcome-model coefficients. A person with a larger cumulative weight contributes more to the weighted equation. Intuitively, that person represents more people with similar observed treatment and follow-up patterns in the reweighted population. This interpretation depends on the causal assumptions and adequate weight models; a weight does not by itself guarantee a valid causal estimate.

For a differentiable mean model \(m(A_i;\beta)\), define \(D_i(\beta)\) as the derivative of the model mean with respect to its parameter vector. A general weighted estimating equation for a scalar outcome, with a working variance factor \(V_i(\beta)\), is

$$ U(\beta)=\sum_{i=1}^{n} W_i D_i(\beta)^{\mathsf T}V_i(\beta)^{-1} \left\{Y_i-m(A_i;\beta)\right\}=0. $$

The equation is solved for \(\hat{\beta}\). In the simple identity-link case with \(V_i=1\), write \(m(A_i;\beta)=x_i^{\mathsf T}\beta\), where \(x_i\) is the design vector. Then \(D_i=x_i\), and the equation reduces to

$$ \sum_{i=1}^{n}W_i x_i\left(Y_i-x_i^{\mathsf T}\beta\right)=0. $$

This is the weighted least-squares normal equation. It is also the condition that minimizes the weighted sum of squared residuals \(\sum_i W_i(Y_i-x_i^{\mathsf T}\beta)^2\) when the design has full column rank and the weights are positive. The objective makes clear how each person enters: person \(i\)’s squared residual is multiplied by \(W_i\). Multiplying every weight by the same positive constant changes the objective’s scale but not its minimizer.

Worked Example: A Weighted Difference Between Two Treatment Groups

Suppose a hypothetical one-visit study has the following outcome values and weights. The outcome is a symptom score in points, and the weights are treated as already calculated for this illustration.

PersonTreatment \(A_i\)Outcome \(Y_i\) (points)Weight \(W_i\)
1041
2062
3171
4193

Fit the saturated binary-treatment MSM \(m(A_i;\beta)=\beta_0+\beta_1A_i\). In this model, the weighted estimating equation for the intercept sets the weighted residual sum to zero within the \(A=0\) group, and the equation for the treatment coefficient does so within the \(A=1\) group. Thus the fitted means are the weighted means in their respective groups:

$$ \hat{\beta}_0= \frac{1(4)+2(6)}{1+2} =\frac{16}{3}=5.333\text{ points}, \qquad \hat{\beta}_0+\hat{\beta}_1= \frac{1(7)+3(9)}{1+3} =\frac{34}{4}=8.500\text{ points}. $$

Subtracting gives \(\hat{\beta}_1=8.500-5.333=3.167\) points. Under the causal assumptions for the weighting procedure and the specified MSM, this estimates a marginal mean contrast of 3.167 points for treatment versus no treatment. The arithmetic alone does not establish those assumptions; the example focuses on how the weighted equation produces the estimate.

Solving a Linear MSM With Several Treatment Indicators

For multiple treatment visits, the design vector can represent the observed history. An additive model for two binary visits is

$$ E[Y^a]=\beta_0+\beta_1a_1+\beta_2a_2. $$

Here \(\beta_1\) represents the modelled marginal mean difference between histories that differ in first-visit treatment but agree on second-visit treatment; \(\beta_2\) is defined analogously for second-visit treatment. These interpretations rely on the model’s additive form. In particular, the model has no treatment-history interaction, so it imposes the same first-visit contrast at either second-visit treatment level.

Worked Example: Solving Weighted Normal Equations

Consider hypothetical outcomes in points under four observed two-visit histories. The cumulative weights are supplied for illustration. Fit the additive MSM using \(x_i=(1,A_{i1},A_{i2})^{\mathsf T}\).

History \((A_{i1},A_{i2})\)Outcome \(Y_i\) (points)Weight \(W_i\)
(0, 0)21
(1, 0)52
(0, 1)41
(1, 1)82

The weighted normal equations are \(X^{\mathsf T}WX\hat{\beta}=X^{\mathsf T}WY\). Substituting the rows, weights, and outcomes gives

$$ \begin{pmatrix} 6&4&3\\ 4&4&2\\ 3&2&3 \end{pmatrix} \begin{pmatrix} \hat{\beta}_0\\ \hat{\beta}_1\\ \hat{\beta}_2 \end{pmatrix} = \begin{pmatrix} 32\\ 26\\ 20 \end{pmatrix}. $$

For example, the first entry on the right is \(1(2)+2(5)+1(4)+2(8)=32\); the second is \(2(5)+2(8)=26\), because only the last two histories have \(A_{i1}=1\). Solving the system gives \(\hat{\beta}_0=1.667\), \(\hat{\beta}_1=3.500\), and \(\hat{\beta}_2=2.667\) points. The fitted model is

$$ \widehat{E[Y^a]}=1.667+3.500a_1+2.667a_2. $$

For instance, the fitted marginal mean under history \((1,1)\) is \(1.667+3.500+2.667=7.834\) points (rounding the unrounded coefficients gives 7.833). The model-implied first-visit contrast is 3.500 points at either value of \(a_2\). This estimate is about population means under specified treatment histories; it is not the contrast between two people with the same measured covariates.

The weighted residuals, in the table’s row order, are approximately \(0.333,-0.167,-0.333,0.167\). Multiplication by the weights and summation makes each component of the estimating equation zero: the weighted residuals sum to zero, and so do their weighted sums within each treatment indicator. This checks that the reported coefficients solve the equations.

How Cumulative Weights Enter Every Person’s Contribution

When a cumulative weight is a product of visit-specific factors, it is the product—not just the most recent factor—that multiplies the person’s outcome-model contribution. A saturated MSM makes this especially visible: each treatment history has its own fitted mean, and its estimating equation sets the weighted residual sum in that history to zero. The fitted history-specific mean is therefore the weighted outcome mean for that history.

Worked Example: Products of Visit-Specific Factors in a Saturated MSM

Suppose eight hypothetical people have two-visit histories. There is no censoring in this illustration, and the listed factors \(q_{i1}\) and \(q_{i2}\) produce cumulative weights \(W_i=q_{i1}q_{i2}\).

HistoryPersonOutcome (points)\(q_{i1}\)\(q_{i2}\)\(W_i\)
(0, 0)12122
(0, 0)24212
(1, 0)35111
(1, 0)46212
(0, 1)54122
(0, 1)66111
(1, 1)77111
(1, 1)89224

For history \((0,0)\), the weighted estimating equation is \(2(2-\mu_{00})+2(4-\mu_{00})=0\). It gives \(\hat{\mu}_{00}=\{2(2)+2(4)\}/4=3.000\) points. For history \((1,0)\), it gives \(\hat{\mu}_{10}=\{1(5)+2(6)\}/3=5.667\) points. Similarly, \(\hat{\mu}_{01}=\{2(4)+1(6)\}/3=4.667\) points, and \(\hat{\mu}_{11}=\{1(7)+4(9)\}/5=8.600\) points.

The saturated MSM’s estimated marginal contrast for history \((1,1)\) versus \((0,0)\) is \(8.600-3.000=5.600\) points. Person 8 contributes \(4(9-\mu_{11})\) to the \((1,1)\) equation because their cumulative weight is \(2\times2=4\); using only one visit’s factor would give a different equation and estimate. This tiny dataset illustrates the calculation only; it is not evidence that the weights or causal assumptions are adequate in an applied study.

Conditions for a Causal Interpretation

Weighted estimating equations define a fitting procedure, but a causal interpretation needs more than solving them. The treatment and censoring weights must be based on suitable models for the observed histories; treatment assignment must be sequentially exchangeable given the measured history used in the weight models; and there must be positivity for the treatment histories being compared. Consistency is also required: a person’s observed outcome under their observed history must equal the corresponding potential outcome. These conditions connect the reweighted observed data to the target population of potential outcomes.

The MSM itself must also be appropriate for the estimand and scale being modelled. For example, the additive two-visit model above imposes no interaction between visits. If that restriction does not describe the target marginal means adequately, its coefficients summarize the specified working model rather than reproducing every history-specific mean. In a saturated model, each supported history has its own mean; in a more restricted model, the equations combine information across histories according to the model form.

The point estimate is the solution to the weighted equations. A complete analysis also needs appropriate uncertainty quantification, particularly because weights are usually estimated rather than known. The fitting arithmetic shown here does not, by itself, provide a standard error or confidence interval.

Common Mistakes

  • Putting time-varying confounders into the outcome regression and calling the result marginal. Conditioning on variables affected by earlier treatment can change the target and introduce bias. Use the weighted MSM to model the intended marginal potential-outcome means, with weights built from the relevant measured histories.
  • Using only the final visit’s weight factor. A longitudinal contribution uses the cumulative product of the specified visit-specific factors. Omitting earlier factors changes the estimating equation.
  • Reading an MSM coefficient as a conditional effect. In the model \(E[Y^a]=\beta_0+\beta_1a_1+\beta_2a_2\), \(\beta_1\) is a modelled contrast of marginal means across histories, not an effect conditional on a person’s observed confounder values.
  • Assuming that a successful numerical fit proves causal validity. A solver can find a root even when exchangeability, positivity, weight-model adequacy, or the MSM form is questionable. Those assumptions require substantive and diagnostic assessment.
Key takeaway: Fit an MSM by solving estimating equations in which each person’s outcome-model contribution is multiplied by their cumulative weight. The coefficients describe the specified model for marginal potential-outcome means, provided the causal assumptions and model form support that interpretation.

Check Your Understanding

Use the equations and examples above to answer the following questions.

  1. For a two-visit study with treatment factors \(q_{i1}=1.5\) and \(q_{i2}=2\), and censoring factors both equal to 1, what cumulative weight multiplies person \(i\)’s estimating-equation contribution?
  2. In a saturated binary-treatment MSM, why does the fitted mean within a treatment group equal that group’s weighted outcome mean?
  3. For the additive two-visit MSM, what assumption about the first-visit contrast is imposed by leaving out an interaction term?
  4. Explain why an MSM coefficient is not generally an outcome association conditional on the observed time-varying covariates.
  5. Name two assumptions, beyond successfully solving the weighted equations, that are needed for a causal interpretation.
Clinical Biostats