Why Integration Strategy Matters
A g-formula estimand averages a modeled counterfactual outcome over the covariate histories that would arise under a specified intervention. The target is an expectation; the practical question is how to evaluate it. For a small discrete history space, summing every possible history may be exact and inexpensive. For continuous covariates, a closed form may or may not exist. Deterministic quadrature can approximate a low-dimensional integral accurately, while Monte Carlo integration can handle large, complicated history spaces by sampling trajectories.
These are computational alternatives for evaluating the same estimand, not alternative identification strategies. Each relies on the same target population, intervention, and fitted conditional models. The usual identification assumptions, including consistency, sequential exchangeability, and positivity for the intervention of interest, remain relevant; changing the integration method does not repair their failure or correct misspecified models.
For a longitudinal history, the expectation can be written schematically as an integral of the conditional mean outcome against the baseline distribution and each covariate transition distribution under \(d\). In the discrete case, integrals are sums. In either case the fitted models determine the integrand and the distributions being averaged over.
The expression is schematic: the conditional distributions and outcome regression must match the study’s time ordering and covariate history. It emphasizes the computational distinction. Exact finite summation enumerates the support; quadrature chooses fixed points and weights to approximate the integral; Monte Carlo generates histories according to the distributions in the formula and averages their predicted outcomes.
Exact Summation and Analytic Integration
Exact evaluation is attractive when the relevant support is finite and small, or when the required expectations have tractable forms. A product of binary covariates over many time points can, however, create exponentially many histories. A closed form may also be unavailable even when the models themselves are simple. Thus, “analytic” does not automatically mean computationally feasible: the number of terms and the complexity of each term matter.
Worked Example: Enumerating a Two-Stage Discrete History
Suppose baseline \(B\) is Bernoulli with \(P(B=1)=0.4\). Under a fixed regime \(d\), an intermediate covariate \(L_1\) is Bernoulli with \(P(L_1=1\mid B=0)=0.2\) and \(P(L_1=1\mid B=1)=0.7\). The fitted outcome risks under the regime are \(0.05,0.20,0.30,0.60\) for \((B,L_1)=(0,0),(0,1),(1,0),(1,1)\), respectively. Find the regime-specific risk by exact summation.
For \(B=0\), average over the two possible values of \(L_1\):
For \(B=1\), the corresponding average is:
Finally average over the baseline distribution:
There are only four covariate histories, so exact enumeration is straightforward and has no integration approximation error. With many binary covariates across many times, the same calculation can require an impractical number of terms.
Monte Carlo Integration: What It Estimates
Monte Carlo integration draws \(N\) independent histories from the baseline and intervention-specific transition distributions, calculates the modeled outcome for each history, and averages those predictions. If the conditional outcome mean is used, write the draw-specific prediction as \(m(H_i)\), where \(H_i\) is the simulated history. The estimate is the sample mean of these predictions.
Here \(F_d\) is the distribution of covariate histories under the intervention. For a fixed fitted model and independent draws from \(F_d\), the estimate is unbiased when \(E_{F_d}[|m(H)|]<\infty\). If \(E_{F_d}[m(H)^2]<\infty\), its variance is \(\operatorname{Var}_{F_d}(m(H))/N\), and the strong law of large numbers gives \(\hat\psi_N(d)\xrightarrow{a.s.}\psi(d)\). If the variance is positive and finite, the central limit theorem further gives \(\sqrt{N}\{\hat\psi_N(d)-\psi(d)\}\xrightarrow{d}N(0,\operatorname{Var}_{F_d}(m(H)))\). These statements concern Monte Carlo integration conditional on the fitted models; they do not include uncertainty from estimating model parameters.
Justification. Linearity of expectation gives \(E[\hat\psi_N(d)]=N^{-1}\sum_i E[m(H_i)]=\psi(d)\). Independence makes all cross-covariances zero, so \(\operatorname{Var}(\hat\psi_N(d))=N^{-2}\sum_i\operatorname{Var}(m(H_i))=\operatorname{Var}(m(H))/N\). The strong law applies to the independent, identically distributed integrable variables \(m(H_i)\). Under the additional finite positive variance condition, the independent, identically distributed central limit theorem applies to those same variables. \(\square\)
Worked Example: Conditional Averaging Reduces Simulation Variance
Let \(X\sim N(0,1)\), and suppose the modeled conditional mean under a regime is \(m(X)=0.3+0.4X+0.2X^2\). The estimand is \(E[m(X)]\). Since \(E[X]=0\) and \(E[X^2]=1\),
If the outcome is simulated as well, suppose \(Y\mid X\) has this conditional mean and conditional variance \(1\). The total variance formula gives
For a standard normal variable, \(\operatorname{Var}(X)=1\), \(\operatorname{Var}(X^2)=2\), and \(\operatorname{Cov}(X,X^2)=E[X^3]-E[X]E[X^2]=0\). Therefore,
A simulation that draws both \(X\) and \(Y\) has per-draw variance \(1.24\); one that draws \(X\) and averages \(m(X)\) has per-draw variance \(0.24\). With \(N=100\), the respective estimator variances are \(1.24/100=0.0124\) and \(0.24/100=0.0024\). Both target the same mean, but averaging the conditional mean avoids unnecessary outcome noise.
Deterministic Numerical Integration
Numerical quadrature evaluates the integrand at selected points and combines the results with fixed weights. In low-dimensional continuous problems, a well-chosen quadrature rule can be accurate with relatively few evaluations. Unlike Monte Carlo, the result is generally deterministic once the grid, rule, and fitted model are fixed. Its error is approximation error from the quadrature rule and, when an unbounded integral is truncated, from the omitted tails. Increasing the grid resolution does not guarantee a simple universal error rate; accuracy depends on the integrand’s smoothness, dimension, domain, and the rule used.
Worked Example: Midpoint Integration Versus Monte Carlo
Let \(X\) be Uniform on \([0,1]\), and let the modeled outcome risk be \(m(X)=X^2\). The target is
Using the midpoint rule with two equal subintervals gives midpoints \(0.25\) and \(0.75\), each with weight \(0.5\):
The deterministic error is \(0.3125-\frac{1}{3}=-\frac{1}{48}\), approximately \(-0.0208\). For Monte Carlo, draw independent \(X_i\sim\operatorname{Uniform}(0,1)\) and average \(X_i^2\). This estimator is unbiased, with variance per draw
Thus the variance of the Monte Carlo estimate at \(N=100\) is \(4/(45\cdot100)\approx0.000889\), with standard error about \(0.0298\). The particular Monte Carlo estimate varies across runs; the midpoint result does not. This comparison does not establish which method is more accurate for a particular run: it shows that quadrature has a fixed approximation error here, whereas Monte Carlo has random error quantified by its variance.
Choosing a Method and Diagnosing Failure
The practical choice depends on the dimension and structure of the integral. Exact summation is compelling for small discrete supports. Closed-form expectations are useful when the distribution and integrand permit them. Deterministic quadrature is often effective in low dimensions, especially when the integrand is smooth. Monte Carlo is often more scalable as the number of continuous covariates or longitudinal time points grows, although its sampling error usually declines only at the rate \(N^{-1/2}\). Hybrid calculations can integrate some components exactly and simulate the rest.
A useful hybrid principle is conditional averaging: whenever part of the integrand can be averaged analytically conditional on the remaining random quantities, use that conditional expectation before simulation. The preceding example illustrated the variance benefit of replacing simulated outcomes by their conditional mean. More generally, if \(Z\) is a simulated quantity and \(W\) is retained, then
because the total variance identity gives \(\operatorname{Var}(Z)=E[\operatorname{Var}(Z\mid W)]+\operatorname{Var}(E[Z\mid W])\), and the first term is nonnegative.
Diagnostics should address the chosen approximation directly. For Monte Carlo, compare independent runs or batches, monitor the estimated standard error as \(N\) increases, and check that simulated histories follow the specified baseline and transition distributions. For quadrature, compare successive grid resolutions or rules, and inspect tail truncation when relevant. For exact summation, verify that probabilities over all enumerated histories sum to one. In every case, compare a smaller problem against a known exact result when possible.
A common mistake is to treat a very large simulation as a remedy for every discrepancy. Increasing \(N\) reduces Monte Carlo error, but it does not fix an incorrect transition model, a coding error, or lack of positivity; neither does a fine quadrature grid. Conversely, disagreement between two numerical integration methods can signal inadequate resolution or a simulation problem, but does not by itself identify which method is wrong. Keep integration error, model-estimation uncertainty, and bias from identification or model assumptions conceptually separate. Bootstrap inference addresses sampling uncertainty in the fitted analysis; it does not make a poor numerical approximation exact.
Check Your Understanding
Answer each question, then compare with the solutions below.
- A regime-specific covariate history has only eight possible values. What integration approach is a natural first choice, and what should be checked? Solution: Exact enumeration is natural if all eight probabilities and modeled outcomes can be evaluated. Check that the history probabilities sum to one and that each possible history is included.
- If the variance of the simulated conditional predictions is \(0.36\), what is the Monte Carlo standard error for \(N=400\) independent histories? Solution: The variance of the average is \(0.36/400=0.0009\), so the standard error is \(\sqrt{0.0009}=0.03\).
- Does increasing the Monte Carlo sample size reduce bias from a misspecified outcome model? Solution: No. It reduces random integration error around the expectation implied by the fitted model, not model misspecification bias.
- Why can averaging conditional outcome means be more efficient than simulating outcomes too? Solution: Conditional averaging removes the nonnegative \(E[\operatorname{Var}(Y\mid H)]\) component of variance, since \(\operatorname{Var}(Y)=E[\operatorname{Var}(Y\mid H)]+\operatorname{Var}(E[Y\mid H])\).