-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29a5345
commit eabe02f
Showing
3 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
--- | ||
title: "Simulate Derived Variables from imported Monolix model" | ||
output: rmarkdown::html_vignette | ||
vignette: > | ||
%\VignetteIndexEntry{Simulate Derived Variables from imported Monolix model} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
library(rxode2) | ||
setRxThreads(1L) | ||
library(data.table) | ||
setDTthreads(1L) | ||
``` | ||
|
||
This page shows a simple work-flow for directly simulating a different | ||
dosing paradigm with new derived items, in this case `AUC`. | ||
|
||
|
||
## Step 1: Import the model | ||
|
||
```{r setup} | ||
library(monolix2rx) | ||
library(rxode2) | ||
# 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 | ||
# You use the path to the monolix mlxtran file | ||
# In this case we will us the theophylline project included in monolix2rx | ||
pkgTheo <- system.file("theo/theophylline_project.mlxtran", package="monolix2rx") | ||
# Note you have to setup monolix2rx to use the model library or save | ||
# the model as a separate file | ||
mod <- monolix2rx(pkgTheo) | ||
print(mod) | ||
``` | ||
|
||
## Step 2: Add AUC calculation | ||
|
||
The concentration in this case is the `Cc` from the model, a trick to | ||
get the `AUC` is to have an additional ODE `d/dt(AUC) <- Cc` and use | ||
some reset to get it per dosing period. | ||
|
||
However, this additional parameter is not part of the original model. | ||
The calculation of AUC would depend on the number of observations in | ||
your model, and for sparse data wouldn't be terribly accurate. | ||
|
||
One thing you can do is to use model piping append `d/dt(AUC) <- Cc` to | ||
the imported model: | ||
|
||
```{r modAuc} | ||
modAuc <- mod %>% | ||
model(d/dt(AUC) <- Cc, append=TRUE) | ||
modAuc | ||
``` | ||
|
||
You can also use `append=NA` to pre-pend or `append=f` to put the ODE | ||
right after the `f` line in the model. | ||
|
||
## Step 3: Setup event table to calculate the AUC for a different dosing paradigm: | ||
|
||
Lets say that in this case instead of a single dose, we want to see | ||
what the concentration profile is with a single day of BID dosing. In | ||
this case is done by creating a [quick event | ||
table](https://nlmixr2.github.io/rxode2/articles/rxode2-event-table.html). | ||
|
||
In this case since we are also wanting `AUC` per dosing period, you | ||
can add a reset dose to the `AUC` compartment every time a dose is given | ||
(so it will only track the AUC of the current dose): | ||
|
||
```{r eventTable} | ||
ev <- et(amt=4, ii=12, until=24) %>% | ||
et(amt=0, ii=12, until=24, cmt="AUC", evid=5) %>% # replace AUC with zero at dosing | ||
et(c(0, 4, 8, 11.999, 12, 12.01, 14, 20, 23.999, 24, 24.001, 28, 32, 36)) %>% | ||
et(id=1:10) | ||
``` | ||
|
||
## Step 4: Solve using `rxode2` | ||
|
||
In this step, we solve the model with the new event table for the 10 | ||
subjects: | ||
|
||
```{r solve} | ||
s <- rxSolve(modAuc, ev) | ||
``` | ||
|
||
Note that since this derived from a `nonmem2rx` model, the default | ||
solving will match the tolerances and methods specified in your | ||
`NONMEM` model. | ||
|
||
## Step 5: Exploring the simulation (by plotting), and summarizing (dplyr) | ||
|
||
This solved object acts the same as any other `rxode2` solved object, | ||
so you can use the `plot()` function to see the individual running AUC profiles | ||
you simulated: | ||
|
||
```{r plot} | ||
library(ggplot2) | ||
plot(s, AUC) + | ||
ylab("Running AUC") | ||
``` | ||
|
||
You can also select the points near the dosing to get the AUC for the | ||
interval: | ||
|
||
```{r gatherAuc} | ||
library(dplyr) | ||
s %>% filter(time %in% c(11.999, 23.999)) %>% | ||
mutate(time=round(time)) %>% | ||
select(id, time, AUC) | ||
``` |