Tutorials › Pharmacometric Workflows and Reproducible Modeling › Time-Varying Covariates in Software Implementations

Software Landscape and Interoperability · Tutorial 210 of 399

Time-Varying Covariates in Software Implementations

You will learn to encode a time-varying renal function covariate consistently across four modeling tools and verify what the software assumes between covariate observations.

Intermediate 11 min read

What You'll Learn

  • Distinguish a covariate updated at data records from one interpolated between measurements.
  • Calculate renal-function effects under last-observation-carried-forward and linear-interpolation assumptions.
  • Translate the same covariate relationship into NONMEM, Monolix, nlmixr2, and mrgsolve workflows.
  • Explain why interpolating renal function before applying a nonlinear effect can differ from interpolating the resulting clearance.
  • Check record alignment, interpolation settings, units, and boundary behavior.
  • Design a cross-software test that isolates covariate handling from other model differences.

Why Covariate Timing Is Part of the Model

A renal-function covariate is not fully specified by its name and effect equation. If estimated or measured renal function changes during follow-up, the implementation must also say when the model uses each value and what value applies between measurements. Two tools can contain the same clearance equation and the same covariate data yet produce different predictions because one holds values constant between records while another interpolates them.

The distinction matters whenever the covariate affects a parameter used to predict concentrations. A change in renal function can alter clearance; clearance in turn affects the rate at which drug is removed. A time-varying input therefore changes the model's predictions over time, not just a static subject characteristic. The earlier material on covariate effects and ODE translation provides the general parameter and state-variable context; here the focus is on how time-indexed covariate values are represented in software.

Definition: A time-varying covariate is an individual-level covariate whose value can change over time. A record-based update assigns the covariate value at specified data or event records and holds that value until a later update, unless the model explicitly specifies another rule. Interpolation defines intermediate covariate values between observations, for example by joining adjacent values with straight lines.

Neither rule is automatically correct for every renal-function variable. A record-based step function can be suitable when a value is treated as unchanged until a new measurement becomes available. Linear interpolation can be a defensible approximation when the underlying quantity is assumed to change gradually. The choice is a modeling assumption, not a cosmetic software option. It should reflect the measurement process and be applied consistently to all individuals.

Define the Time Rule Before Writing Tool Syntax

Let \(R(t)\) denote renal function at time \(t\), measured in mL/min, and let clearance be related to it by a power model. For illustration, suppose typical clearance at \(R_{\mathrm{ref}}=90\ \mathrm{mL/min}\) is \(5.00\ \mathrm{L/h}\), and the renal-function exponent is \(0.75\). The structural relationship is

$$ CL(t)=5.00\left(\frac{R(t)}{90}\right)^{0.75}\ \mathrm{L/h}. $$

The ratio is dimensionless because both renal-function values use mL/min. This example treats the coefficient and exponent as fixed solely to isolate the timing question; it does not imply that these are clinically established values. In a population model, the equation could include between-individual effects and estimated parameters, but the time-handling issue remains.

Suppose \(R(0)=90\ \mathrm{mL/min}\) and \(R(12)=60\ \mathrm{mL/min}\). Under last observation carried forward (LOCF), \(R(t)=90\) for \(0\leq t<12\), then the value changes to 60 at 12. Under linear interpolation,

$$ R(t)=90+\frac{t}{12}(60-90),\qquad 0\leq t\leq12. $$

The expression only defines the interval between the two observations. A separate rule is needed before the first covariate record and after the last one; silently extending a rule beyond observed times can amount to an unexamined extrapolation assumption.

Worked Example: Compare Step Updates With Linear Interpolation

Use the hypothetical values above to calculate clearance at 6 hours under both rules. Assume the first value is available at time 0, the second at time 12, and no other updates occur.

Record-based LOCF. At 6 hours, the next update has not occurred, so \(R(6)=90\ \mathrm{mL/min}\). Therefore,

$$ CL(6)=5.00\left(\frac{90}{90}\right)^{0.75} =5.00\ \mathrm{L/h}. $$

Linear interpolation of renal function. The midpoint renal function is \(R(6)=90+(6/12)(60-90)=75\ \mathrm{mL/min}\). Substitution gives

$$ CL(6)=5.00\left(\frac{75}{90}\right)^{0.75} =5.00(0.8333\ldots)^{0.75} \approx 4.361\ \mathrm{L/h}. $$

The clearances differ by \(5.00-4.36097\ldots\approx0.639\ \mathrm{L/h}\) at 6 hours. That is a consequence of the different covariate-time rules, not a numerical estimation discrepancy. Both calculations use the same clearance equation and endpoint measurements.

