Tutorials › Marginal Structural Models › Outcome Regression with Interactions and Splines

Longitudinal Targeted Maximum Likelihood · Tutorial 388 of 501

Outcome Regression with Interactions and Splines

Build flexible sequential outcome regressions and use their predictions to evaluate a specified treatment intervention across the observed covariate-history distribution.

Advanced 13 min read

What You'll Learn

  • Define the sequential outcome regressions used to evaluate a longitudinal intervention.
  • Add treatment-history interactions to represent effect modification.
  • Use spline basis terms to model nonlinear covariate relationships.
  • Carry predicted outcomes backward through treatment and covariate histories.
  • Diagnose extrapolation, sparse histories, and overly complex regression specifications.
  • Distinguish conditional regression coefficients from marginal intervention contrasts.

Why Flexible Outcome Regressions Matter

A sequential outcome regression estimates conditional means at each time, then evaluates those means under a specified intervention. Its predictions depend on how the regression represents treatment and the covariate history. A model with treatment and history only as additive linear terms may miss effect modification or curvature; a model with many interactions and spline terms may instead become unstable in sparse histories. The goal is not to make a model complicated for its own sake. It is to represent plausible conditional outcome patterns well enough to produce useful predictions under the intervention being studied.

This tutorial develops treatment-history interactions and spline terms as tools for that task. It focuses on fitting the conditional regressions and evaluating their predictions under an intervention. A regression prediction is not automatically a causal effect: causal interpretation also requires identification assumptions, including consistency, sequential exchangeability, and positivity.

Sequential Regressions and Intervention Evaluation

Let \(A_t\) be the treatment at decision time \(t\), and let \(L_t\) be the covariate information available before that treatment. Write \(H_t=(L_0,A_0,L_1,\ldots,A_{t-1},L_t)\) for the observed history just before \(A_t\). The final outcome is \(Y\). A deterministic intervention \(g\) assigns treatment \(g_t(H_t)\) at each time.

Definition: Set \(Q_{T+1}=Y\). At the final treatment time, define \(Q_T(h_T,a_T)=E[Y\mid H_T=h_T,A_T=a_T]\). For \(t<T\), define $$ Q_t(h_t,a_t)=E\left[Q_{t+1}\{H_{t+1},g_{t+1}(H_{t+1})\}\mid H_t=h_t,A_t=a_t\right]. $$ The intervention-specific regression value at time \(t\) is \(V_t(h_t)=Q_t\{h_t,g_t(h_t)\}\). The sequential outcome-regression evaluation of \(g\) is \(E[V_0(H_0)]\).

The recursion averages over the next covariate history using its conditional distribution given the current history and treatment. In practice, it is often implemented backward: regress \(Y\) on the final history and treatment; predict under the final intervention; regress those predictions on the preceding history and treatment; and continue until obtaining predictions under the initial intervention. At each step, predictions are evaluated at the treatment assigned by \(g\), not at the treatment actually received in the record.

For a causal interpretation, consistency requires that observed outcomes agree with the potential outcomes under the treatments actually received. Sequential exchangeability requires that, conditional on each \(H_t\), treatment assignment is independent of the relevant future potential outcomes. Positivity requires that each treatment assigned by \(g\) has support in the observed treatment distribution at histories where the intervention is evaluated. These assumptions do not ensure that a chosen regression model is correctly specified; they identify the target, while the regression specification governs estimation.

Interactions and Spline Terms

An interaction allows the conditional association between treatment and outcome to vary with history. For example, with binary treatment \(A\) and binary covariate \(L\), a logistic model can include \(A\), \(L\), and \(A L\). The interaction coefficient is a difference on the log-odds scale; it is not itself a risk difference. The fitted risks for each treatment must be predicted and contrasted on the outcome scale of interest.

A spline represents a nonlinear association using several basis functions. For example, a piecewise-linear spline with knot \(c\) can use \(L\) and \((L-c)_+=\max(L-c,0)\). This allows the slope to change at \(c\), while keeping the fitted function continuous there. More flexible spline bases can use several knots or restricted cubic splines. Treatment interactions with spline basis terms allow the shape of the covariate-outcome relationship to differ by treatment.

Worked Example: A Treatment-History Interaction

Suppose \(L\) is binary and the fitted conditional risk is $$ \operatorname{expit}(-1+0.8A+0.6L+0.7AL), $$ where \(\operatorname{expit}(x)=1/(1+e^{-x})\). In the target population, \(P(L=1)=0.4\) and \(P(L=0)=0.6\). Evaluate the risks under interventions \(A=1\) and \(A=0\).

For \(L=0\), the linear predictors are \(-1\) under \(A=0\) and \(-1+0.8=-0.2\) under \(A=1\). Thus the risks are \(\operatorname{expit}(-1)=0.2689414\) and \(\operatorname{expit}(-0.2)=0.4501660\); their difference is \(0.1812246\), or \(0.1812\) to four decimal places.

