Tutorials › Marginal Structural Models › Nonlinearities and Interactions in History Models

The Parametric g-Formula · Tutorial 304 of 501

Nonlinearities and Interactions in History Models

Learn to specify and interpret nonlinear time effects and treatment-history interactions in the conditional models used by the parametric g-formula.

Advanced 12 min read

What You'll Learn

  • Specify nonlinear functions of time in conditional covariate and outcome models.
  • Interpret treatment-by-history interactions as history-dependent conditional contrasts.
  • Calculate how model terms change predicted covariate values and outcome risks.
  • Distinguish link-scale interactions from interactions on the response scale.
  • Recognize when sparse histories, unsupported combinations, or restrictive functional forms make fitted models unreliable.

Why Functional Form Matters in History Models

In the parametric g-formula, conditional models describe how covariates and outcomes vary with treatment and observed history. A model need not represent those relationships with a straight line or a constant treatment contrast. If the time trend bends, or treatment effects differ across histories, a model that omits those features can produce the wrong conditional predictions. Those predictions are the ingredients used to evaluate a treatment regime.

Write \(L_t\) for a time-varying covariate at time \(t\), \(A_t\) for treatment, and \(\bar L_{t-1}=(L_0,\ldots,L_{t-1})\), \(\bar A_{t-1}=(A_0,\ldots,A_{t-1})\) for histories through the indicated times. A generic covariate-transition model represents the conditional distribution of \(L_t\) given the history immediately preceding it. For example, its conditional mean may be written as a function of time, past covariates, and past treatment. The conditional outcome model represents the distribution of \(Y\) given the relevant treatment and covariate history.

Definition: A nonlinear time term is a model term whose contribution does not change at a constant rate with time, such as \(t^2\), a spline basis function, or an indicator for a time period. A treatment-history interaction is a term that allows a treatment association to vary with one or more features of the history, such as \(A_{t-1}L_{t-1}\) or \(A_{t-1}t\). These terms specify conditional relationships; they do not, by themselves, establish causal effects.

The model forms below are useful only under the usual requirements for the parametric g-formula: the intervention and target estimand must be well defined, the causal identification conditions must hold, and the conditional distributions used in the formula must be adequately represented by the fitted models over histories relevant to the intervention. The algebraic interpretations of particular terms require no causal assumptions, but causal conclusions do.

Nonlinear Time Effects

A linear time term imposes a constant change in the model’s linear predictor for each unit increase in time, holding other predictors fixed. For a conditional mean model, one possible extension is

$$ E[L_t\mid \bar L_{t-1},\bar A_{t-1}] =\beta_0+\beta_1t+\beta_2t^2+\beta_3L_{t-1}. $$

Here the time contribution is \(\beta_1t+\beta_2t^2\). Its change from time \(t\) to \(t+1\) is not generally constant. More flexible alternatives include piecewise-linear terms, time-period indicators, and spline basis functions. The choice should reflect the time scale and plausible pattern, while avoiding unsupported complexity.

Derived result: In a model whose time contribution is \(\beta_1t+\beta_2t^2\), the difference in that contribution between \(t+1\) and \(t\), holding all other predictors fixed, is \(\beta_1+\beta_2(2t+1)\). Thus, if \(\beta_2\ne 0\), the one-step change depends on the time point.

To verify this, subtract the contribution at \(t\) from the contribution at \(t+1\):

$$ \begin{aligned} \{\beta_1(t+1)+\beta_2(t+1)^2\} -\{\beta_1t+\beta_2t^2\} &=\beta_1+\beta_2\{(t+1)^2-t^2\}\\ &=\beta_1+\beta_2(2t+1). \end{aligned} $$

This is a conditional model contrast, not necessarily the difference between actual covariate values at successive times. In a longitudinal process, \(L_{t-1}\) and other history variables can also change between times.

Worked Example: A Curved Conditional Time Pattern

Suppose a continuous covariate follows the conditional mean model

$$ E[L_t\mid L_{t-1},\text{other history}] =10+2t-0.5t^2+0.8L_{t-1}, $$

and consider predictions at \(t=1,2,3\), holding \(L_{t-1}=4\) and all other history fixed. The history contribution is \(0.8(4)=3.2\).

At \(t=1\), the mean is \(10+2-0.5+3.2=14.7\). At \(t=2\), it is \(10+4-2+3.2=15.2\). At \(t=3\), it is \(10+6-4.5+3.2=14.7\). The conditional mean rises and then falls; a linear time term alone could not reproduce this pattern with the other predictors held fixed.

The result is a comparison of conditional predictions at fixed history, not a claim that an individual’s covariate will follow these three values. In a transition model, the history itself may evolve, and the distribution of \(L_t\) may have variation around its conditional mean.

Interactions Make Conditional Contrasts History-Dependent

Suppose a binary treatment is coded \(A_{t-1}\in\{0,1\}\). Adding a product term \(A_{t-1}L_{t-1}\) to a conditional mean model allows the treatment contrast in that mean to vary with the previous covariate. The following algebra states precisely what the term means.

Derived result: In the model $$ E[L_t\mid \text{history}] =\beta_0+\beta_L L_{t-1}+\beta_A A_{t-1} +\beta_{AL}A_{t-1}L_{t-1}, $$ the conditional mean difference between \(A_{t-1}=1\) and \(A_{t-1}=0\), at fixed \(L_{t-1}=l\) and fixed remaining history, is \(\beta_A+\beta_{AL}l\).

Set \(A_{t-1}=1\) in the model and subtract its value at \(A_{t-1}=0\). The terms \(\beta_0+\beta_Ll\) cancel, leaving

$$ \{\beta_0+\beta_Ll+\beta_A+\beta_{AL}l\} -\{\beta_0+\beta_Ll\} =\beta_A+\beta_{AL}l. $$

An interaction with time works the same way: a term \(\beta_{At}A_{t-1}t\) changes the treatment contrast from \(\beta_A\) to \(\beta_A+\beta_{At}t\). Multiple interactions can be included when substantively justified, but each added term increases the demands on the data: the model must learn its parameters from observed combinations of treatment, time, and history.

Worked Example: Treatment and Time Interact in a Covariate Model

Consider the conditional mean model

$$ E[L_t\mid L_{t-1},A_{t-1}] =2+0.5L_{t-1}+0.4t-0.05t^2+0.8A_{t-1}+0.6tA_{t-1}. $$

Hold \(L_{t-1}=1\) fixed. At time \(t=2\), with \(A_{t-1}=0\), the predicted mean is \(2+0.5+0.8-0.2=3.1\). With \(A_{t-1}=1\), it is \(3.1+0.8+0.6(2)=5.1\). The treatment contrast is \(5.1-3.1=2.0\), matching \(0.8+0.6(2)\).

At \(t=4\), the untreated predicted mean is \(2+0.5+1.6-0.8=3.3\). The treated predicted mean is \(3.3+0.8+0.6(4)=6.5\). The contrast is \(6.5-3.3=3.2\). Thus the treatment-associated difference in the conditional mean is larger at \(t=4\) than at \(t=2\) under this model. The quadratic time term also changes the baseline time pattern, while the treatment-by-time term changes the treatment contrast.

These are model-based conditional predictions. Their use for a causal regime comparison additionally depends on the identification assumptions and adequate model support for the histories being compared.

Interactions in Outcome Models and the Link Scale

For a binary outcome, a logistic conditional model is often expressed on the log-odds scale. An interaction in that model describes variation in the treatment contrast on that scale. It does not imply that the probability difference varies by exactly the same numerical amount. The response-scale probabilities must be obtained by applying the inverse-logit function to each linear predictor.

Worked Example: A Treatment-by-Covariate Interaction for Risk

Suppose the conditional outcome model is

$$ \operatorname{logit}P(Y=1\mid A,L) =-2+0.5A+0.4L+0.8AL, $$

