
Convert ODE-based linear compartment models to analytical linCmt() form
Source:R/odeToLin.R
odeToLin.RdDetects whether a model's ODE equations form a standard 1-3 compartment PK
system and, if so, replaces the d/dt() equations and the central
output assignment (e.g. cp <- central/v) with cp <- linCmt(),
preserving all other model lines. Detection requires linear ODE
right-hand sides, 1-4 compartments in a standard depot/central/peripheral
topology, and one output line of the form var <- central_cmt / v_expr.
Named parameter assignments are retained so linCmt() can infer the
parameterization.
Value
An rxUi model with ODE equations replaced by linCmt(), or
(with a message) the original model unchanged if conversion is not possible.
See also
linToOde for the inverse transformation.
Examples
oneCmtOde <- function() {
ini({
tka <- 0.45
tcl <- log(2.7)
tv <- 3.45
add.sd <- 0.7
})
model({
ka <- exp(tka)
cl <- exp(tcl)
v <- exp(tv)
d/dt(depot) <- -ka * depot
d/dt(central) <- ka * depot - cl/v * central
cp <- central / v
cp ~ add(add.sd)
})
}
linCmtModel <- odeToLin(oneCmtOde)
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments