Why Quantify Uncertainty in G-Computation?
G-computation combines estimated mediator and outcome models to estimate an interventional mean or a contrast between such means. The estimate is therefore uncertain because the data determine both models, and because the final quantity is a function of their estimates. Reporting only a point estimate hides this sampling uncertainty. A confidence interval can show how much the estimated effect might vary across repeated samples from the target population.
The nonparametric bootstrap estimates this variability by repeatedly resampling observed units, refitting the models, and recomputing the target quantity. The key is to treat the whole analysis as one procedure: a bootstrap replicate must carry the mediator and outcome information from the same resampled units through to the final effect estimate.
For binary exposure, examples of contrasts include the interventional direct-effect contrast \(\psi(1,0)-\psi(0,0)\) and the interventional indirect-effect contrast \(\psi(1,1)-\psi(1,0)\). This tutorial concerns uncertainty in estimates of these quantities, not choosing among mediation estimands.
The identification conditions for the chosen interventional mean remain necessary. In particular, the causal interpretation requires the relevant consistency, exchangeability, and positivity conditions, as well as no interference between units under the analysis. A bootstrap does not establish these conditions. It quantifies sampling variability for the estimator and estimand actually used.
The Paired Nonparametric Bootstrap
Suppose the observed data consist of \(n\) independent units, with each unit’s exposure, mediator, outcome, and baseline covariates recorded together. A nonparametric bootstrap sample draws \(n\) units with replacement from the observed \(n\) complete records. Some units may appear more than once and some may not appear. Within each bootstrap sample, refit both the mediator-distribution model and the outcome model, then repeat the entire g-computation calculation.
Draw \(n\) observed records with replacement. Keep each record’s \(A\), \(M\), \(Y\), and \(C\) together.
Estimate the conditional mediator distribution and the outcome regression using that bootstrap sample.
Apply the g-computation formula using the bootstrap-fitted models and the covariate distribution in that sample.
Repeat for \(B\) bootstrap samples, producing \(B\) estimates of each mean and contrast. Use their empirical distribution to quantify uncertainty.
The empirical covariate distribution is usually represented by the resampled units themselves: calculate predicted outcomes over those units and average. If the original analysis instead uses a specified target covariate distribution, the bootstrap calculation should preserve that target and account for any uncertainty in estimating it as appropriate.
A central 95% percentile bootstrap interval uses the 2.5th and 97.5th percentiles of the bootstrap estimates. If \(\hat{\theta}^{*(1)},\ldots,\hat{\theta}^{*(B)}\) are bootstrap estimates of a target \(\theta\), the interval is
where \(Q_q\) is the empirical \(q\) quantile. With a sufficiently large \(B\), such as 2,000 or more, these quantiles are less affected by Monte Carlo noise than with only a small number of replicates. Other bootstrap interval constructions exist; the percentile interval is direct to compute, but it is not guaranteed to have exact 95% coverage in finite samples.
Worked G-Computation and Bootstrap Replicate
Worked Example: Recomputing Interventional Means in One Resample
Hypothetical data and fitted models. Suppose a study has 100 independent participants, a binary exposure, a continuous mediator measured in hours, and an outcome measured in score points. For illustration, the fitted mediator model in the original sample gives mean mediator values of 4 hours under \(A=0\) and 6 hours under \(A=1\). Suppose the fitted outcome mean is
This regression specification has a linear mean in \(M\); consequently, integrating its predicted mean over a mediator distribution requires only that distribution’s mean. The estimates are illustrative model outputs, not results from a real study. Assume for this calculation that the target covariate distribution has no varying covariates.
Under exposure \(A=1\) and the mediator distribution under \(A=0\), the estimated interventional mean is
Under \(A=0\) and the mediator distribution under \(A=0\),
Thus the estimated interventional direct-effect contrast is \(26-22=4\) score points. For comparison, \(\hat{\psi}(1,1)=10+2+3(6)+0.5(6)=33\) score points, so the estimated interventional indirect-effect contrast is \(33-26=7\) score points.
Now consider one paired bootstrap sample drawn from the 100 complete participant records. Suppose refitting both models in this resample gives mediator means 4.3 and 6.4 hours, and the outcome regression
The bootstrap estimate of \(\psi(1,0)\) is
For \(\psi^{*}(0,0)\), the exposure terms vanish:
The bootstrap direct-effect estimate is therefore \(27.165-23.13=4.035\) score points. This is one replicate, not a confidence interval. Repeating the paired resampling and refitting produces the distribution used to construct an interval.
Why Both Models Must Be Refit Together
An interventional mean depends jointly on the outcome response and the mediator distribution. The two fitted components come from the same observed sample, so their sampling errors can be related. For a contrast, the uncertainty in each component and their covariance both matter. Resampling the units once and using that same resample for both model fits reproduces this joint sampling variation.
The point can be seen from the variance of a difference. For bootstrap estimates of two interventional means, the variance of their difference is
The covariance term is not generally zero. It can be important because both means use the same outcome-model fit, the same sampled covariates, and related mediator-model estimates. A bootstrap that keeps one fitted model fixed omits part of the uncertainty. Resampling mediator and outcome data independently, when they are measurements on the same participants, instead breaks the dependence present in the original sampling process.
Worked Example: The Covariance in a Bootstrap Contrast
Suppose 2,000 paired bootstrap replicates of two interventional means produce standard deviations of 2.0 and 1.5 score points, with bootstrap correlation \(0.60\). The covariance is
The bootstrap standard deviation of their difference is therefore
If the two estimates were incorrectly treated as independent, the covariance would be set to zero and the calculated standard deviation would be
That calculation is not the paired bootstrap uncertainty for this hypothetical example. The discrepancy shows why the contrast should be computed within each joint replicate, rather than combining marginal uncertainties as though the estimates were unrelated.
Worked Percentile Confidence Interval
Worked Example: Interpreting a Bootstrap Interval
Hypothetical analysis. In a separate hypothetical study, the estimated interventional indirect effect on an outcome measured in score points is 4.0 points. The analyst draws 2,000 paired bootstrap samples, refits both models in every sample, and calculates the indirect-effect contrast each time. Suppose the 50th ordered bootstrap estimate is 4.1 points, the 50th percentile is 4.1 points, and the empirical 2.5th and 97.5th percentiles are 0.8 and 7.1 points. (The percentile, rather than the particular order-statistic convention, determines the reported interval.)
The 95% percentile bootstrap interval is
In repeated samples under the assumed sampling process, a procedure with valid 95% coverage would produce intervals containing the target interventional effect about 95% of the time. For this dataset, the computed interval ranges from 0.8 to 7.1 score points. It is not a statement that there is a 95% probability the fixed target effect lies in this particular interval. Since zero is outside this interval, it does not include a zero indirect-effect contrast at the nominal 95% interval level; that conclusion does not establish the identification assumptions or rule out bias.
Assumptions, Scope, and Common Pitfalls
The ordinary unit-level nonparametric bootstrap is most directly justified when the observed units are independent and identically distributed from the population relevant to the analysis, and the estimator behaves regularly enough for the bootstrap distribution to approximate its sampling distribution. Each replicate must apply the same fitting choices and g-computation steps as the original analysis. If the data arise from a cluster sample, a repeated-measures design, or a complex sampling scheme, resampling individual rows may be inappropriate; the resampling scheme must reflect the independent sampling units or design.
Bootstrap intervals describe sampling uncertainty under the analysis. They do not repair a poorly specified mediator or outcome model, lack of positivity, unmeasured confounding, or a mismatch between the estimated and scientifically intended target population. A narrow interval can coexist with substantial systematic bias. Model diagnostics and causal identification arguments are separate requirements.
- Holding one model fixed. The incorrect reasoning is that uncertainty in the outcome model alone is enough. The correction is to refit both mediator and outcome models in every replicate because both contribute to the estimate.
- Resampling mediator and outcome records independently. This discards their within-unit pairing and can change the joint sampling distribution. Resample complete participant records together.
- Subtracting separate interval endpoints. The endpoints of intervals for two means do not generally form an interval for their difference. Compute the contrast in each replicate, then take quantiles of that contrast distribution.
- Treating a bootstrap interval as a bias correction. The interval quantifies sampling uncertainty for the estimator; it does not automatically correct confounding, misspecification, or other systematic errors.
Check Your Understanding
Answer each question using the definitions and procedures in this tutorial.
- Why must the mediator-distribution model and outcome model both be refit in each bootstrap sample?
- For an estimated contrast \(\hat{\psi}(1,0)-\hat{\psi}(0,0)\), what quantity should be calculated in each bootstrap replicate before taking interval quantiles?
- If two bootstrap interventional means have positive covariance, how does that covariance enter the variance of their difference?
- What does a 95% percentile bootstrap interval describe, and what does it not mean for the particular interval computed from one dataset?
- Name one source of uncertainty or bias that a nonparametric bootstrap does not resolve.