For \(L=1\), the linear predictors are \(-1+0.6=-0.4\) under \(A=0\), and \(-1+0.8+0.6+0.7=1.1\) under \(A=1\). The risks are \(\operatorname{expit}(-0.4)=0.4013123\) and \(\operatorname{expit}(1.1)=0.7502601\). Their difference is \(0.3489478\), or \(0.3489\) to four decimal places.

Average the two predicted risks within each intervention using the target distribution of \(L\): $$ \begin{aligned} \widehat\psi(1)&=0.6(0.4501660)+0.4(0.7502601)=0.5702036,\\ \widehat\psi(0)&=0.6(0.2689414)+0.4(0.4013123)=0.3218898,\\ \widehat\psi(1)-\widehat\psi(0)&=0.2483138. \end{aligned} $$ The interaction permits the treatment contrast to differ across \(L\). The marginal contrast is the difference between the averaged risks, not the interaction coefficient \(0.7\).

Worked Example: A Piecewise-Linear Spline With Treatment Interaction

Let \(L\) be a continuous covariate and use the spline term \((L-5)_+\), with knot at 5. Consider the logistic regression $$ \operatorname{logit} Q(L,A)=-2+0.15L+0.25(L-5)_++0.7A+0.4A(L-5)_+. $$ Evaluate its predictions at \(L=4\) and \(L=8\), then average under \(A=1\) and \(A=0\) for a population with probability \(2/3\) at \(L=4\) and \(1/3\) at \(L=8\).

At \(L=4\), the spline term is zero. The logit is \(-2+0.15(4)=-1.4\) for \(A=0\), and \(-1.4+0.7=-0.7\) for \(A=1\). The risks are \(\operatorname{expit}(-1.4)=0.1978161\) and \(\operatorname{expit}(-0.7)=0.3318122\).

At \(L=8\), the spline term is \(8-5=3\). The logit is \(-2+0.15(8)+0.25(3)=-0.05\) for \(A=0\), and \(-0.05+0.7+0.4(3)=1.85\) for \(A=1\). The risks are \(\operatorname{expit}(-0.05)=0.4875026\) and \(\operatorname{expit}(1.85)=0.8641271\).

The intervention-specific averages are $$ \begin{aligned} \widehat\psi(0)&=\tfrac{2}{3}(0.1978161)+\tfrac{1}{3}(0.4875026)=0.2943783,\\ \widehat\psi(1)&=\tfrac{2}{3}(0.3318122)+\tfrac{1}{3}(0.8641271)=0.5092505,\\ \widehat\psi(1)-\widehat\psi(0)&=0.2148722. \end{aligned} $$ The hinge term changes the slope above 5, while its interaction with \(A\) lets the treatment contrast change above the knot. The averages use the specified target distribution; they are not predictions at an “average” value of \(L\).

Backward Evaluation Across Two Decisions

In a longitudinal analysis, an intervention can change the distribution of later covariates by changing earlier treatment. The next example makes that averaging explicit. Suppose there is no baseline covariate, \(A_0\) is the first treatment, \(L_1\) is a binary intermediate covariate, and \(A_1\) is the second treatment. Assume the fitted final outcome regression gives the following risks.

\(A_0\)\(A_1\)\(Q_1(L_1=0,A_0,A_1)\)\(Q_1(L_1=1,A_0,A_1)\)
000.100.30
010.200.50
100.150.40
110.350.70

Worked Example: Evaluating a Sustained Two-Time Intervention

Suppose \(P(L_1=1\mid A_0=0)=0.2\) and \(P(L_1=1\mid A_0=1)=0.6\). Evaluate the sustained interventions \(g=(0,0)\) and \(g=(1,1)\).

Under \(g=(0,0)\), the first treatment is \(A_0=0\), so the relevant distribution of \(L_1\) has probability 0.2 at 1 and 0.8 at 0. The final regression predicts 0.10 at \(L_1=0\) and 0.30 at \(L_1=1\) when \(A_0=A_1=0\). Thus the value after the first decision is $$ Q_0(0,0)=0.8(0.10)+0.2(0.30)=0.14. $$

Under \(g=(1,1)\), the first treatment is \(A_0=1\), so \(P(L_1=1)=0.6\) under the specified covariate transition. The final regression predicts 0.35 at \(L_1=0\) and 0.70 at \(L_1=1\) when \(A_0=A_1=1\). Therefore $$ Q_0(0,1)=0.4(0.35)+0.6(0.70)=0.14+0.42=0.56. $$ The model-based contrast is \(0.56-0.14=0.42\). Both the outcome regression and the intermediate-covariate distribution matter: using the \(A_0=0\) distribution of \(L_1\) for the \(A_0=1\) intervention would instead give \(0.8(0.35)+0.2(0.70)=0.42\), which evaluates the wrong intervention distribution.

Why the Backward Recursion Works

