Tutorials › Propensity Score Matching and Instrumental Variables › Deriving the G-Formula for a Binary Treatment

Causal Effects, Ignorability and Positivity · Tutorial 20 of 699

Deriving the G-Formula for a Binary Treatment

Learn how consistency, conditional exchangeability, and positivity lead to the g-formula for each mean potential outcome and the average treatment effect.

Beginner 10 min read

What You'll Learn

  • State the g-formula for the mean potential outcome under each treatment level.
  • Derive the formula from iterated expectation, conditional exchangeability, and consistency.
  • Explain why both treatment levels must be represented across the target covariate distribution.
  • Distinguish the population covariate distribution in the formula from treatment-group distributions.
  • Apply the formula to finite strata and a continuous covariate.
  • Recognize how missing treatment overlap can leave potential-outcome means unidentified.

From Potential Outcomes to Observed Conditional Means

For a binary treatment, the causal question often concerns the mean outcome that would occur if everyone in a population received treatment, compared with the mean if everyone received control. The obstacle is that each person receives only one treatment level, so only one of their two potential outcomes is observed. The g-formula shows how, under explicit assumptions, observed outcomes can identify each population mean potential outcome: first compare outcomes within levels of pretreatment covariates, then average those conditional means over the population distribution of the covariates.

Let \(A\in\{0,1\}\) denote treatment assignment, where 1 is treatment and 0 is control. Let \(Y\) be the observed outcome, \(Y(1)\) the outcome that would be observed under treatment, and \(Y(0)\) the outcome under control. Let \(X\) denote the set of measured pretreatment covariates. The target population mean under treatment level \(a\) is \(E[Y(a)]\). The average treatment effect (ATE) is \(E[Y(1)]-E[Y(0)]\).

Definition: For \(a\in\{0,1\}\), the binary-treatment g-formula is $$ E[Y(a)] = \int E[Y\mid A=a,X=x]\,dF_X(x), $$ where \(F_X\) is the covariate distribution in the target population. If \(X\) has a finite set of values, the integral is a sum: $$ E[Y(a)] = \sum_x E[Y\mid A=a,X=x]P(X=x). $$ The corresponding ATE is the treatment-level mean given by the formula for \(a=1\), minus the control-level mean given by the formula for \(a=0\).

The conditional mean \(E[Y\mid A=a,X=x]\) describes observed outcomes among individuals with covariates \(x\) who received level \(a\). It is not automatically a causal mean. The assumptions below are what allow it to stand in for the corresponding potential-outcome mean, and positivity is what ensures that this observed conditional mean is available across the target population.

Assumptions for the Identification Formula

The formula identifies a population quantity from observed data only under assumptions about treatment assignment, treatment versions, and covariate support. In this setting, consistency captures the link between a person's received treatment and observed outcome; conditional exchangeability says that, within covariate levels, treatment assignment provides no further information about the potential outcomes; and positivity ensures that both treatment levels can occur across the covariate values in the target population.

Assumptions:
  • Consistency: If \(A=a\), then \(Y=Y(a)\). The treatment levels must also refer to sufficiently well-defined interventions for this link to be meaningful.
  • Conditional exchangeability: \(\{Y(0),Y(1)\}\perp A\mid X\). Given \(X\), the potential outcomes are independent of treatment assignment.
  • Positivity: For each \(x\) in the target population's covariate support and each \(a\in\{0,1\}\), \(0<P(A=a\mid X=x)<1\).

The target population matters. The distribution \(F_X\) is the distribution of pretreatment covariates in the population whose mean potential outcomes are sought. It is not, in general, the distribution of covariates among treated individuals or among control individuals. Using a treatment-group distribution instead changes the averaging operation and may no longer yield the population mean \(E[Y(a)]\).

Deriving the G-Formula

The derivation starts by partitioning a potential-outcome mean across covariate values. For a discrete \(X\), this is the law of total expectation; for a continuous \(X\), the same argument uses an integral. Conditional exchangeability then permits replacing the conditional mean of a potential outcome with that among people who received the corresponding treatment. Consistency finally connects that observed outcome to the potential outcome.

