Why Small Implementation Choices Matter
Dynamic-regime g-computation can be conceptually simple: use fitted models to predict outcomes under a treatment rule, then average those predictions. But each part of that sentence matters. The rule must determine the treatments in the simulated histories; the histories must be generated under that rule; and the resulting predictions must be averaged over the population named by the estimand. A program can produce a precise number while failing one of these steps.
This tutorial focuses on three errors that can change the estimand or break its causal interpretation: retaining observed treatments instead of applying the rule, averaging over the wrong population, and treating a fitted conditional mean as though it were a regime-specific causal effect.
A causal interpretation requires more than fitting an outcome model. In the usual longitudinal setting, the identification conditions include consistency (the observed outcome agrees with the counterfactual outcome under the treatment history actually received), no interference between individuals, sequential exchangeability (no unmeasured confounding of each treatment given the measured past), and positivity (the treatment choices required by the regime are supported at the relevant histories). G-computation also depends on correctly specifying the conditional models used to represent covariate evolution and the outcome, or on an estimation approach with appropriate protection against model misspecification.
The Target Calculation
For discrete covariates, the two-treatment regime mean has the form below. Sums can be replaced by integrals for continuous covariates. The key feature is that the distribution of \(L_1\) is generated conditional on the treatment assigned by the regime, and the outcome model is evaluated at both regime-assigned treatments.
This expression separates three operations: start with the target distribution of baseline covariates; generate later covariates under the treatment assigned so far; and predict the outcome at the treatments assigned by the regime. Errors often arise when one of these distributions or treatment assignments is quietly replaced by an observed-data quantity.
Error 1: Retaining Observed Treatments in Simulated Histories
A common mistake is to obtain predictions for people’s observed treatment histories and then average them, even though the intended estimand concerns a specified regime. For a regime-specific mean, the observed \(A_0\) and \(A_1\) are not the treatments to plug into the prediction step. The analyst must set \(A_0\) according to \(d_0\), generate later covariates under that assigned \(A_0\), and set \(A_1\) according to \(d_1\).
Worked Example: Applying an Adaptive Rule Rather Than Observed Treatment
Suppose a hypothetical cohort is evaluated under a rule that assigns \(A_0=1\) to everyone, then assigns \(A_1=1\) if \(L_1\) is high and \(A_1=0\) otherwise. Under the assigned first treatment, the fitted covariate model gives \(P(L_1=\text{high}\mid A_0=1)=0.40\). For illustration, suppose the fitted conditional outcome mean is \(\widehat{E}(Y\mid A_0,A_1)=10+2A_0+3A_1\), with \(Y\) measured in outcome units.
Under the rule, 40% of the simulated histories have \(A_1=1\), and 60% have \(A_1=0\). Every history has \(A_0=1\). The predicted regime mean is therefore
Now suppose a mistaken calculation retains observed treatment histories, which consist of 50% \((A_0,A_1)=(0,0)\), 25% \((1,1)\), and 25% \((1,0)\). Averaging predictions over those histories gives
The 11.75 is an average prediction over the stated observed treatment mix, not the mean under the adaptive rule. The discrepancy is not repaired by having a correctly calculated average: the treatment histories used in the calculation answer a different question. The example assumes the stated outcome and covariate models are adequate for the illustration; a real causal interpretation would additionally require the identification conditions described above.
Forgetting to replace observed treatments can happen in either a manual calculation or code. A particularly subtle version assigns \(A_0\) according to the regime but then uses observed \(A_1\), or predicts \(L_1\) from its observed distribution rather than from the distribution conditional on the assigned \(A_0\). A valid simulated history must follow the rule at every treatment time and must propagate the resulting history forward.
Error 2: Averaging Over the Wrong Population
The target population is part of the estimand. If the goal is \(E(Y^d)\) for a specified population, predictions must be averaged according to that population’s covariate distribution. Averaging strata equally, averaging only records with complete follow-up, or averaging a convenience sample can instead target a different population. These alternatives are not harmless changes in presentation.
Worked Example: Preserving the Target Population Mix
Suppose a hypothetical target population contains 100 people: 80 are in a lower-risk baseline stratum and 20 are in a higher-risk stratum. Under the same specified regime, the fitted counterfactual mean outcome is 10 units for the lower-risk stratum and 30 units for the higher-risk stratum. Assume for this calculation that these predictions are appropriate for the target population.
The target-population mean weights each stratum by its share of the population:
An analyst who averages the two stratum means equally obtains \((10+30)/2=20\) units. That calculation describes a hypothetical population with equal representation of the two strata, not the stated target population. Another analyst who averages predictions only among 50 lower-risk people obtains 10 units, which is also not the target mean. The correct weighting comes from the target population distribution, not from a convenient subset or the number of rows that happen to appear in a model output.
In individual-level Monte Carlo g-computation, the same principle means averaging counterfactual predictions over individuals representing the target population. If the data used for that averaging are a sample from a different population, the desired target distribution must be supplied or otherwise justified. Also check that repeated simulated records are not unintentionally counted as additional target individuals: simulation replication improves approximation to a prediction but does not change the population weights in the estimand.
Error 3: Confusing a Conditional Mean With a Regime Effect
A fitted conditional outcome mean answers a conditional prediction question, such as the expected outcome at specified values of \(L_0,A_0,L_1,A_1\). A regime-specific mean instead averages predictions over the histories that would arise under the regime. A regime contrast compares two such marginal means. The model coefficient or the difference between two predictions at a fixed covariate history need not equal that contrast, especially when an earlier treatment changes the distribution of later covariates.
Worked Example: A Conditional Treatment Difference Is Not the Regime Contrast
Consider a hypothetical setting with binary \(L_1\) and the rule \(A_1=0\) at the second visit. Compare two regimes: \(d^{(1)}\) sets \(A_0=1\), while \(d^{(0)}\) sets \(A_0=0\). Suppose the conditional outcome mean under \(A_1=0\) is \(10+2A_0+4L_1\) units, and the covariate model gives
At a fixed value of \(L_1\), the fitted conditional mean difference for changing \(A_0\) from 0 to 1 is 2 units. But the regime means also account for the different \(L_1\) distributions. Under \(d^{(1)}\),
Under \(d^{(0)}\),
The regime contrast is \(15.2-10.8=4.4\) units, not the fixed-\(L_1\) conditional difference of 2 units. The additional difference arises because the first treatment changes the distribution of \(L_1\) in this example. This arithmetic illustrates why g-computation combines an outcome model with the covariate-history distribution under each regime. It does not establish that a conditional model coefficient is generally causal; that interpretation requires its own assumptions and estimand.
A Short Justification for the Averaging Step
Why does the calculation average outcome predictions over regime-generated histories? Begin with the law of total expectation: a population mean is the average of conditional means over the distribution of the conditioning variables. Under regime \(d\), the relevant history has \(A_0=d_0(L_0)\) and \(A_1=d_1(L_0,L_1)\). Thus, conditioning first on \(L_0,L_1\), the regime mean is the conditional outcome mean evaluated at those assigned treatments, averaged over the regime’s covariate-history distribution.
The second equality uses the identification conditions: consistency links counterfactual and observed outcomes under matching treatment histories; sequential exchangeability permits the observed conditional models to represent the relevant counterfactual quantities; and positivity requires support for the assigned treatment choices. This justification also exposes the three errors: using observed treatments changes the conditional arguments, using the wrong population changes \(P(L_0)\), and reporting a conditional mean without averaging omits the expectation over regime-generated histories.
Practical Audit and Common Pitfall
Before interpreting a dynamic-regime result, trace a single hypothetical individual through the calculation. Confirm which treatment is assigned at each visit, what covariate distribution is used after that assignment, which outcome prediction is evaluated, and how much weight the individual contributes to the final target-population average.
State the regime, outcome scale, follow-up time, and target population. Distinguish a regime mean \(E(Y^d)\) from a contrast such as \(E(Y^{d^{(1)}})-E(Y^{d^{(0)}})\).
At each visit, use the regime’s decision function evaluated at the simulated history. Do not substitute the individual’s observed treatment at that visit.
Generate or integrate later covariates conditional on the treatments assigned so far, rather than automatically reusing their observed histories.
Evaluate the outcome model at regime-assigned treatments, then average according to the intended target population distribution.
Assess whether required treatment choices are supported at relevant histories and whether the conditional models and identification assumptions are credible.
Common mistake: “The outcome model is fitted, so averaging its predictions over the observed records estimates the policy effect.” This reasoning confuses model fitting with the intervention calculation. The correction is to identify the target estimand first, construct each history under the specified regime, and average the resulting predictions over the target population. A fitted model alone neither enforces the regime nor selects the correct population weights.
Check Your Understanding
For each question, identify which part of the regime-specific calculation is at issue.
- A simulation assigns the first treatment according to a rule but retains each person’s observed second treatment. What estimand does this fail to calculate, and what should replace the observed treatment?
- A target population is 70% in one baseline stratum and 30% in another. Why does averaging the two stratum-specific predictions equally generally change the target mean?
- In the third worked example, what two components explain why the regime contrast differs from the conditional treatment difference at fixed \(L_1\)?
- Name the covariate distribution and outcome-model prediction used in the two-treatment g-formula expression.
- Why does a fitted conditional outcome model, by itself, not establish a causal regime effect?