Tutorials › Multiple Imputation by Chained Equations (MICE) › Modeling Time In Longitudinal Imputation

Nested and Multilevel Data · Tutorial 371 of 497

Modeling Time In Longitudinal Imputation

Compare time specifications for repeated outcomes and see how their assumptions affect conditional predictions and stochastic imputations.

Advanced 12 min read

What You'll Learn

  • State a longitudinal conditional imputation model with a chosen representation of time.
  • Interpret linear time effects and the restrictions they impose on visit means.
  • Use categorical visit indicators when changes need not follow a straight line.
  • Construct a piecewise-linear basis and calculate predictions from it.
  • Compare conditional predictions while separating mean structure from random imputation variation.
  • Diagnose time specifications using observed and imputed patterns across visits.

Why the Representation of Time Matters

A longitudinal imputation model must describe how an outcome can change across occasions. If time is entered only as a linear term, the model expects the mean outcome to follow a straight line. That may be a useful approximation, but it rules out plateaus, abrupt changes between visits, and curved trends. Treating each scheduled visit as a separate category allows a different mean at every visit, but it uses more parameters and does not naturally describe time points between visits. Flexible basis terms offer a middle ground: they allow selected departures from linearity while still representing time through a relatively small set of model terms.

These choices affect the conditional distributions used to fill missing repeated outcomes. They can therefore affect both the shape of completed trajectories and later estimates. The goal is not to choose the most flexible model automatically. It is to represent the time pattern plausibly, with enough information in the observed data to estimate that pattern.

Definition: In long-format data, let \(Y_{ij}\) be the outcome for subject \(i\) at occasion \(j\), and let \(t_{ij}\) be the time of that occasion. A time specification is the set of terms used to represent \(t_{ij}\) in the conditional model for \(Y_{ij}\). Common choices are a linear term, indicators for scheduled occasions, and a set of flexible basis functions.

For a continuous outcome, one possible conditional model is a random-intercept model:

$$ Y_{ij}=\beta_0+f(t_{ij})+\boldsymbol{\beta}^{\mathsf T}\mathbf{Z}_{ij}+u_i+\varepsilon_{ij}. $$

Here, \(f(t)\) is the chosen time function, \(\mathbf{Z}_{ij}\) denotes other predictors in the imputation model, \(u_i\) is a subject-specific intercept, and \(\varepsilon_{ij}\) is the occasion-level residual. A standard version assumes \(u_i\sim N(0,\sigma_u^2)\), \(\varepsilon_{ij}\sim N(0,\sigma^2)\), and independence of these terms across subjects and from one another, conditional on the model predictors. The outcome model should also be compatible with the outcome’s scale; a Gaussian model is not appropriate merely because time is measured numerically.

For a valid imputation model, the conditional mean and distribution should be plausible given the observed data and included predictors. Under a missing-at-random assumption, missingness may depend on observed outcomes and covariates included in the imputation model, but not on the missing outcome after conditioning on them. There must also be enough observed information across the relevant times and covariate patterns to estimate the model. These conditions do not guarantee that a particular time function is correct; that needs substantive judgment and diagnostics. In MICE, the conditional model is fitted within the chained-equation procedure, with parameter uncertainty represented by the proper-imputation procedure.

Three Ways to Represent Time

With linear time, \(f(t)=\beta_1t\), so the expected outcome changes by \(\beta_1\) outcome units per unit of time, holding other terms fixed. This is parsimonious and can be reasonable over a short interval. It imposes a constant rate of change: the expected difference between any two occasions is proportional to the elapsed time.

With categorical time, use an indicator for each occasion other than a reference occasion. If there are \(J\) scheduled occasions, the model estimates \(J\) occasion-specific means, subject to the other model terms. This avoids requiring equally spaced visits or a linear trend. It can be costly when there are many occasions, and it does not directly supply a smooth prediction at an unscheduled time.

A flexible basis replaces the single time term with several functions of time. One simple example is a piecewise-linear hinge basis with a knot at \(k\):

$$ f(t)=\beta_1t+\beta_2(t-k)_+,\qquad (t-k)_+=\max(0,t-k). $$

Before the knot, the slope is \(\beta_1\); after the knot, it is \(\beta_1+\beta_2\). The hinge term is zero before the knot and increases linearly after it, so the fitted mean remains continuous at \(k\). Other bases, including spline bases, can represent smoother curvature. Their number and placement of basis terms should be supported by the amount and spread of observed data; more terms do not automatically improve imputations.

Worked Example: A Linear Time Term

Suppose a hypothetical symptom score is measured in points at weeks 0, 1, 2, and 3. For illustration, a fitted conditional model has a population intercept of 10.2 points, a linear time coefficient of \(-0.80\) points per week, a subject intercept contribution of \(1.1\) points, and a contribution of \(0.50\) points from the subject’s other observed predictors. Consider that subject’s missing score at week 3.

The model’s conditional mean is

$$ 10.2+(-0.80)(3)+1.1+0.50=9.40\text{ points}. $$

The time term contributes a decrease of \(0.80\times3=2.40\) points from week 0 to week 3. If the residual standard deviation is hypothetically 1.5 points and a particular stochastic draw is \(0.40\) standard deviations above the conditional mean, the imputed value for this draw is

$$ 9.40+(0.40)(1.5)=10.0\text{ points}. $$

The value 9.40 is the conditional mean, not the imputation itself. A proper imputation also reflects residual and parameter uncertainty. The example assumes the linear mean is adequate over these weeks, the Gaussian residual model is plausible, and the subject contribution is available or appropriately drawn. Those assumptions would need assessment in a real analysis.

Worked Example: Categorical Occasion Effects

Now suppose a hypothetical study schedules visits at weeks 0, 1, 2, and 3. A model using week 0 as the reference has fitted occasion effects of 1.0, 2.6, and 2.1 points at weeks 1, 2, and 3. For the subject in question, other predictors and the subject intercept together contribute 0.60 points. Calculate the week-3 conditional mean and compare it with a linear specification whose fitted increase is 0.80 points per week, with the same reference mean and subject contribution.

Under the categorical model, the week-3 effect is entered directly:

$$ 8.1+2.1+0.60=10.8\text{ points}. $$

Under the stated linear model, the week-3 effect is \(0.80\times3=2.40\) points, giving

$$ 8.1+2.40+0.60=11.1\text{ points}. $$

The difference between these conditional means is \(11.1-10.8=0.30\) points. The categorical model can represent the rise to week 2 followed by a smaller mean at week 3; the linear model cannot reproduce that pattern with a constant slope. These are hypothetical fitted values used to illustrate the calculation, not a claim that either model would be preferred without examining the data. Separate stochastic draws could differ by more than 0.30 points because they also include uncertainty.

Worked Example: A Piecewise-Linear Basis

For another hypothetical outcome, suppose time is measured in weeks and a hinge is placed at week 2. The fitted fixed time component is \(f(t)=0.50t+1.20(t-2)_+\). A subject’s other terms contribute 0.70 points, and the intercept is 8.0 points. Calculate the conditional means at weeks 1 and 3.

At week 1, the hinge is \((1-2)_+=0\), so

$$ 8.0+0.50(1)+1.20(0)+0.70=9.20\text{ points}. $$

At week 3, the hinge is \((3-2)_+=1\), giving

$$ 8.0+0.50(3)+1.20(1)+0.70=11.4\text{ points}. $$

The time slope is 0.50 points per week up to week 2 and \(0.50+1.20=1.70\) points per week after week 2. Both calculations use the same other terms, so the difference in fitted means comes from the specified time function. The knot should have a defensible location and enough data on both sides; a hinge chosen where there are few observations can produce an unstable change in slope.

Why the Models Differ

The restrictions can be seen by writing a separate mean for each scheduled visit. Let \(\mu_j\) be the conditional mean at visit \(j\), after fixing other predictors and the subject intercept. A categorical-time model estimates each \(\mu_j\) separately. A linear-time model instead requires

$$ \mu_j=\beta_0+\beta_1t_j. $$

Thus, the visit means must lie on a straight line when plotted against time. In equally spaced visits, this requires successive mean differences to be equal. For example, if the visit means are 8.1, 9.1, 10.7, and 10.2 points at weeks 0 through 3, their successive changes are 1.0, 1.6, and \(-0.5\) points. They cannot all be generated by one linear slope. A categorical model can represent those means directly, while a flexible basis can approximate their shape with fewer parameters than a fully categorical model.

This is a difference in model assumptions, not merely a difference in how the same model is written. If a linear specification is wrong, imputations may pull missing values toward an inappropriate straight-line trend. If the categorical specification is too large for the available data, visit effects may be imprecise. Flexible bases balance these risks, but the selected basis still imposes structure.

Choosing and Checking a Time Specification

Begin with the design and the intended analysis. If visits are a small set of fixed occasions and no simple trend is credible, categorical time is often a transparent choice. If the scientific question supports a roughly constant change per time unit, a linear term may be adequate. If a curve or change in slope is plausible, a small flexible basis may be warranted. A continuous time term is especially useful when occasion spacing is unequal, since it uses elapsed time rather than treating each occasion as an interchangeable category.