$$ \begin{aligned} E[Y(a)] &= \int E[Y(a)\mid X=x]\,dF_X(x)\\ &= \int E[Y(a)\mid A=a,X=x]\,dF_X(x)\\ &= \int E[Y\mid A=a,X=x]\,dF_X(x). \end{aligned} $$
1
Average within covariate levels.
The law of total expectation gives \(E[Y(a)]=\int E[Y(a)\mid X=x]\,dF_X(x)\). This step simply decomposes the population mean according to the target population's distribution of \(X\).
2
Use conditional exchangeability.
Because \(Y(a)\perp A\mid X\), conditioning additionally on \(A=a\) does not change the conditional mean: \(E[Y(a)\mid X=x]=E[Y(a)\mid A=a,X=x]\), wherever that treatment level occurs.
3
Use consistency and positivity.
Among those with \(A=a\), consistency gives \(Y=Y(a)\), so \(E[Y(a)\mid A=a,X=x]=E[Y\mid A=a,X=x]\). Positivity ensures such individuals occur across the target covariate support, so the needed observed conditional means are defined there.

This derivation applies separately to \(a=1\) and \(a=0\). Subtracting the resulting formulas gives a useful expression for the ATE:

$$ E[Y(1)]-E[Y(0)] = \int \left\{E[Y\mid A=1,X=x]-E[Y\mid A=0,X=x]\right\}\,dF_X(x). $$

Thus, the ATE is an average of conditional differences, with each covariate level weighted according to its prevalence in the target population. This is an identification result: it states when a causal estimand equals a function of the observed-data distribution. It does not, by itself, specify how to estimate the conditional means or quantify sampling uncertainty.

Worked Example: Standardizing Across Two Covariate Strata

Consider a hypothetical population in which \(X\) indicates baseline risk. Forty percent of the population has high baseline risk and 60% has low baseline risk. Suppose the observed conditional outcome means, in outcome points, are as follows.

Baseline riskPopulation proportionMean if treatedMean if control
High0.40811
Low0.6034

Assume consistency, conditional exchangeability given baseline risk, and positivity in both strata. The g-formula weights each treatment-specific conditional mean by the same target-population proportions.

For treatment, the population mean potential outcome is \(E[Y(1)]=(0.40)(8)+(0.60)(3)=3.20+1.80=5.00\) outcome points. For control, it is \(E[Y(0)]=(0.40)(11)+(0.60)(4)=4.40+2.40=6.80\) outcome points. Therefore the identified ATE is \(5.00-6.80=-1.80\) outcome points. Under the assumptions, treatment reduces the mean outcome by 1.80 points compared with control in this hypothetical population.

The shared weights are essential: each potential-outcome mean is averaged over the same population, rather than over the covariate composition of the corresponding treatment group.

Using a Continuous Covariate Distribution

When \(X\) is continuous, the population average is an integral rather than a finite sum. The logic of the derivation is unchanged. The conditional outcome mean can vary across values of \(X\), and the g-formula averages that function with respect to the target covariate distribution. The following example uses a deliberately simple distribution and conditional-mean functions to make the integration explicit.

Worked Example: Integrating Over a Continuous Covariate

Suppose, hypothetically, that a baseline score \(X\) is uniformly distributed from 0 to 1 in the target population. Suppose the conditional observed outcome means are \(E[Y\mid A=1,X=x]=10+2x\) and \(E[Y\mid A=0,X=x]=12+x\), measured in outcome points. Assume these means are identified as the relevant potential-outcome means through consistency and conditional exchangeability, and assume positivity for both treatment levels throughout \(0\leq x\leq1\).

The uniform density is 1 on this interval, so the treatment mean is

$$ E[Y(1)] = \int_0^1 (10+2x)\,dx = \left[10x+x^2\right]_0^1 = 11 \text{ outcome points}. $$

Similarly, the control mean is

$$ E[Y(0)] = \int_0^1 (12+x)\,dx = \left[12x+\frac{x^2}{2}\right]_0^1 = 12.5 \text{ outcome points}. $$

The ATE is \(11-12.5=-1.5\) outcome points. This calculation averages both conditional means over the specified population distribution of \(X\). If the population distribution were different, the same conditional-mean functions could produce different marginal means and a different ATE.

Positivity and What the Formula Cannot Recover

The formula cannot be evaluated from observed data at a covariate value when one treatment level never occurs there. This is not merely a computational inconvenience: the data provide no conditional outcome mean for the missing treatment level in that part of the population. The following hypothetical example makes the missing information explicit.

Worked Example: A Treatment Level Missing in Each Stratum

Suppose a target population has two equally common covariate strata, \(X=0\) and \(X=1\). In a hypothetical sample, all 20 people with \(X=0\) receive treatment and have a mean outcome of 5 points. All 20 people with \(X=1\) receive control and have a mean outcome of 9 points. No one with \(X=0\) receives control, and no one with \(X=1\) receives treatment.