Nonlinear Effects Make the Interpolation Target Matter

A second choice is whether to interpolate the measured covariate and then apply its effect, or to calculate the parameter at observed covariate times and interpolate that parameter. These approaches are generally unequal for a nonlinear effect, though equality can also occur for particular endpoints or interpolation weights.

For linear interpolation of \(R\), define \(w=t/12\). The model first forms \(R(t)=(1-w)R(0)+wR(12)\), then evaluates \(g(R(t))\), where \(g(R)=5.00(R/90)^{0.75}\). Interpolating the endpoint clearances instead gives \((1-w)g(R(0))+wg(R(12))\). These expressions need not match because applying a nonlinear function and taking a weighted average are different operations.

At 12 hours, the clearance calculated from the second renal-function value is approximately \(5.00(60/90)^{0.75}=3.689\ \mathrm{L/h}\). Linear interpolation of clearance at the midpoint, using unrounded endpoint values, gives

$$ \frac{5.00+5.00(60/90)^{0.75}}{2} \approx 4.344\ \mathrm{L/h}. $$

This differs from \(4.361\ \mathrm{L/h}\), the clearance obtained by interpolating renal function to \(75\ \mathrm{mL/min}\) and then applying the power model. A modeler should therefore identify what is being interpolated, not just select a setting called “linear.”

Worked Example: Interpolate the Covariate, Not the Parameter

At 6 hours, compare the two approaches using the same hypothetical endpoints. For interpolation of renal function, the value is 75 mL/min, so the clearance is \(5.00(75/90)^{0.75}\approx4.361\ \mathrm{L/h}\).

For interpolation of clearance, first calculate the endpoint at 12 hours without rounding: \(5.00(60/90)^{0.75}\approx3.68894\ \mathrm{L/h}\). The midpoint is then

$$ \frac{5.00+3.68894}{2} \approx 4.34447\ \mathrm{L/h} \approx 4.344\ \mathrm{L/h}. $$

The results differ by about \(0.0165\ \mathrm{L/h}\). Interpolating renal function is appropriate if the intended assumption is a linear trajectory for renal function followed by the specified power relationship. Interpolating clearance encodes a different trajectory for the parameter itself. It should not be substituted without stating that changed assumption.

Represent the Same Rule in Four Tools

Across tools, separate three tasks: prepare time-stamped covariate values, declare or make those values available to the model, and specify the rule between records. In every case, inspect the data actually passed to the engine. A covariate entered only on laboratory-measurement rows may not be available at other event records in the way intended; preprocessing may need to carry values to relevant records or the tool must be configured to use the time-varying series.

ToolWhere the covariate entersKey timing check
NONMEMInput data column referenced in model code, commonly in $PK or a model derivative blockEnsure update records and parameter reevaluation match the chosen step or time-dependent rule
MonolixCovariate column declared and configured as time-varying, then referenced in the structural modelVerify the covariate type and interpolation behavior selected for the analysis
nlmixr2Covariate data column referenced in the model expressionSet and document the covariate interpolation behavior supported by the estimation workflow
mrgsolveCovariate included in the event data and referenced in model codeConfirm when event records update the value and whether any separate interpolation is implemented

NONMEM. Include renal function as an input variable and reference it in the parameter calculation, for example in a clearance expression corresponding to \(CL=TVCL(R/90)^{\theta_R}\). For a record-based implementation, supply the intended renal-function value on records at which it must be available, and ensure that the model recomputes the relevant parameter at the update. Do not assume that two measurements create a continuous line between them: the data records alone do not state that assumption. If continuous interpolation is intended, make the time-dependent rule explicit and verify how it is evaluated by the selected model structure and estimation setup.

Monolix. Make the renal-function column available as a covariate, classify it as time-varying, and use it in the structural parameter relationship. Then inspect the covariate configuration and its interpolation setting. A continuous covariate may be treated differently from a categorical one, and the setting determines what value the model uses between observed times. The equation may look identical to the NONMEM equation, but that alone does not establish equivalent timing behavior.

nlmixr2. Put renal function in the longitudinal data and refer to its column name in the model expression for clearance. The fitting workflow must also use a defined covariate interpolation behavior; the available control and defaults can depend on the estimation interface and software version. For reproducibility, record the selected behavior explicitly rather than relying on a default. Check that covariate times are correctly ordered within each individual and that values are available across the records needed for the likelihood calculation.

mrgsolve. Provide the time-varying covariate in the event data and use the corresponding data variable when calculating clearance in the model. For a step update, include a record at each time when the value changes, with the new value assigned from that point forward according to the event-data semantics. Do not treat data records as a continuous trajectory unless interpolation is explicitly coded or otherwise configured. When a simulation requires continuously changing renal function, implement that trajectory deliberately and verify it at interior times.

