An RxODE
model specification consists of one or more
statements optionally terminated by semi-colons ;
and
optional comments (comments are delimited by #
and an
end-of-line).
A block of statements is a set of statements delimited by
curly braces, { ... }
.
Statements can be either assignments, conditional if
/else
if
/else
, while
loops (can be exited by break
), special
statements, or printing statements (for debugging/testing)
Assignment statements can be:
simple assignments, where the left hand is an identifier (i.e., variable)
special time-derivative assignments, where the left hand
specifies the change of the amount in the corresponding state
variable (compartment) with respect to time e.g., d/dt(depot)
:
special initial-condition assignments where the left hand
specifies the compartment of the initial condition being specified,
e.g. depot(0) = 0
special model event changes including bioavailability
(f(depot)=1
), lag time (alag(depot)=0
), modeled rate
(rate(depot)=2
) and modeled duration (dur(depot)=2
). An
example of these model features and the event specification for the
modeled infusions the RxODE data specification is found in RxODE
events vignette.
special change point syntax, or model times. These model times are
specified by mtime(var)=time
special Jacobian-derivative assignments, where the left hand
specifies the change in the compartment ode with respect to a
variable. For example, if d/dt(y) = dy
, then a Jacobian for this
compartment can be specified as df(y)/dy(dy) = 1
. There may be
some advantage to obtaining the solution or specifying the Jacobian
for very stiff ODE systems. However, for the few stiff systems we
tried with LSODA, this actually slightly slowed down the solving.
Note that assignment can be done by =
, <-
or ~
.
When assigning with the ~
operator, the simple
assignments and time-derivative assignments will not be output.
Special statements can be:
Compartment declaration statements, which can change the default
dosing compartment and the assumed compartment number(s) as well as
add extra compartment names at the end (useful for multiple-endpoint
nlmixr models); These are specified by cmt(compartmentName)
Parameter declaration statements, which can make sure the input
parameters are in a certain order instead of ordering the parameters
by the order they are parsed. This is useful for keeping the
parameter order the same when using 2 different ODE models. These
are specified by param(par1, par2,...)
An example model is shown below:
# simple assignment C2 = centr/V2; # time-derivative assignment d/dt(centr) = F*KA*depot - CL*C2 - Q*C2 + Q*C3;
Expressions in assignment and if
statements can be numeric or logical,
however, no character nor integer expressions are currently supported.
Numeric expressions can include the following numeric operators +, -,
*, /, ^
and those mathematical functions defined in the C or the R
math libraries (e.g., fabs
, exp
, log
, sin
, abs
).
You may also access the R's functions in the R math
libraries,
like lgammafn
for the log gamma function.
The RxODE
syntax is case-sensitive, i.e., ABC
is different
than abc
, Abc
, ABc
, etc.
Like R, Identifiers (variable names) may consist of one or more alphanumeric,
underscore _
or period .
characters, but the first character
cannot be a digit or underscore _
.
Identifiers in a model specification can refer to:
t
(time), tlast
(last time point), and
podo
(oral dose, in the undocumented case of absorption transit
models).pi
or
R's predefined constants.ka
rate of absorption, CL
clearance, etc.)Currently, the RxODE
modeling language only recognizes system state
variables and "parameters", thus, any values that need to be passed
from R to the ODE model (e.g., age
) should be either passed in the
params
argument of the integrator function rxSolve()
or be in the
supplied event data-set.
There are certain variable names that are in the RxODE
event tables.
To avoid confusion, the following event table-related items cannot be
assigned, or used as a state but can be accessed in the RxODE code:
cmt
dvid
addl
ss
rate
id
However the following variables are cannot be used in a model specification:
evid
ii
Sometimes RxODE generates variables that are fed back to RxODE.
Similarly, nlmixr generates some variables that are used in nlmixr
estimation and simulation. These variables start with the either the
rx
or nlmixr
prefixes. To avoid any problems, it is suggested to
not use these variables starting with either the rx
or nlmixr
prefixes.
Logical operators support the standard R operators ==
, !=
>=
<=
>
and <
. Like R these can be in if()
or while()
statements, ifelse()
expressions. Additionally they can be in a
standard assignment. For instance, the following is valid:
cov1 = covm*(sexf == "female") + covm*(sexf != "female")
Notice that you can also use character expressions in comparisons.
This convenience comes at a cost since character comparisons are
slower than numeric expressions. Unlike R, as.numeric
or
as.integer
for these logical statements is not only not needed, but
will cause an syntax error if you try to use the function.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.