Tutorials › Causal Inference › Fitting Sequential Conditional Outcome Models

The G-Formula and Dynamic Regimes · Tutorial 719 of 972

Fitting Sequential Conditional Outcome Models

Build sequential conditional models that respect the order of treatment and covariate histories and are suitable inputs to the parametric g-formula.

Advanced 12 min read

What You'll Learn

  • Distinguish covariate-transition models from the terminal-outcome model in a longitudinal analysis.
  • Choose model families that match continuous, binary, categorical, or count outcomes.
  • Specify the treatment and covariate history available at each time point.
  • Interpret treatment-history interactions and calculate fitted conditional predictions.
  • Recognize the assumptions needed to use fitted models for causal g-computation.

Why Sequential Models Need to Respect Time

In longitudinal studies, treatment and covariates unfold in a particular order. A covariate measured before a treatment decision can help predict that treatment and the outcome; a covariate measured afterward cannot be used as though it had been known beforehand. A model that ignores this ordering may describe the data poorly and can misrepresent the conditional quantities needed for the parametric g-formula.

Let \(L_t\) denote covariates measured before treatment \(A_t\), for times \(t=0,\ldots,K\), and let \(Y\) be the final outcome measured after \(A_K\). Write \(\bar L_t=(L_0,\ldots,L_t)\) and \(\bar A_t=(A_0,\ldots,A_t)\). The history available just before \(A_t\) is \(H_t=(\bar L_t,\bar A_{t-1})\), with no treatment history in \(H_0\). The model for \(L_{t+1}\) must condition on \(H_t,A_t\); the terminal outcome model must condition on the covariates and treatments observed up to the outcome.

Definition: A sequential conditional model is a model for one factor in the longitudinal data distribution, conditional on the history available at that point in time. For example, a covariate-transition model represents \(P(L_{t+1}\mid H_t,A_t)\), while a terminal-outcome model represents \(P(Y\mid \bar L_K,\bar A_K)\). For continuous variables, these expressions refer to conditional distributions or their conditional means as appropriate.

These models have different jobs. Covariate-transition models describe how covariates evolve after treatment at each time point. The terminal-outcome model describes the outcome given the full observed history. Together, correctly specified conditional distributions provide the ingredients for the parametric g-formula. Fitting them is not the same as fitting a treatment-assignment model: treatment models are not substituted for the conditional outcome and covariate models in this approach.

Choose the Model Family for Each Variable

Begin with the type and scale of the variable being modelled. A continuous covariate or outcome may be modelled with a linear conditional mean, often with a suitable distributional assumption if the full conditional distribution is needed. A binary variable is commonly modelled with logistic regression. A categorical variable with more than two levels may require a multinomial model. Counts may be modelled with Poisson regression, or with a negative-binomial model when the Poisson variance assumption is too restrictive. The choice should reflect the variable’s support and the conditional feature needed by the g-formula.

For example, a linear model for a binary variable can predict values below zero or above one, which are not valid probabilities. A logistic model avoids that problem by modelling the log odds. Conversely, a logistic model is not a natural model for a continuous blood-pressure measurement. A model’s link function and distributional assumptions should be stated, not inferred from the software command.

A useful general form for a conditional mean is

$$ g\{E(Z\mid X)\}=\beta_0+\beta_1 X_1+\cdots+\beta_p X_p, $$

where \(Z\) is the variable being modelled, \(X\) contains the relevant history, and \(g\) is a link appropriate to the outcome type. The model must include the treatment and covariate history needed to represent the conditional distribution; a convenient link cannot compensate for omitting important history.

Worked Example: Fitting a Continuous Covariate-Transition Model

Suppose a hypothetical study records binary baseline covariate \(L_0\), binary first treatment \(A_0\), and continuous covariate \(L_1\) before the next treatment. The following eight hypothetical observations are arranged in four history groups.

\(L_0\)\(A_0\)Observed \(L_1\) valuesGroup mean
002, 43
014, 65
105, 76
1110, 1211

A saturated conditional-mean model for these two binary predictors is

$$ E(L_1\mid L_0,A_0)=\beta_0+\beta_1L_0+\beta_2A_0+\beta_3L_0A_0. $$