The treatment mean required by the g-formula is \(E[Y(1)]=0.5E[Y\mid A=1,X=0]+0.5E[Y\mid A=1,X=1]\). The first conditional mean is observed as 5, but the second is unavailable. The control mean is \(E[Y(0)]=0.5E[Y\mid A=0,X=0]+0.5E[Y\mid A=0,X=1]\). Here the second conditional mean is observed as 9, but the first is unavailable.

For illustration, if the two missing conditional means were 7 and 6, respectively, the completed treatment and control means would be \(0.5(5)+0.5(7)=6\) and \(0.5(6)+0.5(9)=7.5\), giving an ATE of \(-1.5\) points. If instead the missing means were 11 and 2, the means would be \(0.5(5)+0.5(11)=8\) and \(0.5(2)+0.5(9)=5.5\), giving an ATE of \(2.5\) points. These different completions agree with the observed conditional means but imply different effects. The observed data therefore do not determine the g-formula in this example; positivity fails in both strata.

Diagnostics, Alternatives, and Limitations

Positivity can be assessed in part by examining whether both treatment levels appear across the observed covariate patterns. Empty treatment-by-covariate cells are a direct warning for discrete covariates; very sparse cells can make estimated conditional means unstable even when they are not empty. With many covariates, inspect treatment overlap across the joint covariate patterns rather than checking each covariate in isolation. The exact diagnostics depend on the data structure, but no diagnostic can turn a structural absence of a treatment level into information supplied by the data.

Conditional exchangeability is different: it is an assumption about potential outcomes, and observed data alone cannot verify it. Subject-matter reasoning is needed to judge whether the measured pretreatment covariates are sufficient to account for common causes of treatment and outcome. Consistency also requires meaningful, sufficiently well-defined treatment levels. If the same label represents versions with different effects, interpreting a single \(Y(a)\) may be problematic.

The g-formula clarifies how standardization differs from several alternatives. A crude difference in observed treatment-group means averages over the covariate distribution within each treatment group; it need not equal the target-population contrast when those distributions differ. Random assignment can identify mean potential outcomes by comparing randomized groups without this particular conditional standardization argument. Stratified adjustment is the finite-covariate version of the g-formula: calculate conditional means within strata and weight them by target-population proportions. Regression adjustment can estimate conditional means when there are many covariate patterns, but its validity then also depends on how well the chosen model represents those conditional means. These approaches do not remove the need to define the target population or justify the causal assumptions.

In applications, the population formula is often implemented by estimating conditional outcome means and averaging predictions over the target covariate distribution. For an empirical target population of \(n\) individuals with covariate values \(X_i\), a simple plug-in expression is \(n^{-1}\sum_{i=1}^n\widehat{E}[Y\mid A=a,X=X_i]\). This is an estimator, not the identification formula itself. Sparse overlap and inaccurate conditional-mean estimates can make it unreliable; the population derivation does not guarantee that a particular estimation procedure will work well.

Common mistake: “Conditional exchangeability holds, so the observed mean among treated people equals \(E[Y(1)]\).” This skips the averaging over \(X\): treated people may have a different covariate distribution from the target population. The g-formula instead takes the treatment-specific conditional mean at each \(x\) and averages it over the target population's \(F_X\). It also requires positivity so those conditional means are observed across the target support.
Key takeaway: For each treatment level, the g-formula identifies a population mean potential outcome by averaging the corresponding observed conditional outcome mean over the target population's covariate distribution. Conditional exchangeability supplies the causal link, consistency links observed and potential outcomes, and positivity supplies the needed treatment-specific observations across that distribution.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. State the g-formula for \(E[Y(0)]\) when \(X\) is discrete.
  2. A target population has two equally common strata. The conditional means under treatment are 4 and 10 outcome points; under control they are 6 and 8. Calculate both g-formula means and the ATE.
  3. Why does conditional exchangeability alone not justify replacing \(E[Y(a)]\) with the observed mean among people who received \(a\)?
  4. In one covariate stratum, no one receives treatment. Which assumption fails, and what information is missing for the g-formula?
  5. In the continuous-covariate example, what changes if the target population distribution of \(X\) changes while the conditional-mean functions stay the same?

Solutions: (1) \(E[Y(0)]=\sum_x E[Y\mid A=0,X=x]P(X=x)\). (2) The treatment mean is \(0.5(4)+0.5(10)=7\) points; the control mean is \(0.5(6)+0.5(8)=7\) points; the ATE is \(0\) points. (3) The treatment group can have a different covariate distribution from the target population, so its crude mean does not generally use the required target-population weights. (4) Positivity fails in that stratum; the observed data lack the conditional outcome mean for treatment there. (5) The averaging weights change, so the marginal means and potentially their difference change even though the conditional-mean functions are unchanged.

Clinical Biostats