Tutorials › Biostatistics › Handling Non-Linear Trajectories in Longitudinal Data

Longitudinal Data Analysis

Handling Non-Linear Trajectories in Longitudinal Data

A practical guide to recognizing and modeling non-linear change over time in longitudinal clinical data using polynomial terms, categorical time, piecewise models, splines, mixed-effects models, and flexible trajectory specifications in R and SAS.

Advanced 18 min read

What You'll Learn

  • How to recognize when a linear time effect is inadequate
  • How polynomial, categorical, piecewise, and spline time effects differ
  • How to incorporate non-linear time effects into mixed-effects models
  • How random slopes and random effects interact with non-linear trajectories
  • How to implement flexible longitudinal models in R and SAS
  • How to choose a trajectory specification based on the scientific question

Introduction

Longitudinal clinical studies repeatedly measure an outcome for the same participants over time. Examples include blood pressure, forced expiratory volume, disease activity scores, tumor measurements, cognitive scores, biomarkers, and patient-reported outcomes.

A fundamental question is not simply whether the outcome changes, but how it changes over time.

A linear model assumes that the average change is described adequately by a constant slope. That assumption can be reasonable over a limited follow-up period, but many clinical processes do not evolve at a constant rate.

A treatment may produce a rapid initial response followed by a plateau. A biomarker may fall rapidly and then stabilize. A disease score may improve slowly at first, change rapidly during the middle of follow-up, and then level off.

These patterns are examples of non-linear trajectories.

Key idea: A non-linear trajectory does not necessarily require a completely different longitudinal model. Often the same mixed-effects framework can be retained while replacing a simple linear time effect with a more flexible function of time.

What Does "Non-Linear Over Time" Mean?

Suppose the outcome for participant \(i\) at time \(t\) is \(Y_i(t)\). A simple linear trajectory is:

\[ Y_i(t)=\beta_0+\beta_1t+\varepsilon_i(t) \]

The parameter \(\beta_1\) represents the average change per unit increase in time.

The important feature is that the slope is constant.

\[ \frac{dE[Y(t)]}{dt}=\beta_1 \]

A non-linear trajectory allows the rate of change to vary with time:

\[ \frac{dE[Y(t)]}{dt}=f(t) \]

where \(f(t)\) is not constant.

For example, the treatment effect might be largest shortly after treatment initiation and progressively diminish later.

Why a Linear Time Effect Can Be Inadequate

Consider a hypothetical clinical trial in which a symptom score is measured at baseline and at Weeks 2, 4, 8, 12, and 24. Suppose the mean trajectory is approximately:

Week Mean Change from Baseline
0 0.0
2 -4.5
4 -7.5
8 -10.0
12 -10.8
24 -11.1

The treatment appears to have a rapid early effect followed by a plateau.

A single straight line through these observations would force the early and late changes to be summarized by one average slope.

That may obscure the clinically important feature of the data: the rate of improvement decreases over time.

Warning sign: If residuals systematically curve upward or downward when plotted against time, a linear time specification may be inadequate even if the overall treatment effect is statistically significant.

First Principle: Look at the Data

Before selecting a complicated model, examine the observed trajectories.

Useful plots include:

  • Individual subject profiles
  • Mean outcome by visit
  • Mean change from baseline by visit
  • Mean treatment-group trajectories
  • Spaghetti plots with an overlaid mean trajectory
  • Observed-versus-fitted plots
  • Residuals versus time

A trajectory model should be motivated by the pattern of the data and the scientific question, not simply by the availability of a sophisticated statistical method.

Common Shapes of Longitudinal Trajectories

Pattern Typical Shape Potential Model
Constant change Straight line Linear time
Accelerating change Increasing curvature Quadratic or spline
Decelerating change Rapid early change, then plateau Quadratic, spline, exponential
Early change followed by stable period Two distinct slopes Piecewise model
Irregular visit pattern Flexible smooth curve Spline
Distinct visit-specific effects No assumed shape Categorical time
Asymptotic response Approaches a limit Nonlinear mechanistic model

Approach 1: Categorical Time

The simplest flexible alternative to linear time is to treat visit as a categorical variable.

Instead of assuming:

\[ E[Y(t)]=\beta_0+\beta_1t \]

we allow every scheduled visit to have its own mean:

\[ E[Y(t)] = \beta_0+\beta_1I(t_1)+\beta_2I(t_2)+\cdots+\beta_kI(t_k) \]

where the indicator variables represent the scheduled visits.

This approach makes almost no assumption about the shape of the trajectory.

Major advantage: Categorical time is often an excellent default when the primary scientific question concerns differences at specific clinical visits rather than a continuous rate of change over time.

Why Categorical Time Is So Flexible

Suppose measurements occur at Weeks 0, 2, 4, 8, 12, and 24. A categorical-time model can estimate:

  • The mean at Week 2
  • The mean at Week 4
  • The mean at Week 8
  • The mean at Week 12
  • The mean at Week 24

without requiring the trajectory to be linear, quadratic, or otherwise smooth.

The disadvantage is that categorical time does not provide a compact mathematical description of the underlying curve.

Approach 2: Polynomial Time

A common way to introduce curvature is to add powers of time. A quadratic model is:

\[ E[Y(t)] = \beta_0+\beta_1t+\beta_2t^2 \]

The first derivative is:

\[ \frac{dE[Y(t)]}{dt} = \beta_1+2\beta_2t \]

Therefore, the slope changes with time.

If \(\beta_2<0\), the trajectory is concave downward. If \(\beta_2>0\), the trajectory is concave upward.

Quadratic Example

Suppose the fitted model is:

\[ E[Y(t)] = 100-4t+0.15t^2 \]

The instantaneous slope is:

\[ \frac{dE[Y(t)]}{dt} = -4+0.30t \]

At \(t=0\), the slope is \(-4\). At \(t=5\), the slope is:

\[ -4+0.30(5)=-2.5 \]

Thus, the outcome is decreasing rapidly initially, but the rate of decrease becomes progressively smaller.

This is a useful model for a trajectory that improves rapidly and then begins to plateau.

Centering Time

Polynomial models can become difficult to interpret when time is large. Suppose follow-up extends to 52 weeks. Using \(t\) and \(t^2\) directly can produce large numerical values.

One solution is to center time:

\[ t_c=t-t_0 \]

where \(t_0\) is a clinically meaningful reference point.

For example:

\[ t_c=t-12 \]

means that \(t_c=0\) corresponds to Week 12.

Practical benefit: Centering time often makes the intercept easier to interpret and can reduce correlation between polynomial terms such as \(t\) and \(t^2\).

Polynomial Models Beyond Quadratic

A cubic model is:

\[ E[Y(t)] = \beta_0+\beta_1t+\beta_2t^2+\beta_3t^3 \]

Higher-order polynomials can represent increasingly complicated curves. However, adding polynomial terms indiscriminately is usually not a good strategy.

High-degree polynomials can produce unstable behavior, particularly near the boundaries of the observed time range.

Rule of thumb: Use the lowest-order polynomial that adequately represents the scientific trajectory. A quadratic model is often easier to explain and more stable than a high-degree polynomial.

Approach 3: Piecewise Linear Models

A piecewise linear model is useful when the trajectory has different rates of change during distinct periods.

Suppose treatment response changes rapidly during the first 8 weeks and then levels off. We can define:

\[ t_1=\min(t,8) \]

and:

\[ t_2=\max(t-8,0) \]

Then:

\[ E[Y(t)] = \beta_0+\beta_1t_1+\beta_2t_2 \]

Here \(\beta_1\) represents the slope before the knot at Week 8, while \(\beta_2\) represents the additional change in slope after Week 8.

Interpreting a Piecewise Model

Suppose:

\[ E[Y(t)] = 50-1.8t_1-0.3t_2 \]

Before Week 8, the slope is:

\[ -1.8 \]

After Week 8, the total slope becomes:

\[ -1.8-0.3=-2.1 \]

If instead the coefficient for \(t_2\) were \(+1.5\), the post-Week-8 slope would become:

\[ -1.8+1.5=-0.3 \]

That would describe rapid early improvement followed by a much flatter trajectory.

Clinical interpretation: Piecewise models are particularly attractive when there is a scientifically meaningful transition point, such as treatment initiation, dose escalation, induction-to-maintenance transition, or a known disease milestone.

Approach 4: Restricted Cubic Splines

Splines provide a flexible way to model non-linear time effects without requiring the entire trajectory to be described by one polynomial.

A spline divides the time range into regions connected by smooth polynomial functions.

A general spline model can be written as:

\[ E[Y(t)] = \beta_0+\sum_{j=1}^{K}\beta_jB_j(t) \]

where \(B_j(t)\) are spline basis functions.

The coefficients themselves are usually not clinically intuitive. Instead, the fitted curve and predicted differences at clinically relevant times are interpreted.

Why Splines Are Powerful

A spline can capture patterns such as:

  • Rapid early improvement
  • A middle-period acceleration
  • A plateau
  • A gradual late decline
  • Several changes in slope

without requiring the analyst to specify one exact mathematical shape.

This flexibility is especially useful when there is no obvious biological reason to select a quadratic or piecewise model.

Splines Require Restraint

More flexibility is not automatically better.

A spline with too many degrees of freedom can follow random fluctuations rather than the underlying clinical trajectory.

The resulting model may have:

  • Unstable estimates
  • Excessive curvature
  • Poor interpretability
  • Overfitting
  • Unstable predictions near the boundaries
Key principle: The number and location of knots should be selected using subject-matter knowledge, the amount and distribution of data, and a prespecified modeling strategy rather than by repeatedly trying models until one produces the smallest p-value.

Knots in a Spline Model

A knot is a location at which the polynomial pieces of a spline join. For example, if follow-up ranges from 0 to 24 weeks, knots might be placed near clinically important periods such as Weeks 4, 8, and 16.

The exact knot strategy depends on the type of spline and software implementation.

Common approaches include:

  • Clinically specified knots
  • Quantile-based knots
  • Prespecified default knot locations

The key requirement is that the choice be defensible and reproducible.

Mixed-Effects Models and Non-Linear Time

Longitudinal data contain repeated observations from the same participants. Those observations are correlated. A mixed-effects model accounts for this by including subject-specific random effects.

A linear mixed model might be written:

\[ Y_{ij} = \beta_0+\beta_1t_{ij}+b_{0i}+b_{1i}t_{ij}+\varepsilon_{ij} \]

where:

  • \(Y_{ij}\) is the outcome for participant \(i\) at visit \(j\).
  • \(\beta_0\) is the population-average intercept.
  • \(\beta_1\) is the population-average time slope.
  • \(b_{0i}\) is the participant-specific random intercept.
  • \(b_{1i}\) is the participant-specific random slope.
  • \(\varepsilon_{ij}\) is the residual error.

The important point is that the fixed-effect representation of time can be made non-linear while retaining the mixed-effects structure.

Quadratic Mixed-Effects Model

For example:

\[ Y_{ij} = \beta_0+\beta_1t_{ij}+\beta_2t_{ij}^2 +b_{0i}+b_{1i}t_{ij} +\varepsilon_{ij} \]

The population-average trajectory is quadratic, while participants are allowed to have different intercepts and linear rates of change.

The model can be extended to include a random quadratic component, although this requires substantially more information and may be difficult to estimate reliably.

Random Effects Do Not Automatically Make the Trajectory Non-Linear

This distinction is important. A model with a random intercept and random slope:

\[ Y_{ij} = \beta_0+\beta_1t_{ij} +b_{0i}+b_{1i}t_{ij} +\varepsilon_{ij} \]

still assumes that each participant follows a linear trajectory.

The participants can have different starting levels and different slopes, but each individual trajectory is still a straight line.

Critical distinction: Random effects model between-subject heterogeneity. Non-linear time terms model the shape of the trajectory. They address different features of longitudinal data and can be used together.

Adding Treatment to a Non-Linear Time Model

Suppose a randomized trial compares treatment \(A\) with control \(C\). A quadratic trajectory model might be:

\[ Y_{ij} = \beta_0 +\beta_1t_{ij} +\beta_2t_{ij}^2 +\beta_3T_i +\beta_4T_it_{ij} +\beta_5T_it_{ij}^2 +b_{0i} +b_{1i}t_{ij} +\varepsilon_{ij} \]

where \(T_i=1\) for treatment and \(T_i=0\) for control.

The treatment-by-time terms allow the treatment groups to have different trajectory shapes.

Why the Treatment-by-Time Interaction Matters

Suppose treatment produces faster early improvement but the groups become similar later. A simple treatment main effect would not adequately describe that pattern.

The interaction:

\[ T_i\times f(t) \]

allows the treatment effect to vary over time.

For a quadratic model, this can involve:

\[ T_i\times t \]

and:

\[ T_i\times t^2 \]

The resulting treatment difference is a function of time rather than a single constant number.

Treatment Effect as a Function of Time

For the quadratic model above, the treatment-control difference at time \(t\) is:

\[ \Delta(t) = \beta_3+\beta_4t+\beta_5t^2 \]

This is often much more clinically informative than interpreting \(\beta_3\), \(\beta_4\), and \(\beta_5\) separately.

The analyst can estimate \(\Delta(t)\) at clinically meaningful visits such as Weeks 4, 8, 12, and 24.

Best practice: When time is modeled flexibly, emphasize estimated treatment differences and confidence intervals at clinically relevant times or estimated marginal means, rather than relying primarily on individual polynomial or spline coefficients.

Non-Linear Trajectory Does Not Mean Non-Linear Treatment Effect

These concepts should not be confused. A study may have a non-linear outcome trajectory in both groups while the treatment difference remains approximately constant.

For example:

\[ E[Y(t)\mid T=0] = 100-5t+0.2t^2 \] and:

\[ E[Y(t)\mid T=1] = 95-5t+0.2t^2 \]

Both trajectories are non-linear, but:

\[ \Delta(t)=-5 \]

is constant.

Therefore, a non-linear time trend does not automatically imply a time-varying treatment effect.

Visit as a Categorical Variable in Clinical Trials

In many confirmatory clinical trials, scheduled visit is treated as categorical rather than continuous.

This is often particularly attractive when:

  • Visits are irregularly spaced.
  • The primary comparison is defined at a specific endpoint visit.
  • The shape of the trajectory is not itself scientifically important.
  • There is no compelling reason to assume a particular mathematical form.
  • The number of scheduled visits is moderate.

For example, Week 12 and Week 24 can have independent effects without assuming that the difference between Weeks 12 and 24 follows the same rate of change as earlier intervals.

Continuous Time vs. Categorical Time

Feature Continuous Time Categorical Time
Assumes functional form Yes No specific shape
Handles irregular observation times Yes Less naturally
Easy visit-specific estimates Requires prediction Yes
Compact trajectory description Yes No
Can model smooth curves Yes No
Interpretability Depends on parameterization Usually straightforward

Handling Irregular Measurement Times

One major advantage of continuous-time modeling is that time can be represented using the actual measurement time rather than merely the scheduled visit.

Suppose participants have observations at:

  • Day 0
  • Day 13
  • Day 29
  • Day 57
  • Day 91

A continuous-time model can use the actual day value.

Categorical visit coding would treat observations according to visit labels, which may be preferable when the estimand is explicitly visit based.

Design consideration: The choice between scheduled visit and actual time should reflect the scientific estimand. Do not automatically substitute actual elapsed time for visit simply because it is available.

Example: Rapid Early Response Followed by Plateau

Consider a clinical outcome measured over 24 weeks. The observed group means suggest:

Week Observed Mean Change
0 0.0
2 -3.8
4 -6.9
8 -9.4
12 -10.2
24 -10.5

A linear model might estimate an average slope of approximately:

\[ \frac{-10.5}{24}\approx-0.44 \]

But that does not mean the treatment changes the outcome by 0.44 units every week.

The actual trajectory suggests much faster change during the first several weeks.

A quadratic or spline model can represent this changing rate.

Comparing Candidate Models

Model Strength Limitation
Linear Simple and interpretable Cannot represent curvature
Quadratic Simple curvature Can behave poorly at boundaries
Cubic More flexible polynomial Potential instability
Categorical visit Highly flexible and visit-specific Less parsimonious
Piecewise linear Clinically interpretable slope changes Requires knot selection
Restricted cubic spline Flexible smooth trajectory Less intuitive coefficients

Model Selection Should Not Be Based Only on P-Values

Suppose a quadratic term has a p-value of 0.03. That does not automatically mean the quadratic model is the correct clinical model.

Likewise, a non-significant quadratic term does not prove that the true trajectory is linear.

Model selection should consider:

  • Scientific plausibility
  • Graphical fit
  • Residual behavior
  • Clinical interpretability
  • Prespecified analysis strategy
  • Stability of estimates
  • Model complexity
  • Ability to estimate the desired treatment effect

Residual Diagnostics

Residual plots are particularly useful for identifying an inappropriate time specification.

For a linear model, plot residuals against time.

If residuals display a systematic pattern such as:

  • Positive residuals early
  • Negative residuals in the middle
  • Positive residuals late

then the fitted line may be missing curvature.

A successful non-linear model should reduce systematic structure in the residuals.

Observed vs. Fitted Trajectories

A particularly useful diagnostic is to overlay:

  • Observed mean values
  • Linear fitted trajectory
  • Quadratic fitted trajectory
  • Spline fitted trajectory

This allows investigators to determine whether increased model complexity actually provides a meaningful improvement in the trajectory.

Mixed Model Covariance and Non-Linear Time Are Different Decisions

Two separate modeling decisions are sometimes confused.

The first is the mean trajectory:

\[ E[Y(t)] \]

The second concerns the within-subject covariance:

\[ \operatorname{Cov}(Y_i) \]

A non-linear mean trajectory does not determine the appropriate covariance structure.

For example, a study might use:

  • A quadratic mean trajectory
  • Random intercepts and slopes
  • An unstructured residual covariance

or:

  • A spline mean trajectory
  • Random intercepts
  • AR(1) residual covariance

These are separate components of the longitudinal model.

Important: Do not use a complicated covariance structure as a substitute for an inadequate mean trajectory. Likewise, adding a spline does not automatically solve residual correlation.

R: Linear Mixed Model

A basic linear mixed model can be fitted using lmer() from the lme4 package.

library(lme4)

fit_linear <- lmer(
  change ~ week + treatment + week:treatment +
    (1 + week | subject),
  data = dat
)

summary(fit_linear)

This model allows:

  • A linear population-average time trend
  • A treatment effect
  • A treatment-by-time interaction
  • Subject-specific random intercepts
  • Subject-specific random slopes

R: Quadratic Mixed Model

To allow curvature:

fit_quad <- lmer(
  change ~ week + I(week^2) +
    treatment +
    week:treatment +
    I(week^2):treatment +
    (1 + week | subject),
  data = dat
)

summary(fit_quad)

The fixed-effect component now allows each treatment group to have a quadratic trajectory.

Centering Time in R

dat$week_c <- dat$week - 12

fit_quad <- lmer(
  change ~ week_c + I(week_c^2) +
    treatment +
    week_c:treatment +
    I(week_c^2):treatment +
    (1 + week_c | subject),
  data = dat
)

Here, zero corresponds to Week 12. The intercept therefore has a more clinically meaningful interpretation.

R: Categorical Visit

dat$visit <- factor(dat$visit)

fit_visit <- lmer(
  change ~ visit * treatment +
    (1 | subject),
  data = dat
)

summary(fit_visit)

This model estimates treatment differences separately across visits without requiring a linear or polynomial trajectory.

R: Natural Cubic Splines

The splines package provides a convenient way to fit natural cubic splines.

library(splines)

fit_spline <- lmer(
  change ~ ns(week, knots = c(4, 8, 16)) *
    treatment +
    (1 | subject),
  data = dat
)

summary(fit_spline)

The treatment interaction allows the trajectory to differ between groups.

Interpretation: Do not attempt to interpret the individual spline basis coefficients as if they were ordinary clinical slopes. Generate predicted trajectories and treatment contrasts at clinically relevant times.

R: Estimated Treatment Differences

For a flexible model, one useful approach is to estimate marginal means at specific times.

library(emmeans)

emm <- emmeans(
  fit_spline,
  ~ treatment | week,
  at = list(
    week = c(2, 4, 8, 12, 24)
  )
)

pairs(emm)

This produces treatment comparisons at clinically meaningful time points.

SAS: Linear Mixed Model

In SAS, the standard procedure for many linear mixed-effects longitudinal models is PROC MIXED.

proc mixed data=dat;
    class subject treatment;
    
    model change =
        week
        treatment
        week*treatment
        / solution ddfm=kr;
        
    random intercept week
        / subject=subject
          type=un;
run;

This specifies random intercepts and random slopes with an unstructured covariance matrix for the random effects.

SAS: Quadratic Time

data dat2;
    set dat;
    
    week_c = week - 12;
    week_c2 = week_c * week_c;
run;

proc mixed data=dat2;
    class subject treatment;
    
    model change =
        week_c
        week_c2
        treatment
        week_c*treatment
        week_c2*treatment
        / solution ddfm=kr;
        
    random intercept week_c
        / subject=subject
          type=un;
run;

The centered quadratic model allows the average trajectory to curve over time while retaining participant-specific random intercepts and slopes.

SAS: Categorical Visit

proc mixed data=dat;
    class subject treatment visit;
    
    model change =
        visit
        treatment
        visit*treatment
        / solution ddfm=kr;
        
    random intercept
        / subject=subject;
run;

This approach is often very useful when the primary estimand is defined at specific scheduled visits.

SAS: Spline Basis Variables

SAS can generate spline basis variables using procedures such as PROC TRANSREG, or analysts can construct basis variables using appropriate spline functions and then fit those variables in PROC MIXED.

A conceptual workflow is:

/* Generate or define spline basis variables first */

proc mixed data=dat_spline;
    class subject treatment;
    
    model change =
        spline1
        spline2
        spline3
        treatment
        spline1*treatment
        spline2*treatment
        spline3*treatment
        / solution ddfm=kr;
        
    random intercept
        / subject=subject;
run;

The exact basis construction should be aligned with the prespecified spline method and knot locations.

Piecewise Models in R

A piecewise model can be constructed explicitly.

dat$week_early <- pmin(dat$week, 8)
dat$week_late  <- pmax(dat$week - 8, 0)

fit_piecewise <- lmer(
  change ~ week_early +
    week_late +
    treatment +
    week_early:treatment +
    week_late:treatment +
    (1 + week_early | subject),
  data = dat
)

summary(fit_piecewise)

The coefficient for week_early describes the early slope. The coefficient for week_late represents the change in slope after the Week 8 knot.

Piecewise Models in Clinical Interpretation

Suppose the early slope is \(-1.5\) units per week and the post-knot slope is \(-0.2\).

The clinical interpretation is not simply that the outcome changes at \(-0.2\) after Week 8. Rather:

  • Before Week 8, the estimated rate of change is \(-1.5\) units per week.
  • After Week 8, the trajectory becomes much flatter.

This can be much easier to communicate than a high-dimensional spline model.

Non-Linear Trajectories and Baseline Adjustment

Clinical longitudinal models often adjust for baseline outcome. Suppose \(Y_{i0}\) is baseline and \(Y_{ij}\) is a post-baseline measurement. A model can include baseline as a covariate:

\[ Y_{ij} = \beta_0 +\beta_B Y_{i0} +f(t_{ij}) +\beta_TT_i +T_if(t_{ij}) +b_i +\varepsilon_{ij} \]

The exact parameterization depends on the estimand and analysis strategy.

Baseline adjustment should not be confused with the decision about whether time is linear or non-linear.

Non-Linearity Can Be Different by Treatment Group

One of the most important questions is whether the treatment groups have the same trajectory shape.

A model without a treatment-by-time interaction assumes that treatment shifts the trajectory without changing its shape.

A model with treatment-by-time interaction allows the treatment effect to change over time.

For a general function \(f(t)\):

\[ E[Y(t)\mid T] = \beta_0+f(t)+T\{\beta_T+g(t)\} \]

where \(g(t)\) represents the time-varying component of the treatment effect.

Clinical question: Before adding a highly flexible treatment-by-time interaction, ask whether the scientific question truly concerns different trajectory shapes or simply the treatment difference at one or more predefined visits.

What If the Trajectory Is Exponential?

Some biological processes naturally suggest exponential behavior. A simple exponential decay model is:

\[ Y(t)=A+Be^{-kt} \]

where:

  • \(A\) is the asymptotic level.
  • \(B\) describes the initial displacement from that level.
  • \(k\) controls the rate of decay.

This can be appropriate when the underlying scientific mechanism strongly supports exponential behavior.

However, such models are more restrictive than splines and can require nonlinear estimation.

Mechanistic vs. Statistical Non-Linearity

There are two broad reasons to use a non-linear trajectory model.

Statistical flexibility

The objective is to describe the observed trajectory without imposing an unnecessary shape. Splines are often useful here.

Mechanistic modeling

The objective is to represent a biological or pharmacological mechanism. Examples include:

  • Exponential decay
  • Logistic growth
  • Emax models
  • Compartmental models
  • Indirect-response models

Mechanistic models are especially important in pharmacokinetics, pharmacodynamics, and quantitative systems pharmacology.

Do not confuse flexibility with mechanism. A spline can fit a complex curve extremely well without explaining why the curve has that shape.

Modeling a Plateau

A plateau is one of the most common clinical trajectory patterns. A simple quadratic model can approximate a plateau over a limited follow-up period.

But if the asymptotic behavior is scientifically important, a model with an explicit asymptote may be preferable.

For example:

\[ Y(t)=A+B\left(1-e^{-kt}\right) \]

The trajectory approaches \(A+B\) as \(t\) increases.

The advantage is mechanistic interpretability. The disadvantage is that the model imposes a specific functional form.

Don't Overinterpret the Quadratic Coefficient

Suppose a quadratic mixed model estimates:

\[ \hat{\beta}_2=-0.04 \]

It is tempting to say: "The treatment has a negative quadratic effect of 0.04."

That is usually not the most useful clinical interpretation.

Instead, calculate predicted outcomes or treatment contrasts across time. For example:

Week Estimated Treatment Difference 95% CI
4 -4.1 -6.2 to -2.0
8 -7.3 -9.6 to -5.0
12 -8.5 -10.8 to -6.2
24 -8.7 -11.2 to -6.2

This directly communicates how the treatment effect evolves over time.

Non-Linearity and Missing Data

Longitudinal studies frequently contain missing measurements. A flexible trajectory model does not automatically solve missing-data problems.

Investigators should consider:

  • Why observations are missing
  • The assumed missing-data mechanism
  • Whether the likelihood-based model is appropriate
  • Sensitivity analyses
  • Pattern-mixture or selection models when appropriate

Under a missing-at-random assumption, mixed models estimated by maximum likelihood can use incomplete longitudinal records without requiring last-observation-carried-forward imputation.

Important: A flexible time model and a missing-data assumption are separate components. Adding splines or polynomial terms does not make missing data "ignorable."

Non-Linearity and Unequal Follow-Up

Participants may have different numbers of observations. One participant might have measurements through Week 24, while another might withdraw at Week 12.

Mixed-effects models can naturally accommodate different numbers of observations per participant under their assumed missing-data framework.

This is one reason mixed models are widely used for longitudinal clinical data.

Non-Linearity and Unequally Spaced Visits

Unequally spaced visits create another reason to think carefully about the time variable.

Suppose visits occur at Days 1, 7, 28, 84, and 168. Treating visit number as:

\[ 1,2,3,4,5 \]

implicitly assumes equal spacing.

Using actual time:

\[ 1,7,28,84,168 \]

preserves the actual temporal distances.

Which approach is appropriate depends on whether the scientific estimand is visit-based or time-based.

A Practical Model Selection Workflow

1
Plot individual and mean longitudinal trajectories.
2
Determine whether a linear trajectory appears scientifically plausible.
3
Decide whether the primary question is visit-specific or trajectory-based.
4
Consider categorical time when specific visits are the primary estimands.
5
Consider quadratic or piecewise models when the shape has a simple interpretable form.
6
Consider splines when substantial smooth flexibility is needed.
7
Add treatment-by-time terms when treatment effects may vary over time.
8
Specify appropriate random effects and covariance structure separately.
9
Evaluate fitted trajectories and residual diagnostics.
10
Report clinically interpretable estimated differences at relevant times.

How to Choose Among the Main Approaches

Situation Preferred Starting Point
Only a few scheduled visits Categorical time
Clearly curved trajectory Quadratic model
Rapid early change then plateau Piecewise or spline model
Known clinical transition point Piecewise model
Unknown smooth shape Restricted cubic spline
Strong biological mechanism Mechanistic non-linear model
Primary estimand at Week 12 Visit-specific contrast

Common Mistakes

  1. Assuming every longitudinal trajectory is linear. Many clinical outcomes have rapid early changes followed by stabilization.
  2. Adding polynomial terms without examining the data. A quadratic term should have a scientific or empirical rationale.
  3. Using a high-degree polynomial to fit every fluctuation. This can produce unstable and poorly interpretable trajectories.
  4. Confusing random slopes with non-linear trajectories. Random slopes allow subjects to have different linear rates; they do not create curvature.
  5. Interpreting spline coefficients directly. Spline basis coefficients are usually not clinically intuitive.
  6. Choosing knots solely because they improve a p-value. Knot selection should be scientifically and statistically defensible.
  7. Ignoring treatment-by-time interaction. If treatment effects evolve differently over time, a common trajectory may be inadequate.
  8. Focusing only on the time-term p-value. The clinical question is often better answered using estimated treatment differences at relevant times.
  9. Confusing mean trajectory with covariance structure. These are separate components of a longitudinal model.
  10. Using actual time automatically. Actual elapsed time is not always the appropriate estimand when the analysis is explicitly visit based.
  11. Assuming a flexible model solves missing-data problems. The missing-data mechanism still requires consideration.
  12. Overfitting the trajectory. More flexibility does not necessarily produce a better clinical model.

A Detailed Example: Linear vs. Quadratic vs. Spline

Suppose a randomized clinical trial measures change from baseline through Week 24. The investigator fits three models.

Model AIC Trajectory Description
Linear 2,410 Constant slope
Quadratic 2,350 Early change followed by flattening
Restricted cubic spline 2,342 Flexible smooth curve

The spline has the smallest AIC, but that does not automatically mean it should be selected.

The quadratic model may be preferable if:

  • Its fitted trajectory is nearly identical to the spline.
  • The quadratic shape is clinically plausible.
  • The parameters are easier to communicate.
  • The prespecified analysis plan favors a parsimonious model.

Conversely, the spline may be preferable if the quadratic model systematically misses clinically important changes in slope.

Model selection principle: Statistical fit is one consideration. The final model should also be scientifically credible, interpretable, stable, and aligned with the prespecified estimand.

Comparing Trajectories at Specific Times

For a flexible trajectory model, investigators often want estimates at a set of clinically important times. For example:

\[ t\in\{4,8,12,24\} \]

At each time, estimate:

\[ \Delta(t) = E[Y(t)\mid T=1] - E[Y(t)\mid T=0] \]

and its confidence interval.

This transforms a complicated trajectory model into clinically interpretable results.

Plotting the Estimated Trajectory

A publication-quality longitudinal analysis should usually include a plot of the estimated trajectories.

A useful figure can show:

  • Observed group means
  • Model-based predicted means
  • 95% confidence intervals
  • Time on the horizontal axis
  • Outcome or change from baseline on the vertical axis

The figure often communicates the non-linear pattern more effectively than a table of regression coefficients.

Trajectory Modeling and the Estimand

Before selecting a model, define what quantity the study is trying to estimate. Possible estimands include:

  • Treatment difference at Week 12
  • Treatment difference at Week 24
  • Average treatment difference across follow-up
  • Difference in slopes
  • Difference in trajectory shape
  • Time to maximum treatment response
  • Area under the outcome trajectory

Different estimands can lead to different preferred models.

Most important question: Do not start with "Which non-linear model should I use?" Start with "What longitudinal quantity am I trying to estimate?"

When Categorical Time Is the Better Choice

Categorical time is often underestimated because it is statistically simple.

Suppose the trial's primary objective is the treatment difference at Week 12. If measurements occur at six scheduled visits, categorical visit can provide direct estimates at each visit without imposing an artificial curve.

This is particularly useful in confirmatory clinical trials where scheduled visits and prespecified contrasts are central to the analysis.

When a Continuous Non-Linear Time Model Is Better

Continuous non-linear time is especially useful when:

  • The actual timing of observations varies.
  • The trajectory itself is scientifically important.
  • The study contains many observation times.
  • A smooth response curve is desired.
  • There is interest in estimating changes between scheduled visits.
  • A biologically meaningful functional form exists.

Non-Linear Time and Random Slopes

Suppose the population trajectory is quadratic. It may still be reasonable to allow participants to have different linear rates of change:

\[ Y_{ij} = \beta_0+\beta_1t_{ij}+\beta_2t_{ij}^2 +b_{0i}+b_{1i}t_{ij} +\varepsilon_{ij} \]

This model says:

  • The population trajectory is curved.
  • Participants vary in baseline level.
  • Participants vary in their linear rate of change.
  • The curvature is shared through the fixed-effect structure.

That can be a sensible compromise when there are insufficient data to support subject-specific curvature.

Should You Add a Random Quadratic Effect?

In principle, a model could include:

\[ b_{2i}t^2 \]

so that each participant has an individual quadratic component.

But this substantially increases model complexity.

The data must support estimation of:

  • Random intercept variance
  • Random slope variance
  • Random quadratic variance
  • Covariance between these random effects

With limited numbers of observations per participant, this can lead to singular fits or unstable covariance estimates.

Practical principle: Do not add random curvature merely because the fixed-effects trajectory is curved. Subject-specific non-linear random effects require enough repeated measurements and sufficient information to estimate them reliably.

Model Convergence Matters

Flexible longitudinal models can encounter computational problems. Common warnings include:

  • Non-convergence
  • Singular covariance matrices
  • Boundary estimates
  • Very large standard errors
  • Highly correlated parameters

These are not merely technical annoyances. They can indicate that the proposed model is too complex for the available data.

A simpler, stable model is often preferable to a theoretically richer model that cannot be estimated reliably.

Centering and Scaling for Polynomial Models

Suppose time ranges from 0 to 365 days. Using:

\[ t^2 \]

produces values as large as:

\[ 365^2=133225 \]

Centering and scaling can improve numerical behavior. For example:

\[ t_c=\frac{t-180}{30} \]

now expresses time approximately in months relative to Day 180.

The exact transformation should be chosen so that coefficients and predictions remain interpretable.

Reporting a Non-Linear Longitudinal Analysis

A statistical report should explain:

  • Why a non-linear trajectory was considered
  • How time was parameterized
  • Whether time was centered or scaled
  • How knots were selected if splines were used
  • Whether treatment-by-time interactions were included
  • The random-effects specification
  • The residual covariance structure
  • The method used for estimation
  • How missing observations were handled
  • Which time points were used for treatment contrasts

Example Statistical Methods Language

A concise methods description might state:

Example: The longitudinal outcome was analyzed using a linear mixed-effects model with fixed effects for treatment, time, and treatment-by-time interaction and subject-specific random intercepts and slopes. Because exploratory graphical assessment indicated a non-linear trajectory, time was modeled using a prespecified quadratic function centered at Week 12. Treatment differences were estimated at Weeks 4, 8, 12, and 24 with corresponding 95% confidence intervals.

For a spline model, the corresponding description would specify the spline type and knot locations.

What to Include in a Statistical Analysis Plan

For an important longitudinal analysis, the SAP should specify:

  • Outcome definition
  • Baseline definition
  • Scheduled visits
  • Time scale
  • Primary estimand
  • Fixed effects
  • Time parameterization
  • Treatment-by-time interaction
  • Random effects
  • Covariance structure
  • Estimation method
  • Degrees-of-freedom method where applicable
  • Missing-data assumptions
  • Planned contrasts
  • Confidence interval method
  • Graphical displays
  • Sensitivity analyses

Sensitivity Analyses

When the trajectory is uncertain, sensitivity analyses can compare reasonable alternative specifications. For example:

  • Categorical visit
  • Linear time
  • Quadratic time
  • Piecewise linear time
  • Restricted cubic spline

The goal is not to select whichever model gives the most favorable treatment result.

Instead, the purpose is to assess whether the substantive conclusion is robust to plausible trajectory assumptions.

Avoiding Data-Driven Model Shopping

Suppose an analyst tries:

  • Linear time
  • Quadratic time
  • Cubic time
  • Four-knot spline
  • Five-knot spline
  • Piecewise model with three knots

and then selects the model with the smallest p-value for treatment.

This can introduce substantial bias.

Model flexibility should be justified independently of the observed treatment result whenever possible.

Best practice: Use clinical knowledge, design-stage considerations, exploratory data visualization, and prespecified modeling rules to determine the trajectory specification.

Non-Linear Trajectories in Regulatory Clinical Trials

In a regulatory clinical-trial setting, the model should be chosen to support a clearly defined estimand.

A highly flexible trajectory can be useful for understanding the longitudinal profile, but the primary efficacy conclusion may still be based on a prespecified visit-specific contrast.

This is an important distinction:

\[ \text{trajectory model} \neq \text{primary estimand} \]

The trajectory model is a statistical tool used to estimate the desired clinical quantity.

A Complete Decision Framework

Question Recommended Consideration
Are there only a few scheduled visits? Consider categorical visit
Is the trajectory approximately straight? Linear time may be sufficient
Is there simple curvature? Consider quadratic time
Is there a meaningful change point? Consider piecewise linear time
Is the trajectory smooth but unknown? Consider restricted cubic splines
Is there a biological mechanism? Consider a mechanistic non-linear model
Do treatment effects change over time? Include treatment-by-time terms
Do subjects differ in rate of change? Consider random slopes
Are residual correlations substantial? Evaluate covariance structure separately
Is the model unstable? Reduce complexity

The Most Important Distinction: Shape vs. Heterogeneity

Longitudinal modeling involves at least two distinct sources of complexity.

The first is trajectory shape:

\[ f(t) \]

which determines whether the average response is linear, curved, piecewise, smooth, or otherwise non-linear.

The second is between-subject heterogeneity:

\[ b_i \]

which describes how participants differ from one another.

A strong longitudinal model addresses both without confusing them.

A Practical Example of the Distinction

Imagine two patients:

Week Patient A Patient B
0 50 65
4 43 57
8 39 51
12 38 49
24 37 48

Both patients show a curved trajectory. They also differ substantially in baseline level.

A useful model may therefore need:

  • A non-linear fixed time effect to describe curvature
  • A random intercept to describe baseline heterogeneity
  • Possibly a random slope to describe differences in rate of change

These are complementary rather than competing ideas.

Recommended Default Strategy

There is no universal best model, but a practical strategy for many longitudinal clinical analyses is:

1
Start by defining the estimand and clinically relevant time points.
2
Plot observed trajectories before choosing a functional form.
3
Use categorical visit when visit-specific inference is primary and there are relatively few visits.
4
Use a quadratic or piecewise model when the trajectory has a simple interpretable shape.
5
Use splines when smooth flexibility is needed and the shape is not known in advance.
6
Add treatment-by-time interactions only when changing treatment effects are scientifically relevant.
7
Specify random effects and covariance structure independently of the mean trajectory.
8
Check convergence, residuals, fitted trajectories, and sensitivity to reasonable alternatives.
9
Report predicted treatment differences at clinically meaningful times.

Summary Comparison

Method Flexibility Interpretability Best Use
Linear Low High Approximately constant rate of change
Quadratic Moderate Moderate Simple curvature
Piecewise linear Moderate High Known change points
Categorical visit High High at specific visits Visit-specific clinical inference
Restricted cubic spline High Moderate Unknown smooth trajectory
Mechanistic non-linear Variable Potentially very high Strong biological model

Key Takeaways

Non-linear longitudinal trajectories are common in clinical research. A linear time effect is convenient, but it should not be used automatically when the underlying trajectory clearly changes slope.

Several approaches are available:

  • Categorical time avoids imposing a functional form.
  • Quadratic models provide a simple representation of curvature.
  • Piecewise models are useful when slope changes occur at meaningful time points.
  • Splines provide flexible smooth trajectories.
  • Mechanistic models are appropriate when biological knowledge supports a specific functional form.

These approaches can all be embedded within a mixed-effects framework.

The most important conceptual distinction is that non-linear time effects describe trajectory shape, while random effects describe between-subject heterogeneity.

Bottom line: When longitudinal clinical data do not follow a straight-line trajectory, do not simply force a linear model to summarize the entire follow-up period. First define the estimand and inspect the observed trajectory. Then select a time specification—categorical, polynomial, piecewise, spline, or mechanistic—that is scientifically defensible and sufficiently flexible for the data. In mixed-effects models, non-linear fixed time effects can be combined with random intercepts, random slopes, and appropriate covariance structures. For interpretation, focus on predicted trajectories and treatment differences at clinically meaningful times rather than on the individual coefficients of a complicated non-linear basis.

References

Fitzmaurice, G.M., Laird, N.M. & Ware, J.H. (2011). Applied Longitudinal Analysis, 2nd ed. Wiley.
Verbeke, G. & Molenberghs, G. (2000). Linear Mixed Models for Longitudinal Data. Springer.
Pinheiro, J.C. & Bates, D.M. (2000). Mixed-Effects Models in S and S-PLUS. Springer.
Harrell, F.E. (2015). Regression Modeling Strategies, 2nd ed. Springer.
Ruppert, D., Wand, M.P. & Carroll, R.J. (2003). Semiparametric Regression. Cambridge University Press.
Diggle, P., Heagerty, P., Liang, K.-Y. & Zeger, S. (2002). Analysis of Longitudinal Data, 2nd ed. Oxford University Press.
Little, R.J.A., et al. (2012). The prevention and treatment of missing data in clinical trials. New England Journal of Medicine, 367, 1355–1360.