G-computation (source code)

= G-computation
{wiki}

= G-formula
{c}
{synonym}

<G-computation> calculates the outcome distribution under a specified <intervention> from conditional laws identified under a causal model. For a single binary <treatment>, pretreatment <covariates> $X$, and outcome $Y$, the <G-formula> is
$$
\mathbb E[Y(a)]=\int\mathbb E(Y\mid A=a,X=x)\,dF_X(x).
$$
It follows by averaging over $X$, using <conditional exchangeability> to replace the conditional <potential outcome> mean by the mean among recipients of $a$, and using <consistency in causal inference> to replace $Y(a)$ by observed $Y$. <Positivity> ensures the required conditional outcome laws are represented in the target strata.<Estimating causal effects from epidemiological data by Miguel A. Hernán and James M. Robins>[Standardisation; Bibliographical notes on the g-formula; Appendix A.1]{ref}

For an illustrative binary outcome, suppose target weights are $0.8$ and $0.2$ in two baseline strata. Untreated risks $0.1,0.4$ give <intervention> risk $0.8(0.1)+0.2(0.4)=0.16$. Treated risks $0.05,0.2$ give $0.08$, so the standardized <causal risk ratio> is $0.5$ and the <risk difference> is $-0.08$. Both strategies use the same target weights.

With repeated <treatments> and time-varying <covariates>, the longitudinal <G-formula> integrates products of the <covariate> transition laws while setting each <treatment> according to the <intervention> strategy. This requires <sequential exchangeability>, longitudinal <positivity> and <consistency in causal inference>. Simply conditioning on every observed intermediate variable can block part of the intended effect; the sequential <intervention> calculation specifies which laws are averaged.