What is G-Computation?
G-Computation (causal standardization) estimates what would happen on average if we set every person to a specific exposure value β as opposed to "which people actually had that value".
Key marginaleffects concept: variables=list(X=val) sets X to val for every observation and averages over all confounder distributions. This is true marginalization β not a "typical person" estimate.
Binary exposure β estimands
- ATE (Average Treatment Effect): E[Y(1)βY(0)] β effect in the full population.
- ATT (on the Treated): E[Y(1)βY(0) | X=1] β effect only among the actually exposed.
- ATU (on the Untreated): E[Y(1)βY(0) | X=0] β effect if the unexposed were treated.
ATE β ATT β ATU when there is effect heterogeneity. Under randomization without interactions they are equal.
Metric exposure β AME & ate_k
- AME (Average Marginal Effect): Average partial derivative dE[Y]/dX. Answers: "By how much does Y change per one unit increase in X?"
- ate_k (causal contrast): E[Y(x_hi) β Y(x_lo)] β averages the difference between two specific X values over all persons. Answers: "What would the difference be between Min and Max, Q1 and Q3, etc.?"
AME and ate_k are conceptually different: AME is a slope (per unit), ate_k is a total contrast (fromβto). Both are causal effects when confounding is controlled.
ate_k β contrast strings in marginaleffects
"minmax" β Min β Max of the exposure
"iqr" β Q1 β Q3 (25th β 75th percentile)
"sd" β MeanβSD β Mean+SD
c(lo, hi) β user-defined interval
ATT/ATU analogue (metric)
For metric exposures there is no natural "treated/untreated". The analogue splits the population artificially at a cutoff (default: median):
- att_k: contrast β only for observations with X β₯ cutoff ("highly exposed")
- atu_k: contrast β only for observations with X < cutoff ("low exposed")
Useful for checking whether the effect differs for already highly exposed vs. low exposed persons β effect heterogeneity along the exposure axis.
Dose-response curve
Estimates E[Y | do(X=x)] for 100 values from min to max. Each point is a genuine G-Computation estimate: the entire population is "set to X=x" and the marginal mean is computed.
ICE β Individual causal effects
Individual Counterfactual Effects: ΟΜα΅’ = ΕΆα΅’(x_hi) β ΕΆα΅’(x_lo). Shows heterogeneity in the causal effect across persons. Sorted by ΕΆα΅’(x_lo) β same row = same person in both plots.
Workflow
- Build DAG in Golem Builder β export to G-Comp Builder
- Check formula, fit model in R
- Copy code, compute estimands
- Export MCMC draws β Decision Maker
Only variables from the adjustment set are required in the formula. Precision covariates (causes of Y but not X) can safely be added β they reduce variance without introducing bias.