Tutorials › Causal Inference › Structural Nested Models Versus The G-Formula

Structural Nested Models and G-Estimation · Tutorial 773 of 972

Structural Nested Models Versus The G-Formula

See how g-estimation and the longitudinal g-formula identify and estimate the same sustained treatment contrast through different models and calculations.

Advanced 10 min read

What You'll Learn

  • Define a sustained treatment contrast using counterfactual outcomes under treatment regimes.
  • State the assumptions shared by g-estimation and the longitudinal g-formula.
  • Distinguish structural nested blip models from the conditional models used by the g-formula.
  • Work through both methods on the same hypothetical two-visit data-generating structure.
  • Explain why blipped-down outcomes must remove the current blip as well as later blips.
  • Identify modeling and positivity pitfalls when comparing the methods.

Two Routes to a Longitudinal Treatment Effect

When treatment and health status are recorded repeatedly, the effect of a treatment strategy cannot generally be recovered by comparing people who happened to follow different strategies. Earlier treatment can change a later health measure, and that measure can influence both subsequent treatment and the outcome. The longitudinal g-formula and structural nested models address this problem, but they organize the modeling task differently.

This tutorial compares the two methods for the same target: the mean outcome difference between sustained treatment at every visit and no treatment at any visit. The g-formula models how covariates and the outcome evolve under each regime. G-estimation models treatment blips, the contrasts associated with treatment at a particular time, and uses treatment residuals to estimate their parameters. Neither method makes treatment assignment ignorable by itself; both need appropriate causal assumptions and adequate treatment variation.

Definition: Let \(A_t\) be treatment at visit \(t\), \(L_t\) the covariate information measured before that visit, and \(Y\) the final outcome. Write \(\bar a=(a_1,\ldots,a_K)\) for a treatment regime and \(Y^{\bar a}\) for the outcome that would be observed under that regime. The sustained-treatment mean contrast is \(E[Y^{\bar 1}]-E[Y^{\bar 0}]\), where \(\bar 1\) assigns treatment at every visit and \(\bar 0\) assigns no treatment at every visit.

Assumptions Shared by the Approaches

The methods use different statistical models, but their causal interpretation rests on a common foundation. Consistency means that a person's observed outcome and covariate history agree with the corresponding counterfactuals when their observed treatment history matches the regime in question. The treatment versions represented by each value of \(A_t\) must also be sufficiently well defined for this equality to make sense. No interference is assumed: one person's treatment does not change another person's outcome.

Sequential exchangeability requires that, at each visit, treatment is independent of the relevant future counterfactual covariates and outcomes conditional on the measured history available before that treatment. In words, after conditioning on that history, there is no unmeasured common cause of current treatment and those future counterfactual quantities. Sequential positivity requires that each treatment value specified by a regime has positive probability at histories that occur under that regime. These assumptions concern treatment assignment; a correct statistical model cannot replace them.

Both approaches also require appropriate handling of missing outcomes or censoring if these occur. For clarity, the examples below assume complete follow-up. Their calculations illustrate the methods under the stated models and assumptions; they do not establish that those assumptions hold in an actual study.

What Each Method Models

For the longitudinal g-formula, the main modeling targets are the conditional distributions of covariates as they evolve and the conditional mean of the outcome given the treatment and covariate history. Under consistency, sequential exchangeability, and positivity, the mean under a fixed regime is obtained by averaging the outcome model over the covariate histories that would arise under that regime. The treatment assignment probabilities do not appear in this averaging formula, because the intervention sets treatment rather than drawing it from its observed assignment mechanism.

$$ E[Y^{\bar a}] = \int E[Y\mid \bar A=\bar a,\bar L=\bar l,W=w]\, \prod_{t=1}^{K} f(l_t\mid \bar l_{t-1},\bar a_{t-1},W=w)\, f(w)\,d\bar l\,dw $$

Here \(W\) denotes baseline covariates, and the covariate density at visit \(t\) is conditional on the treatment history through \(t-1\), since \(L_t\) is measured before \(A_t\). With discrete covariates, the integral is a sum. The same formula can be evaluated under each regime, and the two means are subtracted to obtain the contrast.

A structural nested model instead specifies treatment blips: conditional mean contrasts for treatment at a given visit, with the later treatment effects accounted for. G-estimation uses these blip models together with treatment residuals. For binary treatment, let \(p_t(H_t)=P(A_t=1\mid H_t)\), where \(H_t\) is the measured history just before \(A_t\). A key estimating condition is that the outcome after removing the current and later modeled blips has no remaining conditional mean association with \(A_t\):

$$ E\!\left[(A_t-p_t(H_t))U_t(\psi)\right]=0 $$

In this expression, \(U_t(\psi)\) is the outcome blipped down through visit \(t\): the current blip and all later blips have been removed. The parameter \(\psi\) collects the blip-model parameters. Under a correctly specified structural nested mean model and sequential exchangeability, the residual moment condition holds at the true parameter. In practice, the treatment probabilities may be estimated from models for treatment given history, and the blip parameters are chosen to make the sample moment conditions close to zero.

Important distinction: The g-formula targets regime-specific means by modeling covariate evolution and the outcome. G-estimation targets blip parameters by modeling treatment-specific contrasts and solving conditional moment equations. Both can identify a regime contrast, but their modeling requirements and estimation steps are not interchangeable.

Worked Example: The G-Formula for Two Visits

Worked Example: The G-Formula for Two Visits

Suppose a hypothetical two-visit setting has treatment \(A_1\), then a binary health measure \(L_2\), then treatment \(A_2\), followed by outcome \(Y\). Assume the covariate and outcome models are

$$ P(L_2=1\mid A_1=0)=0,\qquad P(L_2=1\mid A_1=1)=1, \qquad E[Y\mid A_1,L_2,A_2]=10+5L_2+2A_1+(3+4A_1)A_2. $$

These are hypothetical values chosen to make the calculations transparent. Suppose treatment is randomized at visit 1 with probability \(0.5\), and at visit 2 its probability is \(0.25\) when \(A_1=0\) and \(0.75\) when \(A_1=1\). Thus both treatment values occur with positive probability at the histories relevant to either sustained regime. Assume consistency, no interference, sequential exchangeability, and the stated conditional models.

For the sustained no-treatment regime, \(A_1=0\) and \(A_2=0\). The covariate model gives \(L_2=0\), so the g-formula reduces here to the outcome mean at that history:

$$ E[Y^{(0,0)}] = \sum_{l_2} E[Y\mid A_1=0,L_2=l_2,A_2=0]P(L_2=l_2\mid A_1=0) =10+5(0)+2(0)+(3+4(0))(0)=10. $$

Under sustained treatment, \(A_1=1\) and \(A_2=1\), and the covariate model gives \(L_2=1\). Therefore

$$ E[Y^{(1,1)}] =10+5(1)+2(1)+(3+4(1))(1) =10+5+2+7=24. $$

The sustained-treatment mean contrast is \(24-10=14\) outcome units. The assignment probabilities do not enter these regime-specific calculations: the formula sets treatment to the specified values and averages over the covariate distribution under those values.

Worked Example: G-Estimation on the Same Structure

Worked Example: Blipping Down the Outcome

Use the same hypothetical model. At visit 2, the treatment blip is \((3+4A_1)A_2\): the effect of \(A_2\) is 3 outcome units when \(A_1=0\) and 7 when \(A_1=1\). Removing this later blip gives

$$ U_2(\psi)=Y-(3+4A_1)A_2. $$

Substituting the outcome model shows exactly what remains:

$$ U_2(\psi) =10+5L_2+2A_1+(3+4A_1)A_2-(3+4A_1)A_2 =10+5L_2+2A_1. $$

The visit-1 blip under this model is \(7A_1\). It includes the direct \(2A_1\) contribution and the \(5L_2\) contribution, since \(L_2=A_1\) in this hypothetical setting. The outcome used at visit 1 must therefore remove that current blip as well:

$$ U_1(\psi)=U_2(\psi)-7A_1 =10+5L_2+2A_1-7A_1=10, $$

where the last equality uses \(L_2=A_1\). If \(p_1(H_1)=0.5\), the visit-1 moment is

$$ E[(A_1-0.5)U_1(\psi)] =E[(A_1-0.5)10] =10\{E[A_1]-0.5\}=0. $$

At visit 2, \(H_2\) includes \(A_1\) and \(L_2\), and \(U_2=10+5L_2+2A_1\) is fixed given that history. Consequently, using the specified treatment probability \(p_2(H_2)\),

$$ E[(A_2-p_2(H_2))U_2(\psi)\mid H_2] =U_2(\psi)\,E[A_2-p_2(H_2)\mid H_2]=0. $$

The g-estimated blips therefore imply a sustained contrast of \(7+7=14\) outcome units: the visit-1 blip is 7, and the visit-2 blip under \(A_1=1\) is also 7. This agrees with the g-formula calculation. The agreement is expected here because both calculations use the same hypothetical data-generating structure and assumptions.

Worked Example: A Different Regime Contrast

Worked Example: Treating Only at Visit 2

Consider the contrast between regime \((0,1)\) and regime \((0,0)\). Under both regimes, \(A_1=0\), so \(L_2=0\). The g-formula gives

$$ E[Y^{(0,1)}]=10+5(0)+2(0)+(3+4(0))(1)=13, \qquad E[Y^{(0,0)}]=10. $$

The contrast is \(13-10=3\) outcome units. G-estimation gives the same answer by evaluating the visit-2 blip at \(A_1=0\): \((3+4(0))\times 1=3\). This example shows why a blip parameter is not automatically the effect of every possible regime contrast; the relevant blip must be evaluated at the history and treatment values specified by the contrast.

Why the G-Formula Calculation Works

The g-formula follows from iterated expectation and the causal assumptions. For two visits, under a fixed regime \((a_1,a_2)\), first average the outcome over the covariate distribution that would occur after setting \(A_1=a_1\). Then average over baseline covariates if present. Sequential exchangeability allows the observed conditional outcome and covariate distributions at the corresponding histories to represent those under the intervention; consistency links those observed distributions to the counterfactuals.

In the two-visit example, this reduces to

$$ E[Y^{(a_1,a_2)}] =\sum_{l_2} E[Y\mid A_1=a_1,L_2=l_2,A_2=a_2]\, P(L_2=l_2\mid A_1=a_1). $$

For \((0,0)\), the only covariate value with positive probability under \(A_1=0\) is \(L_2=0\); for \((1,1)\), it is \(L_2=1\). Substitution gives the two means calculated above. In more complex settings, the same logic is applied successively across visits, summing or integrating over each evolving covariate distribution.

Modeling and Interpretation: A Comparison

FeatureLongitudinal g-formulaStructural nested model with g-estimation
Main modeled quantitiesConditional covariate distributions and conditional outcome meanVisit-specific treatment blips; treatment probabilities are used in moment equations
Estimation targetRegime-specific means, then their contrastBlip parameters, then the contrast implied by the blips
Role of treatment probabilitiesNot part of the intervention mean formulaUsed to form treatment residuals such as \(A_t-p_t(H_t)\)
Key model riskMisspecification of covariate or outcome models can bias regime meansMisspecification of the blip model can bias blip parameters and implied contrasts
Shared causal requirementsConsistency, sequential exchangeability, and positivityConsistency, sequential exchangeability, and positivity

Neither method is universally preferable. The g-formula makes the covariate evolution under each regime explicit, but may require many conditional models. G-estimation can focus the model on treatment effects and avoid specifying a full outcome regression for the intervention mean, but its blip structure must be adequate and its moment equations must be informative. In either case, adequate fit to observed data alone does not verify the causal assumptions.

Common Mistakes

  • Leaving the current blip in the moment-equation outcome. Removing only later effects does not generally make the remaining outcome conditionally unrelated to current treatment. In the additive example, if one used \(U_2=Y-(3+4A_1)A_2\) in the visit-1 moment, the term \(7A_1\) would remain. With \(p_1=0.5\), its contribution would be \(7E[(A_1-0.5)A_1]=7(0.25)=1.75\), not zero. The correction is to subtract the current blip too, defining \(U_1=U_2-7A_1\).
  • Treating the g-formula and g-estimation as different causal assumptions. Their model targets differ, but neither removes the need for consistency, sequential exchangeability, and positivity.
  • Using observed treatment-group means as regime means. People receiving a treatment at a later visit can differ in measured history from those not receiving it. The g-formula standardizes over the covariate history under the regime; g-estimation uses conditional treatment-residual equations.
  • Assuming a blip coefficient is the sustained-regime effect. A blip is tied to a visit and specified history. The regime contrast must be assembled by evaluating the relevant blips under the regime.
Key takeaway: For the same sustained treatment contrast, the longitudinal g-formula averages a modeled outcome over regime-specific covariate histories, while g-estimation solves moment conditions for modeled treatment blips. Correct identification requires the causal assumptions shared by both methods, and correct estimation additionally depends on the method-specific models.

Check Your Understanding

Use the definitions and hypothetical model above to answer the following.

  1. For the sustained regimes \((1,1)\) and \((0,0)\), which conditional distributions are averaged in the g-formula?
  2. In the two-visit example, why does \(U_1\) have to subtract \(7A_1\) after the visit-2 blip is removed?
  3. What role does \(p_t(H_t)\) play in a g-estimation moment equation, and why does it not appear in the intervention mean formula?
  4. If the visit-2 blip is \((3+4A_1)A_2\), what is its value under \(A_1=0,A_2=1\)?
  5. Name one model misspecification risk specific to the g-formula and one specific to g-estimation.
Clinical Biostats