Why the Longitudinal G-Formula Averages Over Histories
A treatment regime determines which treatment is assigned at each time, possibly using covariates measured along the way. But a regime-specific mean is not generally the outcome mean for one “typical” covariate history. The regime can change the distribution of later covariates, and the outcome mean can vary across those histories. The longitudinal g-formula makes this averaging explicit.
We derive the formula by iterated expectations. At each step, condition on the current history, take the conditional outcome mean, and then average over the next covariate value generated under the regime. This derivation separates two ideas: the algebra of averaging counterfactual histories, and the assumptions needed to replace counterfactual distributions with observed-data distributions.
Notation and the History-Averaging Formula
Consider treatment times \(t=0,\ldots,K\). Let \(L_0\) be baseline covariates, and let \(L_t\), for \(t=1,\ldots,K\), be covariates measured before treatment \(A_t\). The outcome \(Y\) is measured after \(A_K\). Write \(\bar L_t=(L_0,\ldots,L_t)\) and \(\bar A_t=(A_0,\ldots,A_t)\). The history just before treatment \(A_t\) is \(H_t=(\bar L_t,\bar A_{t-1})\), with \(\bar A_{-1}\) empty.
A regime \(d=(d_0,\ldots,d_K)\) assigns \(A_t=d_t(H_t)\). A static regime is a special case in which the assigned treatment does not vary with history. Superscript \(d\) denotes the counterfactual variables that would arise under this regime; the target mean is \(E[Y^d]\).
Here the conditional distributions in the display must be interpreted as the distributions of covariates and outcomes under the regime, or as observed-data conditional distributions when the causal identification assumptions justify that substitution. The display does not require the outcome itself to be discrete or continuous in a particular way: provided its conditional mean exists, the formula averages that mean rather than integrating the full outcome distribution.
Derivation by Iterated Expectations
The basic identity is the law of iterated expectations: if \(E|Y^d|<\infty\), then \(E[Y^d]=E\{E[Y^d\mid \bar L_K^d]\}\). Conditioning first on the final covariate history gives an outcome mean for each history. Conditioning successively on shorter histories then averages over the covariates that can occur under the regime.
To see the recursion, define \(g_K(\bar l_K)=m^d(\bar l_K)\). For \(t=K-1,\ldots,0\), define \(g_t(\bar l_t)=\int g_{t+1}(\bar l_t,l_{t+1})Q_t^d(d l_{t+1}\mid\bar l_t)\). Each \(g_t\) is the mean of the remaining future outcome after averaging the next covariate and all subsequent covariates according to their regime-specific laws. Applying iterated expectations from \(L_K^d\) backward to \(L_0^d\) gives \(E[Y^d]=\int g_0(l_0)F_0^d(d l_0)\). Substituting the definitions of the \(g_t\)'s yields the displayed formula. All expectations are well-defined because \(E|Y^d|<\infty\); conditional expectations are integrable, and the successive integrations are conditional-expectation operations. \(\square\)
For the usual observed-data version, consistency, sequential exchangeability, and positivity are needed. In brief, consistency links observed outcomes and covariates to the counterfactuals for the treatment actually received; sequential exchangeability requires treatment assignment at each time to be independent of relevant future counterfactuals conditional on the measured history; and positivity requires the regime’s assigned treatment to have positive conditional probability at histories it reaches. Under these conditions, the regime-specific covariate and outcome laws in the derivation can be represented by observed-data conditional laws evaluated at the regime’s treatment choices. This tutorial derives the history average; the identification argument explains that substitution in detail.
Worked Example: Two Binary Covariate Histories
There are two treatment times, \(A_0\) and \(A_1\), and one binary intermediate covariate \(L_1\). Consider the static regime \(A_0=0,A_1=0\). Suppose under this regime \(P(L_1=1)=0.30\), and the conditional outcome means are \(E[Y\mid L_1=0,A_0=A_1=0]=0.10\) and \(E[Y\mid L_1=1,A_0=A_1=0]=0.50\). Calculate the regime-specific mean using these regime-compatible conditional laws.
There are two possible histories. The formula averages the outcome mean in each history using that history’s regime probability: $$ E[Y^d]=(1-0.30)(0.10)+(0.30)(0.50) =0.70(0.10)+0.30(0.50) =0.07+0.15=0.22. $$
Thus the regime-specific mean is \(0.22\). Averaging the two conditional means equally would give \(0.30\), which is incorrect because the histories do not have equal probability under this regime. If \(Y\) is binary, the mean is also the regime-specific risk: \(22\%\).
Worked Example: A Regime That Uses the Covariate
Let \(L_1\) be binary and consider the dynamic regime \(d_0=1\), followed by \(d_1(L_1)=L_1\). Under \(A_0=1\), suppose \(P(L_1=1)=0.60\). Under this regime, the conditional outcome means are \(0.10\) for history \((L_1=0,A_1=0)\) and \(0.40\) for history \((L_1=1,A_1=1)\). Find the regime-specific mean.
The rule assigns \(A_1=0\) when \(L_1=0\), and \(A_1=1\) when \(L_1=1\). Thus the two possible histories have probabilities \(0.40\) and \(0.60\), respectively. Substitution gives $$ E[Y^d]=0.40(0.10)+0.60(0.40)=0.04+0.24=0.28. $$
The conditional outcome mean must be evaluated at the treatment prescribed for each history. Using the mean for \(A_1=1\) in both histories would not evaluate this regime; it would replace the rule with a different treatment assignment.
Worked Example: Integrating a Continuous Covariate
Suppose \(L_1\), under the regime \(A_0=A_1=0\), has distribution \(N(3,4)\), where the second parameter is the variance. Suppose the conditional mean outcome under that regime is \(E[Y\mid L_1=l,A_0=A_1=0]=10+2l\). Calculate the regime-specific mean.
The g-formula integrates the conditional mean against the normal density: $$ E[Y^d]=\int_{-\infty}^{\infty}(10+2l)f_{L_1^d}(l)\,dl. $$
By linearity of expectation and \(E[L_1^d]=3\), $$ E[Y^d]=10+2E[L_1^d]=10+2(3)=16. $$
The variance \(4\) does not enter this calculation because the conditional mean is linear in \(l\). For a nonlinear conditional mean, the full distribution, including its variance, can matter. For example, \(E[(L_1^d)^2]=\operatorname{Var}(L_1^d)+\{E[L_1^d]\}^2=4+9=13\), not \(3^2=9\).
When the Formula Is Useful—and Where It Can Fail
The g-formula is useful because it makes clear which histories contribute to a regime’s mean and how their probabilities are determined. It also allows treatment-confounder feedback: a treatment can affect a later covariate, and that covariate can influence both later treatment and the outcome. The regime-specific covariate distribution carries the consequences of earlier treatment forward into the outcome average.
A practical parametric g-computation analysis estimates conditional models for covariate evolution and the outcome, then evaluates the history average using those fitted models. This is different from inverse-probability weighting, which constructs weights from treatment probabilities rather than explicitly averaging fitted outcome means across covariate histories. The formula itself does not guarantee that either strategy is reliable: parametric g-computation depends on adequate conditional models, while weighting depends on treatment-probability models and can be unstable when probabilities are small.
Several checks follow directly from the derivation. Verify that the regime is applied at the correct time and uses only the history available then. Check that each conditional model uses the correct past history and that the fitted covariate distributions generate plausible histories. Look for sparse or unsupported histories, implausible predictions, and strong sensitivity to model choices. If a regime assigns a treatment rarely observed in a history it reaches, the observed-data version may require extrapolation; a precise-looking estimate does not remove that problem.
The formula also has limits. It identifies a causal mean from observed data only when the requisite causal assumptions hold, and its parametric implementation can be biased if the conditional models are misspecified. Continuous histories make direct enumeration impossible, and high-dimensional histories can make model fitting and support assessment difficult. The history-integral representation remains conceptually valid, but computation may require numerical integration or simulation.
Check Your Understanding
Answer each question, then compare with the brief solutions below.
- Under a regime, \(P(L_1=1)=0.25\), and the conditional outcome means for \(L_1=0\) and \(L_1=1\) are \(0.20\) and \(0.60\). What is the regime-specific mean?
- Why does a dynamic regime require evaluating conditional outcome means at potentially different treatment values in different covariate histories?
- If \(L_1^d\sim N(2,9)\) and the conditional mean is \(E[Y^d\mid L_1^d=l]=5+l^2\), calculate \(E[Y^d]\).
- Name two assumptions needed to identify the observed-data g-formula as a causal regime mean.
- What is the error in using the overall observed distribution of a time-varying covariate in every term of the formula?
Solutions. (1) \(0.75(0.20)+0.25(0.60)=0.15+0.15=0.30\). (2) The regime’s assigned treatment can depend on history, so the treatment value and corresponding conditional mean must follow the rule in each history. (3) Since \(E[(L_1^d)^2]=9+2^2=13\), the mean is \(5+13=18\). (4) Examples are consistency, sequential exchangeability, and positivity; any two suffice. (5) It ignores how prior regime treatments affect later covariate distributions, so it averages over the wrong histories.