Tutorials › Response-Adaptive Randomization › Flexible Trend Adjustment With Splines

Time Trends and Drift · Tutorial 398 of 501

Flexible Trend Adjustment With Splines

Use prespecified spline terms to adjust an outcome model for nonlinear enrollment-time drift while preserving a clear treatment contrast.

Advanced 10 min read

What You'll Learn

  • Represent nonlinear prognostic drift with prespecified spline basis terms.
  • Distinguish prognostic time adjustment from a treatment-by-time interaction.
  • Choose and report knot locations using the planned enrollment-time scale.
  • Diagnose weak treatment overlap near knots and in sparse periods.
  • Recognize how too many spline terms can overfit temporal noise.
  • Interpret adjusted treatment contrasts without treating model adjustment as a substitute for randomization.

Why Use a Flexible Time Adjustment?

In a response-adaptive trial, the allocation probabilities can change as outcomes accrue. Consequently, treatment groups may include different proportions of participants enrolled early and late. If prognosis also changes over enrollment time, a single linear time term may fail to represent that drift. A spline allows the modeled prognostic trend to bend at prespecified locations while remaining smooth or continuous, depending on the spline chosen.

The aim here is not to model every fluctuation in outcomes. It is to represent plausible, gradual changes in prognosis with a limited and interpretable set of time terms. The spline form, its knot locations, and the number of terms should be specified before inspecting outcome patterns that could guide those choices.

Definition: A spline is a function built from polynomial pieces over intervals of a predictor, joined at specified locations called knots. A linear spline is continuous and piecewise linear; a cubic spline is piecewise cubic, with continuity constraints at its knots. A spline basis is a set of functions \(B_1(t),\ldots,B_K(t)\) whose weighted sum represents the fitted time trend.

Outcome Model and Assumptions

For clarity, suppose \(Y_i\) is a continuous outcome for participant \(i\), \(A_i=1\) denotes assignment to the experimental treatment and \(A_i=0\) denotes assignment to control, and \(t_i\) is enrollment time on a prespecified scale, such as days since trial opening. Let \(X_i\) denote any other prespecified baseline covariates. A model with a flexible prognostic trend and a constant treatment contrast is

$$ E(Y_i\mid A_i,t_i,X_i) =\beta_0+\tau A_i+\gamma^\mathsf{T}X_i +\sum_{j=1}^{K}\theta_j B_j(t_i). $$

Here, \(\tau\) is the model’s treatment contrast, conditional on the included covariates and enrollment time. The spline terms describe a shared prognostic trend: this model does not include treatment-by-time interactions, so it assumes the treatment contrast is constant across enrollment time. If that assumption is not appropriate, this model alone does not describe time-varying treatment effects.

The interpretation depends on substantive and design conditions. The chosen spline basis must represent the relevant pattern of the conditional mean well enough for the intended adjustment; the outcome and time scale must be recorded meaningfully; and the model must not omit a crucial feature that makes its conditional mean unsuitable. Randomization supports a causal treatment comparison, but it does not guarantee that a chosen time function is adequate. There must also be information from both treatment groups over the time range used to compare them. Where one group is absent, the model’s comparison there relies on extrapolation rather than a within-period comparison.

For a binary or other noncontinuous outcome, an analogous model can be specified on an appropriate link scale. The coefficient interpretation then depends on that link. The examples below use a continuous outcome and an identity link, so fitted differences are in the outcome’s original units.

Building the Time Basis

A simple, transparent choice is a linear spline. With one knot at \(\kappa\), define \((t-\kappa)_+=\max(0,t-\kappa)\). Then

$$ f(t)=\theta_1t+\theta_2(t-\kappa)_+. $$

Before the knot, the slope is \(\theta_1\); after the knot, it is \(\theta_1+\theta_2\). The fitted trend is continuous at the knot, but its slope can change there. With multiple knots, include one hinge term for each knot. This is a direct way to allow a few prespecified changes in slope; it does not force a curve to bend everywhere.

Cubic splines use cubic pieces rather than straight pieces. Continuity constraints join those pieces; for a conventional cubic spline, the function and its first two derivatives are continuous at each interior knot. A natural cubic spline adds boundary constraints that make the function linear beyond the boundary knots. These choices can produce smooth trends, but they also require more careful specification and interpretation than a single linear hinge. In any implementation, the resulting basis columns—not just the phrase “cubic spline”—should be documented.

Key principle: A knot is a location where the fitted curve is allowed additional flexibility; it is not evidence that the true outcome process changes at that exact time. Choose knots from design considerations, such as the planned enrollment span and a reasonable number of temporal degrees of freedom, rather than searching for outcome-driven locations.

How the Adjustment Works

Once the basis functions and knot locations are fixed, the model is an ordinary regression on the treatment indicator, covariates, and basis columns. The spline does not require participants to be assigned in blocks or change the trial’s randomization probabilities. It adjusts the outcome comparison for the modeled time pattern.

The core justification is the conditional mean contrast. Under the model, at the same \(t\) and \(X\), the spline and other covariate terms are identical for the two treatment values:

$$ \begin{aligned} &E(Y_i\mid A_i=1,t_i,X_i)-E(Y_i\mid A_i=0,t_i,X_i)\\ &=\left[\beta_0+\tau+\gamma^\mathsf{T}X_i+\sum_{j=1}^{K}\theta_jB_j(t_i)\right] -\left[\beta_0+\gamma^\mathsf{T}X_i+\sum_{j=1}^{K}\theta_jB_j(t_i)\right] =\tau. \end{aligned} $$

Thus, if the conditional mean model is appropriate and the treatment contrast is constant, the spline represents prognostic drift without changing the model’s conditional treatment contrast. This algebra does not establish that the time function is adequate, that treatment groups overlap at every time, or that an analysis has the desired uncertainty properties. Those require separate assessment.

Worked Example: Interpreting a One-Knot Linear Spline

Suppose a hypothetical trial records a continuous symptom score in points, with higher scores indicating worse symptoms. Enrollment time \(t\) is measured in weeks from trial opening. A prespecified linear-spline model has a knot at week 6 and is fitted as

$$ \widehat{E}(Y_i\mid A_i,t_i) =50+2.4A_i+0.30t_i+0.20(t_i-6)_+. $$

For a control participant enrolled at week 4, the hinge term is zero because \((4-6)_+=0\). The fitted mean is \(50+0.30(4)=51.2\) points. For an experimental-treatment participant at the same time, it is \(51.2+2.4=53.6\) points. Under this fitted model, the experimental-minus-control contrast is 2.4 points at week 4.

At week 10, the hinge is \((10-6)_+=4\). The control fitted mean is \(50+0.30(10)+0.20(4)=53.8\) points, and the experimental fitted mean is \(53.8+2.4=56.2\) points. The modeled control trend has slope 0.30 points per week before week 6 and \(0.30+0.20=0.50\) points per week after it. The treatment contrast remains 2.4 points because no treatment-by-time term is included.

These fitted means are illustrations of the model’s arithmetic, not findings from a real study. The model describes a worsening prognostic trend in both groups; it does not imply that enrollment time causes the score to worsen.

Prespecification, Knots, and Overlap

Knot locations should be chosen on the enrollment-time scale before examining outcome results used to estimate the treatment effect. A protocol might place a small number of knots at planned quantiles of the anticipated enrollment distribution, or at other design-based locations that cover the trial’s time span. The number and placement depend on the intended flexibility and the amount of information available. There is no universally correct knot count.

In a response-adaptive trial, assess not only how many participants enroll near each knot, but also whether both treatment groups are represented through the relevant time range. A spline can be numerically fitted even when treatment overlap is poor; the existence of a coefficient estimate does not mean it is supported by close comparisons. A highly flexible curve may then use a small number of participants to shape predictions in a period where a treatment contrast is also weakly supported.

Worked Example: Reviewing Prespecified Knots and Arm Overlap

Consider a hypothetical trial planned to enroll over 100 days. Before outcome review, investigators choose linear-spline knots at days 25, 50, and 75. Their enrollment table is:

Enrollment daysExperimentalControlTotal
1–25242650
26–50232245
51–75201030
76–10018220

There are 145 participants in total: \(24+26+23+22+20+10+18+2=145\). In the final period, the experimental share is \(18/20=0.90\), while the control share is \(2/20=0.10\). Both treatments appear in that period, but the comparison is much less balanced than in the first two periods. The knot specification itself is not changed just because these observed counts are uneven; instead, the imbalance is reported and treated as a warning that estimates involving the late-period contrast may be sensitive to the model.

The table is a coarse diagnostic, not proof that overlap is adequate within every day or near every knot. Investigators should also inspect enrollment timing and allocation patterns at a useful finer resolution. If there were no controls at all late in enrollment, a fitted spline could still draw a model-based prediction there, but the late-period treatment comparison would not come from concurrent observations in that period.

Controlling Flexibility and Diagnosing Problems

Each additional spline basis term gives the model more ability to follow variation in outcomes over time. That can reduce bias when the time trend is genuinely nonlinear, but it can also fit random fluctuations, particularly in sparse periods. A useful diagnostic review includes the time distribution by treatment, the number of participants contributing to each region of the curve, fitted values over the observed range, and residual patterns over enrollment time. These checks help reveal unsupported bends, abrupt changes induced by a poor specification, or temporal structure that the fitted trend has not captured.

Diagnostics do not select a uniquely correct spline. A curve that looks smooth can still be misspecified, while a visually irregular curve may simply reflect sparse data. Report the basis and knots, check whether the fitted trend is being driven by a few observations, and avoid selecting terms solely because they produce a preferred treatment estimate or a more favorable result.

Worked Example: Recognizing an Overfit Time Curve

Suppose 60 hypothetical participants contribute to a trial model. Investigators compare a modest prespecified spline with 3 temporal basis coefficients to a much more flexible spline with 11 temporal basis coefficients. The larger model has a smaller training residual sum of squares, but the validation results are:

ModelValidation participantsValidation sum of squared errorsValidation RMSE
3 temporal coefficients20420 points squared4.583 points
11 temporal coefficients20510 points squared5.050 points

For the modest model, the validation root mean squared error is \(\sqrt{420/20}=\sqrt{21}=4.583\) points. For the more flexible model, it is \(\sqrt{510/20}=\sqrt{25.5}=5.050\) points. The more flexible model predicts these held-out outcomes less well, despite its better fit to the training outcomes. That pattern is consistent with overfitting, although a single validation split is not definitive.

If enrollment is sparse near some knots or concentrated in one treatment group, the concern is stronger: extra terms can respond to a few observations without supplying reliable information about the underlying trend. The appropriate response is not automatically to remove all flexibility. Rather, revisit whether the planned complexity is defensible, inspect the time and arm counts, and describe the sensitivity of the result to reasonable prespecified alternatives.

Common Mistakes and Alternatives

  • Assuming randomization removes temporal imbalance. Randomization governs assignment, but adaptive allocation can leave different time distributions across groups. A time adjustment may be useful when prognosis drifts.
  • Adding knots until the outcome plot looks right. This uses outcome patterns to tune the adjustment and risks fitting noise. Prespecify the basis and knots, and report any sensitivity analyses transparently.
  • Reading a prognostic spline as a treatment-effect curve. The shared time function describes modeled outcome drift. A changing treatment contrast requires treatment-by-time terms and a different model.
  • Assuming a spline repairs absent overlap. A curve can produce extrapolated fitted values where one treatment group is missing; it cannot create observed comparisons that are not present.

Compared with a linear calendar-time adjustment, a spline can represent gradual curvature or a small number of slope changes, at the cost of additional parameters and greater sensitivity to sparse data. Compared with time-stratified standardization, a spline uses a smooth functional form rather than estimating separate contrasts within time strata. Neither approach is universally preferable: a spline is attractive when a compact smooth trend is plausible, whereas stratification makes fewer functional-shape assumptions but can become unstable when periods are thin. The choice should be guided by the trial design, overlap, and prespecified analysis plan.

The main limitation is that flexible adjustment is still model-based. A spline cannot ensure that the chosen time scale captures every relevant change, nor can it resolve sparse treatment overlap, abrupt unmodeled changes, or a treatment effect that varies over time when the model assumes it is constant. It is an adjustment for a specified prognostic trend, not a guarantee of an unbiased or precise answer.

Key takeaway: Prespecify a modest spline basis to represent plausible nonlinear prognostic drift, then assess whether both treatment groups and enough participants support the fitted curve across enrollment time. Flexibility should improve representation of the time trend without pretending to replace observed overlap.

Check Your Understanding

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

  1. A linear spline has \(f(t)=0.4t+0.3(t-5)_+\). What are its slopes before and after week 5?
  2. Why does a model with a shared spline term and no treatment-by-time interaction imply a constant conditional treatment contrast?
  3. In a period with 15 experimental participants and no controls, what can a fitted treatment comparison in that period rely on?
  4. Give one reason to prespecify knot locations and one diagnostic that can reveal a problem with the fitted time adjustment.

Solutions. (1) Before week 5 the hinge is zero, so the slope is 0.4 outcome units per week. After week 5 the slope is \(0.4+0.3=0.7\) outcome units per week. (2) At fixed time and covariates, the shared spline terms are identical for \(A_i=1\) and \(A_i=0\), so they cancel in the conditional mean difference, leaving the treatment coefficient. (3) It relies on model-based extrapolation from other times; there is no within-period treatment comparison because no controls enrolled in that period. (4) Prespecification limits outcome-driven choices and supports a transparent analysis plan. Useful diagnostics include arm-specific enrollment counts over time, fitted curves, residual patterns over time, and whether a few observations dominate a bend.

Clinical Biostats