Tutorials › Quantitative Systems Pharmacology (QSP) › Separating Parameters, Inputs, and Model State

Writing and Debugging a Model · Tutorial 73 of 799

Separating Parameters, Inputs, and Model State

Learn how to pass parameters, external inputs, and evolving states separately into an ODE right-hand side, using a drug-exposure-driven turnover model to make the distinctions testable.

Intermediate 11 min read

What You'll Learn

  • Distinguish fixed parameters, time-varying inputs, and evolving states by their roles in an ODE model.
  • Define a right-hand-side function that receives time, the state vector, parameters, and inputs separately.
  • Formulate and calculate derivatives for an exposure-driven turnover model.
  • Test whether changing an input or state affects the derivative under the relevant conditions.
  • Identify common implementation failures caused by hidden inputs, mutable parameters, or state-index confusion.
  • Compare explicit input passing with representing a dynamically evolving exposure as a model state.

Why Separate the Model’s Three Roles?

An ODE model can be written mathematically as a rule for how its state changes over time. In software, that rule is evaluated repeatedly at times and states chosen by the numerical solver. The implementation is easier to reason about when it keeps three roles distinct: parameters describe fixed model quantities, inputs provide externally specified values that may vary with time, and states are the quantities whose changes the ODE defines.

This separation is more than a matter of tidy code. If an input is accidentally held fixed, or a state is mistakenly treated as a parameter, the program may calculate a different model from the one intended. A clear interface makes it possible to inspect what affects a derivative and to test each dependency without changing the model’s other components.

Definition: In an ODE implementation, a state vector \(x(t)\) contains the evolving quantities, and the right-hand side returns their derivatives, \(dx/dt=f(t,x,\theta,u(t))\). The parameter vector \(\theta\) contains quantities treated as fixed during that integration. An input \(u(t)\) is a value supplied to the model as a function of time rather than calculated as one of its state derivatives.

The role is determined by how a quantity enters the model, not by its biological name. Drug concentration can be an externally supplied input in a pharmacodynamic model, or it can be a state in a pharmacokinetic model that calculates its own concentration trajectory. A quantity’s role should be consistent throughout the equations and the implementation.

An Exposure-Driven Turnover Model

Consider a response amount or concentration \(R(t)\) with constant production and exposure-enhanced loss. Let \(C(t)\) denote drug exposure supplied to the turnover model. One possible model is

$$ \frac{dR}{dt} = k_{\mathrm{in}} - k_{\mathrm{out}}R \left(1+E_{\max}\frac{C(t)}{EC_{50}+C(t)}\right). $$

Here, \(R(t)\) is the state. The parameters are \(k_{\mathrm{in}}\), \(k_{\mathrm{out}}\), \(E_{\max}\), and \(EC_{50}\). The time-varying input is \(C(t)\). The fraction \(C/(EC_{50}+C)\) describes a saturable exposure effect: for nonnegative exposure and positive \(EC_{50}\), it is zero at zero exposure and approaches one as exposure increases.

Assumptions for this formulation: \(R\) and \(C\) are nonnegative, \(EC_{50}>0\), \(k_{\mathrm{in}}\geq 0\), \(k_{\mathrm{out}}>0\), and \(E_{\max}\geq 0\). The production rate is constant, and the exposure-enhanced loss is proportional to the current state \(R\). Exposure is supplied externally; the turnover equation does not calculate it.

For dimensional consistency, if \(R\) has units of amount per volume and time is measured in days, then \(k_{\mathrm{in}}\) has units of amount per volume per day, while \(k_{\mathrm{out}}\) has units of inverse days. \(E_{\max}\) is dimensionless, and \(C\) and \(EC_{50}\) must have the same units. The parenthetical multiplier is dimensionless, so the loss term has the same units as production: amount per volume per day.

The corresponding software interface should make all three roles visible. In words, the right-hand-side function receives the current time, the current state vector, the fixed parameters, and the input value or input function evaluated at that time; it returns the derivative vector. For this one-state model, it computes \(f(t,R,\theta,C(t))\) and returns \(dR/dt\). It should calculate from the supplied arguments rather than silently retrieving exposure from an unrelated global variable or changing the state in place.

Worked Example: Calculate the Derivative at a Given Exposure

Suppose \(R=80\) mg/L, \(C=2\) mg/L, \(k_{\mathrm{in}}=8\) mg/L/day, \(k_{\mathrm{out}}=0.10\) per day, \(E_{\max}=1.5\), and \(EC_{50}=2\) mg/L. Find the instantaneous rate of change of \(R\).