where \(A\) is binary and \(L\) is a covariate. At \(L=1\), the logit for \(A=0\) is \(-2+0.4=-1.6\), so the risk is \(1/(1+e^{1.6})\approx0.168\). For \(A=1\), the logit is \(-1.6+0.5+0.8=-0.3\), giving risk \(1/(1+e^{0.3})\approx0.426\). The risk difference is approximately \(0.426-0.168=0.258\).

At \(L=3\), the logit for \(A=0\) is \(-2+1.2=-0.8\), giving risk \(1/(1+e^{0.8})\approx0.310\). For \(A=1\), the logit is \(-0.8+0.5+2.4=2.1\), giving risk \(1/(1+e^{-2.1})\approx0.891\). The risk difference is approximately \(0.891-0.310=0.581\).

The treatment contrast on the logit scale is \(0.5+0.8L\): it is \(1.3\) at \(L=1\) and \(2.9\) at \(L=3\). The probability differences above are not those logit contrasts. This distinction matters when interpreting model coefficients and when using the fitted outcome model to obtain conditional outcome predictions.

Model Building, Diagnostics, and Limitations

A practical model should include functional terms that are plausible for the scientific setting and estimable from the observed histories. For example, centering time at a meaningful reference point can make a treatment main-effect coefficient easier to interpret when treatment interacts with time. If \(t_c=t-c\), then the treatment coefficient is the model contrast at \(t=c\), rather than at a possibly unobserved time zero. Centering changes the interpretation of coefficients but does not, by itself, change the fitted model when the corresponding terms are retained.

Check fitted predictions across time and across important history strata, not just overall averages. Warning signs include systematic residual patterns over time, implausible predicted means or probabilities, very large or unstable interaction estimates, and predictions that change sharply in history regions with few observations. For categorical transitions, examine predicted category probabilities; for continuous transitions, examine whether the fitted conditional distribution is reasonable, not only its mean. A well-fitting average can still conceal poor fit in a subgroup important to the intervention contrast.

A richer model is not automatically better. A quadratic term cannot represent every possible time pattern; a spline with many degrees of freedom can be unstable in sparse regions; and a treatment-history interaction is difficult to estimate when some treatment-history combinations are rare or absent. Extrapolating the fitted model to unsupported histories is a substantive limitation, not something that can be resolved merely by adding more terms. Conversely, omitting real curvature or effect modification can force predictions to be too simple. Model assessment and sensitivity to plausible specifications are therefore important, while causal identification and model correctness remain distinct requirements.

The central alternative to these terms is a simpler model with linear time and no interaction. It is more parsimonious and can be preferable when the data are limited and the restrictions are plausible. The flexible model permits changing trends or history-specific contrasts but requires more information and careful interpretation. In either case, terms should be evaluated on the scale of the model and the scientific question: a logit-scale interaction is not itself a risk-difference interaction.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. In a model with time contribution \(0.7t-0.1t^2\), what is the change in that contribution from \(t=2\) to \(t=3\)?
  2. For the mean model \(E[L\mid A,L_0]=1+2L_0+3A-0.5AL_0\), what is the treatment contrast at \(L_0=4\)?
  3. In a logistic outcome model with an \(A\times L\) term, does the interaction coefficient directly give the change in risk difference per unit of \(L\)? Explain.
  4. Name two indications that an interaction model may be unreliable for histories relevant to a treatment regime.

Solutions. (1) The change is \(0.7+(-0.1)\{2(2)+1\}=0.7-0.5=0.2\). (2) Subtracting the \(A=0\) mean from the \(A=1\) mean gives \(3-0.5L_0\), hence \(3-0.5(4)=1\). (3) No. The coefficient describes modification of the treatment contrast on the logit scale; probabilities require the inverse-logit transformation, so risk differences must be calculated from predicted risks. (4) Examples include very sparse treatment-history combinations, unstable or extreme interaction estimates, poor residual patterns within history strata, or implausible fitted predictions.

Clinical Biostats