% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/odeToLin.R
\name{odeToLin}
\alias{odeToLin}
\title{Convert ODE-based linear compartment models to analytical linCmt() form}
\usage{
odeToLin(ui)
}
\arguments{
\item{ui}{rxUi-like model object (function, rxUi, or anything accepted by
\code{as.rxUi}).}
}
\value{
An rxUi model with ODE equations replaced by \code{linCmt()}, or
(with a message) the original model unchanged if conversion is not possible.
}
\description{
Detects whether a model's ODE equations form a standard 1-3 compartment PK
system and, if so, replaces the \code{d/dt()} equations and the central
output assignment (e.g. \code{cp <- central/v}) with \code{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 \code{var <- central_cmt / v_expr}.
Named parameter assignments are retained so \code{linCmt()} can infer the
parameterization.
}
\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)

}
\seealso{
\code{\link{linToOde}} for the inverse transformation.
}
\author{
Matthew Fidler
}