Check the specification using the observed data available for the outcome and relevant predictors. Useful diagnostics include:

  • Plot observed outcome summaries against time, alongside fitted conditional means. Look for systematic curvature or visit-specific departures that the chosen model misses.
  • Compare observed and imputed distributions separately by occasion, including spread and tails where the outcome scale permits.
  • Inspect trace plots and summaries across imputations. Stable chains are necessary, but they do not establish that the time function is well specified.
  • Check whether a flexible model is supported at every part of the time range. Very sparse visits or a knot near the edge can make fitted values unstable.

Do not diagnose the model by expecting each completed trajectory to be smooth. Residual variation means individual values need not lie on the fitted mean curve. The relevant question is whether the distribution of imputations, conditional on predictors and time, is plausible. Also examine whether the time coding used for imputation agrees with the coding needed for the intended analysis.

1
Specify the time scale.
Record whether time is visit number, elapsed time, or another meaningful scale; center or rescale it when that improves interpretation or numerical stability.
2
Choose a mean structure.
Use a linear term, occasion indicators, or a limited flexible basis based on the design, scientific context, and available observations.
3
Fit and assess the conditional model.
Check the fitted pattern and residual behavior across occasions, and assess whether the model has enough observed information to estimate its terms.
4
Compare completed-data patterns.
Review imputed distributions by time and across imputations, and consider whether conclusions are sensitive to reasonable alternative time specifications.

Alternatives, Limitations, and a Common Pitfall

The main alternatives differ in how much structure they impose. A linear term is compact and easy to interpret but may be too restrictive. Categorical occasion effects allow arbitrary means at scheduled visits but can be inefficient with many occasions and do not encode a smooth relationship across times. A basis expansion can capture curvature with fewer terms than a large set of visit indicators, but its shape depends on the basis and knot choices. Comparing these specifications can reveal sensitivity; it does not identify the true model automatically.

No time specification repairs a lack of relevant observed information. If nearly all outcomes are missing at a late visit, the imputation there depends heavily on model assumptions and other predictors. A flexible curve can behave poorly when extrapolated beyond the range or into sparse regions of observed time. Time terms also do not, by themselves, ensure that all important predictors are included or that the repeated-measures dependence is correctly represented. The specific covariance and trajectory structures beyond a random intercept are separate modeling issues.

Common mistake: “The visits are numbered 1, 2, 3, and 4, so a linear time term is automatically appropriate.” This confuses a convenient numeric coding with a justified shape assumption. A linear term says that each one-unit increase in the coded time has the same expected effect, which may be implausible if visits are unequally spaced or the mean changes nonlinearly. Check the actual time scale and the observed pattern; consider categorical or flexible terms when a straight line is not credible.

Key takeaway: Time coding determines which longitudinal mean patterns an imputation model can represent. Select a form that is plausible and estimable, then assess its fitted and imputed patterns by occasion rather than assuming that a more complex model is always better.

Check Your Understanding

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

  1. A model has a time coefficient of 0.6 outcome units per month. What does it imply about the expected difference between months 2 and 5, holding other model terms fixed?
  2. Why can a categorical-time model represent a rise followed by a decline across four scheduled visits when a linear-time model cannot?
  3. For \(f(t)=0.4t+0.9(t-3)_+\), calculate the time component at \(t=2\) and \(t=5\). What are the slopes before and after week 3?
  4. Name two diagnostics for assessing whether the chosen time representation is plausible for imputations.
  5. Why is a flexible time basis not automatically preferable to categorical time?

Solutions: (1) The model implies an expected increase of \(0.6(5-2)=1.8\) outcome units from month 2 to month 5. (2) Categorical time estimates a separate mean at each visit; a linear model requires all visit means to follow one straight line with constant change per time unit. (3) At \(t=2\), the hinge is zero, so \(f(2)=0.4(2)=0.8\). At \(t=5\), the hinge is \(5-3=2\), so \(f(5)=0.4(5)+0.9(2)=3.8\). The slopes are 0.4 before week 3 and \(0.4+0.9=1.3\) after it. (4) Examples include plotting observed summaries and fitted means against time, comparing observed and imputed distributions by occasion, and checking trace behavior across imputations. (5) A basis imposes its own shape and knot structure; categorical time may be more transparent and less dependent on those choices when the number of visits is small and well observed.

Clinical Biostats