Because the model has one parameter for each of the four history-group means, ordinary least squares fits each group mean. At \(L_0=0,A_0=0\), the fitted mean is \(\hat\beta_0=3\). At \(L_0=1,A_0=0\), it is \(3+\hat\beta_1=6\), so \(\hat\beta_1=3\). At \(L_0=0,A_0=1\), it is \(3+\hat\beta_2=5\), so \(\hat\beta_2=2\). Finally, at \(L_0=1,A_0=1\), the fitted mean is \(3+3+2+\hat\beta_3=11\), giving \(\hat\beta_3=3\).

Thus the fitted model is \(E(L_1\mid L_0,A_0)=3+3L_0+2A_0+3L_0A_0\). For the history \(L_0=1,A_0=1\), the predicted conditional mean is \(3+3+2+3=11\) units of \(L_1\). This is a model for the covariate transition after \(A_0\), not a causal effect estimate by itself. A distributional model may also be needed if the g-formula requires more than this conditional mean.

Include the Relevant Treatment History

The terminal outcome model generally needs the treatment history, not just the most recent treatment. For two treatment times, one possible linear predictor includes \(A_0\), \(A_1\), and their product \(A_0A_1\). The product allows the conditional association of \(A_1\) with the outcome to differ according to \(A_0\). Covariates that predict the outcome or describe time-varying confounding may also need to appear in the model.

An interaction is not automatically required in every analysis. It is a way to represent effect modification on the model’s link scale. If the interaction is omitted, the model imposes a restriction: for a logistic model, for example, the conditional log-odds contrast for \(A_1\) is the same at each value of \(A_0\), given the other included covariates. Whether that restriction is plausible should be guided by subject-matter knowledge and the intended model, rather than by a search for whichever specification gives a preferred result.

Worked Example: A Binary Outcome With Treatment-History Interaction

Suppose a hypothetical dataset yields the following fitted logistic model for a binary outcome \(Y\), conditional on \(L_1,A_0,A_1\):

$$ \operatorname{logit}\{P(Y=1\mid L_1,A_0,A_1)\} =-2+0.4L_1+0.8A_0+0.5A_1+1.0A_0A_1. $$

Here \(\operatorname{logit}(p)=\log\{p/(1-p)\}\). Consider the history \(L_1=1,A_0=1,A_1=0\). The fitted linear predictor is \(-2+0.4(1)+0.8(1)+0.5(0)+1.0(1)(0)=-0.8\). Converting from log odds to probability gives

$$ \hat p=\frac{1}{1+\exp(-(-0.8))} =\frac{1}{1+\exp(0.8)} \approx 0.3100. $$

For the same \(L_1=1,A_0=1\) history but with \(A_1=1\), the linear predictor is \(-2+0.4+0.8+0.5+1.0=0.7\), and the fitted probability is \(1/\{1+\exp(-0.7)\}\approx0.6682\). These are fitted conditional outcome probabilities for the stated histories. The interaction coefficient means that the conditional log-odds contrast for \(A_1\) is \(0.5+1.0A_0\): it is \(0.5\) when \(A_0=0\) and \(1.5\) when \(A_0=1\), holding \(L_1\) fixed.

The coefficients here are hypothetical fitted estimates; the calculation illustrates how to use them, not how to estimate them from a particular dataset. Logistic-regression estimates are ordinarily obtained by maximizing the binomial likelihood. For observed binary outcomes \(y_i\) and fitted probabilities \(p_i\), the likelihood is \(\prod_i p_i^{y_i}(1-p_i)^{1-y_i}\). The history terms in the predictor must match the ordering and variables actually observed before the outcome.

Fit Each Conditional Factor, Then Check Its Specification

A practical fitting sequence follows the data-generating order. First specify a model for each covariate transition \(L_{t+1}\mid H_t,A_t\), using the treatment and covariates observed before that transition. Then specify the terminal outcome model \(Y\mid\bar L_K,\bar A_K\). For each factor, declare the outcome type, link or distribution, included history, and any interactions. This makes clear which model supplies each part of the parametric g-formula.

