Created
January 7, 2021 09:33
-
-
Save rfaelens/ea5a2c225b86f120b0020d616c4eedda to your computer and use it in GitHub Desktop.
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
## Author: Ruben Faelens, 2021 | |
## Goal: demo for RxODE use | |
## See https://nlmixrdevelopment.github.io/RxODE/articles/RxODE-sim-var.html for more examples | |
library(tidyverse) | |
library(RxODE) | |
modelCode <- " | |
KA = THETA1; | |
V = THETA2 * exp(ETA1) * (BW/70); | |
CL = THETA3 * exp(ETA2) * (BW/70)**0.75; | |
Ke = CL/V; | |
d/dt(A0) = -KA*A0; | |
d/dt(A1) = KA*A0 - Ke*A1; | |
CONC = A1 / V | |
" | |
m1 <- RxODE::RxODE(modelCode) | |
## Simulate from a dataset | |
N <- 100 | |
theta <- c(THETA1=0.05, | |
THETA2=2, | |
THETA3=0.1) | |
omega <- lotri(ETA1 + ETA2 ~ c(0.4^2, 0, 0.3^2)) | |
events <- eventTable() %>% | |
add.dosing(dose=10, nbr.doses=10, dosing.interval=48) %>% | |
add.sampling(time=seq(0, 100, by=0.1)) | |
db <- tibble( | |
ID=seq_len(N), | |
BW=rnorm(N, 70, 0.10*70) | |
) | |
db <- expand_grid(db, events$get.EventTable()) | |
sim <- rxSolve(m1, theta, db, omega=omega) | |
ggplot(sim, aes(x=time, y=CONC)) + | |
# geom_line(aes(group=id)) + | |
stat_summary(fun=mean, color='red') + | |
stat_summary(fun="mean_cl_boot", geom="ribbon") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment