Parametric g-Formula

Statistics
Introduced by
James M. Robins; Ashley I. Naimi, Alexander P. Keil et al. (applied tutorial)
Year
1986
Type
Counterfactual simulation pipeline for time-varying treatment regimes
Family
Causal inference / g-methods

What does it do?

The parametric g-formula is the estimator James Robins introduced in 1986 for the causal effect of a time-varying exposure when time-varying confounders are themselves affected by past exposure.

In this setting, ordinary regression adjustment can give a biased estimate of the effect. Rather than conditioning on these confounders directly, the g-formula parametrically models how confounders and the outcome evolve over time, then uses Monte-Carlo simulation to estimate outcomes under hypothetical exposure regimes such as 'always exposed' versus 'never exposed.' Keil and colleagues' 2014 tutorial presented a simple introduction to the method for time-to-event data and a worked example. In social epidemiology it has been used for questions about cumulative exposures, such as sustained deprivation, employment, or income trajectories, where confounders and mediators are intertwined across time.

The intuition behind the method

Imagine you want to know whether staying employed throughout adulthood protects health, but unemployment both responds to deteriorating health and causes further decline. Health at each point is a confounder of the next employment spell, yet it is also a consequence of past employment. If you simply adjust for health history in a regression, you block part of the effect you want to measure (over-adjustment) while still leaving bias from conditioning on a collider. The g-formula avoids conditioning on these variables. Instead it builds a simulator of the life course: a model for how health evolves given past employment and past health, and a model for the outcome. You then run the simulator twice, once forcing everyone to follow an 'always employed' rule and once a 'never employed' rule, letting the confounders take whatever values the fitted models imply under that rule. The gap between the two simulated populations is the estimated causal effect of the exposure regime. The key step is that the intervention is imposed in the simulation rather than through conditioning on the observed data.

History

James Robins introduced the g-computation formula in a 1986 Mathematical Modelling paper, motivated by the healthy-worker survivor effect, in which prior health affects both employment and mortality. Ordinary adjustment cannot separate the effect of exposure from this selection. Keil, Edwards, Richardson, Naimi, and Cole's 2014 Epidemiology paper described the method in intuitive terms for time-to-event data and presented a worked example in which standard regression adjustment was compared with the g-formula estimate. The abstract notes that few published applications existed at that time.

When to use it

Choose the parametric g-formula when you have longitudinal data and want the effect of a sustained or dynamic exposure regime in the presence of time-varying confounders that are affected by prior exposure. This is the setting where standard time-varying regression adjustment is biased, and a marginal structural model is the other main g-method option. It is especially useful when you want to compare several hypothetical regimes, including dynamic 'treat-when' rules, or estimate counterfactual survival or risk curves rather than a single coefficient. It suits social-epidemiologic questions about cumulative exposure to deprivation, employment, income, or policy. Prefer inverse-probability weighting (a marginal structural model) when you do not want to model the full time-varying covariate process, recognising that weighting can be unstable when positivity is fragile. Avoid the g-formula when the time-varying confounder models cannot be credibly specified, because it is sensitive to their misspecification.

Limitations and considerations

  • Requires correctly specifying parametric models for every time-varying confounder as well as for the outcome, and is sensitive to their misspecification.
  • Susceptible to the g-null paradox: under the sharp causal null, misspecified covariate and outcome models can produce spurious rejection of the null.
  • Computationally heavy: Monte-Carlo simulation combined with bootstrap inference means refitting many models many times.
  • Like all g-methods, identification rests on the untestable assumptions of sequential exchangeability, positivity, and consistency.
  • For time-to-event outcomes, censoring (and competing events) must be handled explicitly, typically by modelling censoring as a further time-varying process or by assuming independent censoring given measured history. This is an extra assumption beyond the identifying conditions.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Estimates effects of time-varying exposures when time-varying confounders are also affected by prior exposure, a setting in which standard regression adjustment can be biased.
  • Accommodates dynamic treatment regimes and allows comparison of several hypothetical interventions, including counterfactual risk or survival curves.
  • Models the outcome directly rather than relying only on exposure-weighting, so it can be used for comparisons that weighting handles less naturally, such as dynamic regimes.
  • Provides a natural-course simulation that can be checked against the observed data as a diagnostic of the fitted models.

Applications

  • Estimating the cumulative health effect of sustained employment, unemployment, or income trajectories where health feeds back into the exposure.
  • Quantifying the effect of long-term exposure to neighborhood deprivation or environmental hazards over the life course.
  • Comparing dynamic treatment or policy regimes, such as intervening when a biomarker or risk score crosses a threshold.
  • Controlling the healthy-worker survivor effect in mortality studies of occupational cohorts.
  • Producing counterfactual survival or risk curves under hypothetical public-health interventions for decision-makers.

How it works

How it works

1

The pipeline begins by writing the causal estimand as Robins's g-formula: the mean counterfactual outcome under a fixed exposure regime equals the expectation of the outcome, averaged over the time-varying confounder distribution, with the confounder densities sequentially conditioned on exposure and confounder history. This identification result requires sequential exchangeability (no unmeasured time-varying confounding), positivity (every exposure level is possible at every confounder history), and consistency. The formula treats confounders as quantities to be integrated over according to their conditional distribution under the regime, not as variables to be held fixed. This is why it can handle confounders that are also affected by earlier exposure.

Formula
E[Y^{\bar{a}}] = \sum_{\bar{l}} E[Y \mid \bar{A}=\bar{a}, \bar{L}=\bar{l}] \prod_{k=0}^{K} f(l_k \mid \bar{a}_{k-1}, \bar{l}_{k-1})
2

Because the confounder distribution in the g-formula is unknown, it must be estimated. The analyst fits a sequence of parametric models, one for each time-varying confounder at each interval, regressing it on prior exposure history and prior confounder history. These pooled longitudinal models encode how the covariate process unfolds over time. They are often logistic for binary covariates and linear or generalized-linear for continuous ones. Their specification matters, because the g-formula is sensitive to misspecification of the covariate-evolution models, so flexible forms such as splines and interactions are commonly included.

Formula
L_k \sim f_k(l_k \mid \bar{A}_{k-1}, \bar{L}_{k-1}; \hat{\gamma}_k),\quad k=0,\dots,K
3

Next the analyst specifies a model for the outcome as a function of cumulative exposure and the time-varying confounder history. For a single end-of-follow-up outcome, one regression suffices. For time-to-event outcomes, the usual implementation is a pooled discrete-time hazard model: follow-up is split into person-period records and a binary event indicator is regressed on current exposure, current and lagged confounders, and time, for example by pooled logistic regression. The fitted hazards convert each simulated trajectory of exposure and covariates into a predicted probability of the event in each interval, from which survival under the regime follows. The continuous-time proportional-hazards expression in the mechanics panel illustrates the form a hazard can take, but estimation in practice is usually carried out with the pooled discrete-time model described here. The outcome model must include the covariates needed for the exchangeability assumption. With time-to-event outcomes, censoring must also be handled explicitly, usually by modelling censoring as a further time-varying process or by assuming independent censoring given measured history. This is an additional assumption beyond sequential exchangeability, positivity, and consistency, and competing events need comparable treatment.

Formula
\lambda(t \mid \bar{A}_t, \bar{L}_t) = \lambda_0(t)\exp\bigl(\beta_1 \bar{A}_t + \beta_2 \bar{L}_t\bigr)
4

With the models fitted, the counterfactual population is generated by Monte-Carlo simulation. Starting from the observed baseline covariate distribution, the algorithm steps forward in time. Under the chosen exposure rule it sets exposure deterministically, draws each time-varying confounder from its fitted conditional model given the intervened history, and accumulates predicted outcome risk from the outcome model. Repeating this for a large simulated cohort and averaging gives the estimated mean counterfactual outcome under that regime. The same procedure can handle dynamic regimes, such as treating when a biomarker crosses a threshold, by applying the rule at each step.

Formula
\hat{E}[Y^{\bar{a}}] = \frac{1}{M}\sum_{m=1}^{M} \tilde{Y}_m^{\bar{a}},\quad \tilde{L}_{k,m} \sim \hat{f}_k(\cdot \mid \bar{a}_{k-1}, \tilde{L}_{k-1,m})
5

The regime-specific estimates are then contrasted to give the causal effect, such as a risk difference, risk ratio, or difference in survival curves, between regimes such as 'always exposed' and 'never exposed.' Because the estimate depends on many fitted models and a simulation, closed-form standard errors are impractical. Inference is therefore usually obtained by the nonparametric bootstrap, in which the whole procedure (refitting all models, resimulating, and recontrasting) is repeated on resampled subjects to produce confidence intervals. A standard diagnostic is to compare the simulated natural-course outcome with the observed data before any intervention is imposed, to check that the fitted models reproduce the observed population. The estimate is a population-average counterfactual contrast: the difference or ratio of simulated mean outcomes under two regimes in the target population over a stated time horizon. It is not a conditional, per-unit regression coefficient. Report it together with the explicit regime definitions, the time horizon, and the scale used (risk difference, risk ratio, or difference in survival).

Formula
\widehat{\theta} = \hat{E}[Y^{\bar{a}=1}] - \hat{E}[Y^{\bar{a}=0}],\quad \widehat{\mathrm{se}}(\widehat{\theta}) = \mathrm{sd}_{b=1}^{B}\bigl(\widehat{\theta}^{(b)}\bigr)

Common pitfalls

  • Adjusting for time-varying confounders in a single conventional regression instead of using a g-method, which reintroduces the bias that the g-formula is designed to avoid.
  • Specifying overly simple covariate-evolution models, which can produce the g-null paradox or biased simulated trajectories.
  • Skipping the natural-course diagnostic, so that misspecification which distorts the simulated population goes undetected.
  • Reporting standard errors that ignore the uncertainty from the fitted covariate and outcome models and from the simulation, instead of bootstrapping the whole pipeline.

Frequently asked questions

How does the parametric g-formula differ from a marginal structural model?

Both are g-methods that target the same kind of causal effect under the same identifying assumptions, but they estimate it differently. The g-formula models the outcome and the full time-varying confounder process and simulates counterfactual populations under each regime. A marginal structural model instead reweights subjects by the inverse probability of their observed exposure, which breaks the confounder-exposure association, and then fits a simple outcome model to the weighted pseudo-population. The g-formula handles dynamic regimes naturally but requires modeling the whole covariate process and is sensitive to its misspecification. Weighting requires treatment models but can be unstable when positivity is nearly violated. The two approaches are complementary and are often reported together.

Why can't I just adjust for the time-varying confounders in one regression?

When a time-varying confounder is affected by prior exposure, it is simultaneously a confounder of later exposure and a mediator of earlier exposure. Conditioning on it in a single regression blocks the indirect pathway you want to estimate (over-adjustment) and can open a collider bias path, so the estimate is biased in a direction you cannot sign. The g-formula avoids conditioning entirely: it integrates over the confounder distribution under the intervened exposure history, which keeps the mediating role intact while still controlling confounding. This is the central reason g-methods exist.

What is the g-null paradox and should I worry about it?

Under the sharp causal null (exposure has no effect on the outcome or on the covariates at any time), misspecified parametric submodels of the g-formula can produce spurious rejection of the null. This is the g-null paradox. In practice, use flexible covariate and outcome models, check the natural-course simulation against the observed data, and interpret a small 'significant' effect near the null cautiously.

Related methods

Sources

  1. Robins, J. M. (1986). A new approach to causal inference in mortality studies with a sustained exposure period—application to control of the healthy worker survivor effect. Mathematical Modelling, 7(9-12), 1393-1512.

    Open DOI reference
  2. Keil, A. P., Edwards, J. K., Richardson, D. B., Naimi, A. I., & Cole, S. R. (2014). The parametric g-formula for time-to-event data: intuition and a worked example. Epidemiology, 25(6), 889-897.

    Open DOI reference