1
Map the time order.
List when each \(L_t\), \(A_t\), and \(Y\) is measured. Include only information available by the time the variable being modelled is generated.
2
Choose a family and link.
Match the conditional model to the outcome’s support, such as a logistic model for a binary variable or a linear model for a continuous mean.
3
Represent the history.
Include relevant prior treatment and covariate information. Consider interactions when the conditional relationship may vary across treatment histories.
4
Assess adequacy.
Check whether the functional form and distributional assumptions are plausible, and whether predictions are sensible over histories that the analysis will use.

For a continuous variable, residual patterns and the plausibility of the conditional mean and variance can inform assessment. For a binary outcome, assess calibration and whether the model captures important history-specific differences. For count outcomes, assess whether the assumed variance is credible. These checks do not prove a model correct; they can reveal obvious misspecification. A flexible model with many interactions can also be unstable when some histories are sparse.

Worked Example: A Count Outcome With Exposure Time

Suppose a hypothetical analysis models a count of events \(Y\) observed over different follow-up durations. A Poisson log-link model includes treatment history and an offset for exposure time \(e\):

$$ \log E(Y\mid A_0,A_1,e) =\log(e)-1.2+0.3A_0+0.4A_1+0.5A_0A_1. $$

The offset \(\log(e)\) gives exposure time a coefficient fixed at one. For \(e=2\) person-years and history \(A_0=1,A_1=1\), the log expected count is \(\log(2)-1.2+0.3+0.4+0.5=\log(2)\). Therefore the conditional expected count is \(\exp\{\log(2)\}=2\) events over two person-years, corresponding to a modelled rate of \(2/2=1\) event per person-year.

This model assumes a Poisson conditional distribution, including equality of the conditional mean and variance. If the data show substantially greater conditional variation, a negative-binomial model may be more appropriate. Changing the family changes the distributional assumptions; it does not remove the need to specify the correct treatment and covariate history.

From Fitted Models to Causal G-Computation

Fitting a collection of conditional models does not, by itself, make their predictions causal. A causal interpretation of g-computation also relies on the identification conditions for the chosen intervention, including consistency, sequential exchangeability, and positivity. Informally, these conditions connect observed conditional distributions to the regime-specific counterfactual quantities and require relevant histories to be represented in the data. In addition, the parametric models used for the required conditional distributions must be sufficiently well specified. A model can be estimated precisely and still be wrong.

The distinction matters when choosing predictors. A model should condition on the appropriate observed history for its time point, not on variables measured later. It should also represent treatment history flexibly enough for the intended application. A coefficient from a conditional outcome regression is not automatically the regime-specific mean or causal contrast: that requires applying the fitted conditional models according to the intervention and combining the resulting predictions.

Key takeaway: Fit one conditional model for each required covariate transition and a separate model for the terminal outcome. Match each model to its variable type, use the history available at that point in time, and make any restrictions on treatment-history interactions explicit.

Common Mistakes

  • Using only the latest treatment. This can discard earlier treatment history that predicts the outcome. Specify the history needed for the conditional distribution, and assess whether interactions are required.
  • Using a model family that permits impossible predictions. A linear model can predict a binary probability outside \([0,1]\). Use a model whose link and support are appropriate for the variable.
  • Conditioning on future information. A covariate measured after a treatment decision is not part of the history available before that decision. Respect the measurement order in every transition model.
  • Calling a fitted prediction a causal effect. A conditional prediction is a model output. A causal interpretation additionally requires identification assumptions and the g-computation under the intervention.
  • Adding interactions without regard to data support. Interactions can represent history-specific relationships, but sparse histories may produce unstable estimates. Consider both the scientific rationale and the information available in each history.

Check Your Understanding

Use the time ordering and model choices from this tutorial to answer the following questions.

  1. With \(L_0,A_0,L_1,A_1,Y\) measured in that order, which variables belong in a model for \(L_1\), and which belong in a terminal model for \(Y\)?
  2. Why might a logistic model be preferable to a linear model for a binary outcome?
  3. In a logistic outcome model containing \(A_0\), \(A_1\), and \(A_0A_1\), what does the interaction allow to vary?
  4. A Poisson model includes \(\log(e)\) as an offset. If its fitted rate is 0.8 events per person-year and exposure is 3 person-years, what expected count does it imply?
  5. Why does fitting the conditional models not, on its own, establish that their predictions have a causal interpretation?
Clinical Biostats