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.
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.
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\):
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.
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
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:
Under sustained treatment, \(A_1=1\) and \(A_2=1\), and the covariate model gives \(L_2=1\). Therefore
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
Substituting the outcome model shows exactly what remains:
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:
where the last equality uses \(L_2=A_1\). If \(p_1(H_1)=0.5\), the visit-1 moment is
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)\),
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
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
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
| Feature | Longitudinal g-formula | Structural nested model with g-estimation |
|---|---|---|
| Main modeled quantities | Conditional covariate distributions and conditional outcome mean | Visit-specific treatment blips; treatment probabilities are used in moment equations |
| Estimation target | Regime-specific means, then their contrast | Blip parameters, then the contrast implied by the blips |
| Role of treatment probabilities | Not part of the intervention mean formula | Used to form treatment residuals such as \(A_t-p_t(H_t)\) |
| Key model risk | Misspecification of covariate or outcome models can bias regime means | Misspecification of the blip model can bias blip parameters and implied contrasts |
| Shared causal requirements | Consistency, sequential exchangeability, and positivity | Consistency, 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.
Check Your Understanding
Use the definitions and hypothetical model above to answer the following.
- For the sustained regimes \((1,1)\) and \((0,0)\), which conditional distributions are averaged in the g-formula?
- In the two-visit example, why does \(U_1\) have to subtract \(7A_1\) after the visit-2 blip is removed?
- 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?
- If the visit-2 blip is \((3+4A_1)A_2\), what is its value under \(A_1=0,A_2=1\)?
- Name one model misspecification risk specific to the g-formula and one specific to g-estimation.