$NMEXT
= 101
run = "../model/nonmem"
project = "cppfile" root
The $NMEXT
and $NMXML
blocks allow you to import estimates (THETA, SIGMA, and OMEGA) from a NONMEM run. So if you are running a population PK model in NONMEM and translating to mrgsolve, you should never need to copy the final estimate but rather read them in using these blocks.
If you are running sequential PK/PD or parent/metabolite models, you might need to pull estimates from multiple NONMEM runs. This is easy to do with multiple $NMEXT
(or $NMXML
) blocks.
1 Import the first (PK) model
First, grab the estimates from the PK model; let’s call it run 101. The $NMEXT
block could look like this
This will find the file 201.ext
in the ../model
directory which is taken to be relative to the location of the mrgsolve model file (using the root
argument). If the paths are a little confusing, you can try installing the here package and using
$NMEXT
= 101
run = here::here("model/nonmem") project
This would require an Rstudio project file in the (project) root directory and then we would locate the NONMEM run relative to that project root (e.g. in <project-root>/model/nonmem
).
Once the first model is imported, we now have access to THETA1
, THETA2
etc from the PK model.
2 Import the second (PD) model
Now, we import estimates from the PD model run (let’s call it 201) using another call to $NMEXT
$NMEXT
= 201
run = here::here("model/nonmem")
project = "theta" tname
This is the second import in the same mrgsolve model file, so we change the handle for referencing the THETA
estimates: now the PD model uses theta1
, theta2
etc so that we can retain the THETA numbering for both the PK and PD models, remembering that the PD model uses theta1
(lower case) while the PK model uses THETA1
(upper case). Note that we have to change the handle (to something like theta
) otherwise mrgsolve will throw an error because there would be two THETA1
in the parameter list.