Worked Example: Build a Record-Based Dataset

Suppose a hypothetical subject receives a dose at time 0, has a concentration observation at time 6, and a renal-function measurement at time 12. The intended rule is LOCF from the baseline renal-function value of 90 mL/min until the time-12 update to 60 mL/min. The important modeling timeline is therefore: 90 mL/min applies at time 0 and through the interval before time 12; 60 mL/min applies from the time-12 update onward.

A robust input preparation would make the intended value available on the records used by the software. For example, the dose and time-6 observation records can carry 90, while the time-12 covariate update record carries 60. If the concentration at time 6 is represented by a record without a renal-function value, the model may encounter a missing value or a tool-specific behavior instead of the intended carry-forward value. This is why carrying values into records or using a documented covariate-series mechanism is part of model implementation.

In NONMEM the covariate column is referenced in the parameter calculation; in Monolix it is declared as a time-varying covariate with the selected step behavior; in nlmixr2 the longitudinal covariate and explicit interpolation configuration must agree with LOCF; and in mrgsolve the event data must produce the intended update schedule. The numerical check is simple: clearance at time 6 should be 5.00 L/h under these assumptions. If a tool instead gives approximately 4.361 L/h, it is behaving as if renal function were interpolated linearly between 0 and 12 hours.

Verification, Failure Modes, and Limitations

A reliable translation tests the covariate behavior independently of parameter estimation. Use a small hypothetical dataset with known values and evaluate the covariate and derived clearance at three times: just before an update, exactly at the update, and between two measurements. At time 6 in the example, LOCF predicts 5.00 L/h, whereas linear interpolation of renal function predicts about 4.361 L/h. These checks reveal whether an update is delayed, applied at the wrong record, or interpolated unexpectedly.

Also check the following before comparing model predictions across software:

  • Units and scale. Renal function in the data and the reference value in the equation must use the same units. A value in a different unit system changes the ratio unless converted.
  • Record alignment. Confirm that every relevant observation and event sees the intended covariate value, especially when measurements and dosing records occur at different times.
  • Update timing. Establish whether the new value applies at the record time itself or only after it, and check duplicate records at the same time.
  • Boundaries. Decide what the model uses before the first covariate measurement and after the last. Avoid unintentional extrapolation.
  • Transformation order. Determine whether interpolation applies to renal function or to a derived parameter such as clearance.
  • Version and defaults. Record software versions and explicit settings; a default is not a portable model specification.

A useful cross-tool diagnostic is to hold all parameters and random effects fixed and compare the implied clearance trajectory before comparing concentrations. If clearances disagree, the source may be covariate timing, data handling, or the transformation order; investigating those first is more informative than changing estimation settings. Once the clearance trajectories match, concentration predictions can be compared under the same doses, events, and ODE model.

Record-based updates are transparent and often align naturally with measured covariate histories, but they imply abrupt changes and may be a poor representation of a continuously evolving quantity. Interpolation gives intermediate values but assumes a trajectory that was not directly observed; linear interpolation can be particularly questionable across long gaps or abrupt clinical changes. A static baseline covariate is simpler, but it discards within-subject changes. The suitable choice depends on the scientific question and measurement schedule, and sensitivity analysis can show whether conclusions depend on it.

Common pitfall: “The data contain renal-function measurements at times 0 and 12, so the model must use a straight line between them.” This is not generally true. Measurements specify observed values, not the between-measurement rule. State whether the model uses a step function, interpolation of renal function, or interpolation of a derived parameter, and verify that behavior at an interior time.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. Under LOCF, what renal-function value is used at 6 hours if the measurements are 90 mL/min at time 0 and 60 mL/min at time 12?
  2. Under linear interpolation of renal function, calculate renal function at 4 hours for those same measurements.
  3. Why can interpolating renal function and then calculating clearance differ from interpolating clearance directly?
  4. Name two implementation checks that help establish equivalent time-varying covariate behavior across tools.

Solutions. (1) LOCF uses 90 mL/min before the time-12 update, so clearance under the example equation is 5.00 L/h at 6 hours. (2) \(R(4)=90+(4/12)(60-90)=80\ \mathrm{mL/min}\). (3) The clearance equation is nonlinear in renal function, so applying the power transformation to an interpolated covariate generally does not equal interpolating the transformed endpoint clearances. (4) For example, check the covariate and clearance just before, at, and between update times; verify that the same units, update timing, interpolation target, and boundary rules are used.

Clinical Biostats