Theorem: Suppose consistency, sequential exchangeability, and positivity hold for a deterministic intervention \(g\). Suppose each conditional mean in the definition of \(Q_t\) is the true conditional mean. Then \(E[V_0(H_0)]\) equals the mean potential outcome under \(g\), \(E[Y^g]\).

Proof. Under \(g\), consistency identifies the observed outcome with the potential outcome for individuals whose treatment history follows \(g\). Sequential exchangeability and positivity imply that, conditional on a history and treatment assigned by \(g\), the next covariate has the same conditional distribution as the observed covariate given that history and treatment. At the final time, the conditional mean of the outcome under the assigned treatment is therefore \(Q_T(H_T,g_T(H_T))=V_T(H_T)\).

Now proceed backward. If \(V_{t+1}\) gives the conditional mean of the future outcome under \(g\), then conditioning on \(H_t\) and assigning \(A_t=g_t(H_t)\) gives $$ E[Y^g\mid H_t\text{ follows }g]=E[V_{t+1}(H_{t+1})\mid H_t,A_t=g_t(H_t)] =Q_t\{H_t,g_t(H_t)\}=V_t(H_t). $$ The first equality averages over the next covariate history under its conditional distribution given the assigned treatment. Repeating this equality through \(t=0\) and averaging over the baseline distribution gives \(E[Y^g]=E[V_0(H_0)]\). \(\square\)

Result: An interaction coefficient is not generally a marginal intervention contrast. The contrast must be formed from outcome-scale predictions and then averaged over the target history distribution.

Justification. Even in a single-time logistic model, the risk is a nonlinear function of the linear predictor. For the first example, the conditional risk differences are 0.1812246 at \(L=0\) and 0.3489478 at \(L=1\), whereas the marginal risk difference is \(0.2483138\). The coefficient on \(A L\) is 0.7 on the log-odds scale, so it is neither of those conditional risk differences nor their population average. Averaging must follow prediction on the scale of the target parameter. \(\square\)

Specification, Diagnostics, and Alternatives

A main-effects-only model is simpler and may be adequate when treatment effects and covariate relationships are plausibly stable across history. It can be badly misleading when effects vary by prior treatment or covariate level. Fully stratifying by every history avoids imposing a shared functional form, but rapidly creates empty or very small cells. Interactions and splines offer a middle ground: they encode particular forms of variation while sharing information across histories. That flexibility still relies on modeling choices.

  • Inspect predicted risks. For binary outcomes, check that risks lie in \([0,1]\), and examine whether predictions are extreme or nearly constant across histories where variation is expected.
  • Check overlap in the histories used by the intervention. A model may return a prediction where few or no observations support it. Such extrapolation is not repaired by adding spline terms.
  • Check the basis and interactions. Confirm the knot locations, reference levels, and treatment-history coding. An omitted interaction can impose a constant treatment contrast; an unnecessary large interaction set can produce unstable fits.
  • Compare reasonable specifications. Examine whether intervention predictions change materially under simpler or modestly more flexible bases. Large changes can signal weak support or functional-form sensitivity.

These checks do not prove correct specification or the identification assumptions. They help find coding errors and reveal where the estimate depends on extrapolation. Spline knots and interaction terms should be selected with the scientific question and the amount of data in mind. A flexible model cannot compensate for a treatment history that is absent from the data.

Common Mistake

A common error is to interpret the treatment coefficient, or an interaction coefficient, as the marginal treatment effect. In a nonlinear model, coefficients describe changes on the model’s link scale, and the effect may vary across histories. The correction is to predict each person’s outcome under each specified intervention, carry those predictions backward through the sequential regressions, average over the target baseline distribution, and contrast the resulting means. Another error is to evaluate a later treatment intervention while holding the intermediate-covariate distribution fixed at its observed marginal distribution. Instead, propagate the covariate distribution conditional on the earlier treatment prescribed by that intervention.

Check Your Understanding

Answer each question, then compare with the short solutions.

  1. Why does an \(A L\) term allow the treatment association to vary with \(L\), and why is its coefficient not generally a marginal risk difference?
  2. For a piecewise-linear spline with knot \(c=5\), what are the values of \(L\) and \((L-5)_+\) at \(L=3\) and \(L=8\)?
  3. In a two-decision regime, why might the distribution of \(L_1\) used to evaluate the second decision depend on the first assigned treatment?
  4. What is the problem with predicting under a treatment history that has little or no support in the observed data?

Solutions. (1) The product changes the treatment term as \(L\) changes, so the conditional contrast varies; in a logistic model the coefficient is on the log-odds scale and predictions must be averaged on the risk scale. (2) At \(L=3\), the basis values are \(3\) and \(0\); at \(L=8\), they are \(8\) and \(3\). (3) Earlier treatment can affect the intermediate covariate, so the intervention-specific distribution is conditional on that assigned treatment. (4) The regression must extrapolate beyond observed support, making predictions unreliable and undermining the positivity condition needed for causal interpretation.

Clinical Biostats