First calculate the saturable fraction and the exposure multiplier:

$$ \frac{C}{EC_{50}+C} = \frac{2\ \mathrm{mg/L}}{2\ \mathrm{mg/L}+2\ \mathrm{mg/L}} =0.5, \qquad 1+E_{\max}\frac{C}{EC_{50}+C} =1+1.5(0.5)=1.75. $$

The loss rate is \(0.10\ \mathrm{day}^{-1}\times80\ \mathrm{mg/L}\times1.75=14\) mg/L/day. Therefore,

$$ \frac{dR}{dt} = 8\ \mathrm{mg/L/day}-14\ \mathrm{mg/L/day} = -6\ \mathrm{mg/L/day}. $$

At that instant, the model predicts that \(R\) is decreasing at 6 mg/L/day. This is an instantaneous derivative, not a claim that the response will continue to decrease at that rate over a finite interval.

Derivatives Reveal Which Role a Quantity Plays

A useful justification for the separation is to inspect how the right-hand side depends on its arguments. In the turnover model, \(R\) appears as the current state, the four fixed quantities enter as parameters, and \(C(t)\) is an input. Holding the state and parameters fixed while evaluating the function at another exposure changes only the input argument.

For this model, the change in the derivative with exposure can be expressed by a partial derivative. Differentiating the saturable fraction gives

$$ \frac{\partial}{\partial C} \left(\frac{C}{EC_{50}+C}\right) = \frac{EC_{50}}{(EC_{50}+C)^2}. $$

Thus, under the stated assumptions,

$$ \frac{\partial}{\partial C}\left(\frac{dR}{dt}\right) = -k_{\mathrm{out}}R E_{\max} \frac{EC_{50}}{(EC_{50}+C)^2}. $$

This derivative is nonpositive. It is strictly negative when \(R\ne 0\), \(E_{\max}\ne 0\), \(k_{\mathrm{out}}>0\), and \(EC_{50}>0\). Consequently, increasing exposure then decreases the derivative, because exposure increases the loss term. If \(R=0\), however, the exposure-dependent loss term is zero, so changing exposure does not change the derivative. The dependency test must account for the current state and parameters, not just the formula’s appearance.

Worked Example: Compare Two Input Values at the Same State

Use the parameters and state from the previous calculation, but compare \(C=1\) mg/L with \(C=4\) mg/L. The state and all parameters remain fixed, so only the input changes.

At \(C=1\) mg/L, the saturable fraction is \(1/(2+1)=1/3\). The multiplier is \(1+1.5(1/3)=1.5\), so the loss is \(0.10\times80\times1.5=12\) mg/L/day. The derivative is \(8-12=-4\) mg/L/day.

At \(C=4\) mg/L, the saturable fraction is \(4/(2+4)=2/3\). The multiplier is \(1+1.5(2/3)=2\), so the loss is \(0.10\times80\times2=16\) mg/L/day. The derivative is \(8-16=-8\) mg/L/day.

The higher exposure changes the derivative from \(-4\) to \(-8\) mg/L/day, consistent with the exposure-enhanced loss. This check works because \(E_{\max}\ne0\), \(R\ne0\), and the changed exposures give different saturable fractions.

A related check is to vary one role at a time. At fixed state and parameters, changing exposure should change the derivative when \(E_{\max}\ne0\), \(R\ne0\), and the exposure change changes the saturable fraction. At fixed input and parameters, changing \(R\) changes the loss term in proportion to \(R\). Changing a parameter changes the model’s rule, not the current state or the external exposure value. These are dependency checks, not universal claims that every change must alter every derivative: for example, at \(R=0\), the loss term vanishes for any exposure.

Worked Example: Distinguish a State Change From a Parameter Change

Take \(C=2\) mg/L and the parameters used above. At \(R=80\) mg/L, the derivative is \(-6\) mg/L/day. Now compare two separate changes.

Change the state only. If \(R=40\) mg/L, the multiplier remains \(1.75\), while the loss becomes \(0.10\times40\times1.75=7\) mg/L/day. The derivative is \(8-7=1\) mg/L/day. The function has been evaluated at a different current state.

Change the parameter only. Return to \(R=80\) mg/L and change \(k_{\mathrm{out}}\) from \(0.10\) to \(0.08\) per day. The loss becomes \(0.08\times80\times1.75=11.2\) mg/L/day, giving a derivative of \(8-11.2=-3.2\) mg/L/day. The current state and input are unchanged; the rule has a different fixed parameter value.

These calculations illustrate why the function should receive \(R\) and \(k_{\mathrm{out}}\) in separate arguments. If the program substitutes a stored baseline value for the state, or changes a parameter when it intends to update a state, it no longer evaluates the stated ODE.

Implementation Checks and Common Failure Modes

A practical right-hand-side evaluation can be checked in stages. First confirm that the input is evaluated at the requested time and that parameters are passed as fixed values. Then confirm that the state argument—not a separately stored or previously calculated response—is used in the derivative. Finally, check that the returned value is a derivative with the correct units, rather than a new state value.

1
Make the arguments explicit.
Keep time, the state vector, parameters, and input values or input functions in distinct parts of the function interface.
2
Evaluate the input for the requested time.
Use \(C(t)\) for the time supplied to the right-hand side; do not substitute a constant by accident when the intended input varies over time.
3
Calculate and return derivatives.
Use the supplied state in the model equation and return \(dR/dt\), with units of response per time.
4
Vary one role at a time.
Compare outputs while holding other arguments fixed, and interpret any unchanged result in light of the equation’s conditions.

A common mistake is to store exposure in a global variable and let the ODE function read it implicitly. This hides a model dependency: the same stated arguments can then produce different derivatives depending on external program state. Pass exposure explicitly, or pass a clearly defined input function that can be evaluated at the requested time.

Another mistake is to update the state inside the right-hand-side function. The right-hand side should evaluate the derivative at the solver’s supplied state; it should not advance the state itself. The solver uses repeated derivative evaluations to perform that advancement. Mutating the supplied state can make the calculation depend on evaluation order and can interfere with the solver’s control of the integration.

A third pitfall is treating every biologically measured quantity as a parameter. If a value changes with time and is supplied from outside this ODE, it is an input here. Conversely, if exposure is generated by pharmacokinetic equations in the model, it belongs in the state vector, with its own derivative; that is a different model structure, not merely another way to pass the same external input.

Choosing the Representation and Its Limits

RepresentationAppropriate whenMain consideration
Fixed parameterThe quantity is held constant during the integration being performed.Changing it defines a different parameter setting or simulation.
Time-varying inputThe value is prescribed externally as a function of time.The input must be available at each requested time and in compatible units.
Model stateThe quantity evolves according to an equation included in the model.It needs a derivative and is advanced together with the other states.

The explicit-input formulation is appropriate when exposure is supplied as known or externally generated information and the aim is to calculate the response conditional on that exposure. Representing exposure as a state is preferable when its trajectory is to be generated by the model’s own dynamic equations and coupled to the response. Treating a time-varying exposure as one fixed parameter is only appropriate if it truly remains constant over the integration interval.

This separation does not establish that the exposure-effect relationship is biologically correct, identify parameter values, or account for uncertainty in the supplied input. Nor does it determine how an input should be represented when it changes abruptly. Those are separate modeling and numerical questions. The present structure makes the chosen roles explicit so such decisions can be made without confusing them with state updates or parameter values.

Key takeaway: A reliable ODE interface makes the model’s dependencies visible: parameters specify the rule, inputs supply externally prescribed values, and states are the evolving quantities whose derivatives the function returns. For the exposure-driven turnover model, test dependencies under conditions that make the corresponding terms nonzero.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. In the turnover model, classify \(R(t)\), \(C(t)\), and \(EC_{50}\) when exposure is supplied externally and \(EC_{50}\) is fixed.
  2. For \(R=0\), explain whether changing exposure changes the derivative, assuming the other model quantities are fixed.
  3. Suppose \(R=50\) mg/L, \(k_{\mathrm{in}}=5\) mg/L/day, \(k_{\mathrm{out}}=0.10\) per day, \(E_{\max}=1\), \(EC_{50}=1\) mg/L, and \(C=1\) mg/L. Calculate \(dR/dt\).
  4. If exposure is generated by a pharmacokinetic equation included in the same ODE system, should it be passed only as an external input or represented as a state? Explain.

Solutions. (1) \(R(t)\) is the state, \(C(t)\) is the time-varying input, and \(EC_{50}\) is a fixed parameter. (2) No. The exposure-dependent loss is proportional to \(R\), so at \(R=0\) it is zero for every exposure; the derivative is \(k_{\mathrm{in}}\). (3) The fraction is \(1/(1+1)=0.5\), so the multiplier is \(1+1(0.5)=1.5\). The loss is \(0.10\times50\times1.5=7.5\) mg/L/day, and \(dR/dt=5-7.5=-2.5\) mg/L/day. (4) Represent exposure as a state with its own derivative, because the model itself calculates its time evolution; it is not merely an externally prescribed input in that formulation.

Clinical Biostats