knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(rxode2) setRxThreads(1L) library(data.table) setDTthreads(1L)
The goal of nonmem2rx
is to convert a NONMEM control stream to
rxode2
for easy clinical trial simulation in R.
Here is a quick example of a conversion:
library(nonmem2rx) # First we need the location of the nonmem control stream Since we are running an example, we will use one of the built-in examples in `nonmem2rx` ctlFile <- system.file("mods/cpt/runODE032.ctl", package="nonmem2rx") # You can use a control stream or other file. With the development # version of `babelmixr2`, you can simply point to the listing file mod <- nonmem2rx(ctlFile, lst=".res", save=FALSE, determineError=FALSE) mod
nonmem2rx
for your modelSome common options that you may want to change when importing NONMEM control stream are:
The default NONMEM output extension; By default it is .lst
. You
can set it to something else, like .res
, using the following
option: options(nonmem2rx.lst=".res")
.
Turn on extended control
stream
support. You can turn it on by options(nonmem2rx.extended=TRUE)
You probably also want to change the name of parameters and compartments. The easiest way to name the parameters whatever you want is to pre-specify the names. For example:
mod <- nonmem2rx(system.file("mods/cpt/runODE032.ctl", package="nonmem2rx"), lst=".res", save=FALSE, thetaNames=c("lcl", "lvc", "lq", "lvp", "prop.sd"), etaNames=c("eta.cl", "eta.vc", "eta.q","eta.vp"), cmtNames = c("central", "perip")) mod
This checks the parameter names to make sure they are the same
length as the input names, if they are not, the model will skip parameter
renaming and keep the default translation names theta#
and eta#
.
As a note, sigma
parameters are not currently renamed; So for the
following model (which grabs the parameter automatically labels to
generate variables), sigma
is simply eps#
.
mod <- nonmem2rx(system.file("Theopd.ctl", package="nonmem2rx"), save=FALSE) mod
You can still rename however you wish, though, using model piping
(rxRename()
or dplyr::rename()
would both work):
mod <- mod %>% rxRename(add.var=eps1) mod
This model does not specify the residuals in a way that makes sense to
nlmixr2
. If you want, you can still convert the rxode2
model to
a nlmixr2 fit.
The key files to import are the NONMEM control stream (or related
file) and the NONMEM output (often with a .lst
or .res
extension).
The import process steps are below:
Read in the nonmem control stream and convert the model to a
rxode2
ui function.
Try to determine an endpoint/residual specification in the model (if
possible), and convert to a fully qualified ui model that can be
used in nlmixr2
and rxode2
. If it cannot be determined
automatically, you can manually fix this and
still convert to a nlmixr2
object (if the data/estimates are
available of course).
If available, nonmem2rx
will read the final parameter estimates
and update the model.
The converter will read in the nonmem input dataset, and search for
the output files with IPRED
, PRED
and the ETA
values. The
translated rxode2
model is run for the population parameters and
the individual parameters. This will then compare the results
between NONMEM
and rxode2
to make sure the translation makes
sense. This only works when nonmem2rx
has access to the input
data and the output with the IWRES
, IPRED
, PRED
and the ETA
values.
Converts the upper case NONMEM variables to lower case (can be
turned off with nonmem2rx(..., toLowerLhs=FALSE))
)
Replaces the NONMEM theta / eta names with the label-based names
like an extended control stream (can be turned off with
nonmem2rx(thetaNames=FALSE, etaNames=FALSE)
)
Replaces the compartment names with the defined compartment names in
the control stream (ie COMP=(compartmenName)
)
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.