R script: pk3.R


$$ \newcommand{\esp}[1]{\mathbb{E}\left(#1\right)} \newcommand{\var}[1]{\mbox{Var}\left(#1\right)} \newcommand{\deriv}[1]{\dot{#1}(t)} \newcommand{\prob}[1]{ \mathbb{P}\!(#1)} \newcommand{\eqdef}{\mathop{=}\limits^{\mathrm{def}}} \newcommand{\by}{\boldsymbol{y}} \newcommand{\bc}{\boldsymbol{c}} \newcommand{\bpsi}{\boldsymbol{\psi}} \def\pmacro{\texttt{p}} \def\like{{\cal L}} \def\llike{{\cal LL}} \def\logit{{\rm logit}} \def\probit{{\rm probit}} \def\one{{\rm 1\!I}} \def\iid{\mathop{\sim}_{\rm i.i.d.}} \def\simh0{\mathop{\sim}_{H_0}} \def\df{\texttt{df}} \def\res{e} \def\xomega{x} \newcommand{\argmin}[1]{{\rm arg}\min_{#1}} \newcommand{\argmax}[1]{{\rm arg}\max_{#1}} \newcommand{\Rset}{\mbox{$\mathbb{R}$}} \def\param{\theta} \def\setparam{\Theta} \def\xnew{x_{\rm new}} \def\fnew{f_{\rm new}} \def\ynew{y_{\rm new}} \def\nnew{n_{\rm new}} \def\enew{e_{\rm new}} \def\Xnew{X_{\rm new}} \def\hfnew{\widehat{\fnew}} \def\degree{m} \def\nbeta{d} \newcommand{\limite}[1]{\mathop{\longrightarrow}\limits_{#1}} \def\ka{k{\scriptstyle a}} \def\ska{k{\scriptscriptstyle a}} \def\kel{k{\scriptstyle e}} \def\skel{k{\scriptscriptstyle e}} \def\cl{C{\small l}} \def\Tlag{T\hspace{-0.1em}{\scriptstyle lag}} \def\sTlag{T\hspace{-0.07em}{\scriptscriptstyle lag}} \def\Tk{T\hspace{-0.1em}{\scriptstyle k0}} \def\sTk{T\hspace{-0.07em}{\scriptscriptstyle k0}} \def\thalf{t{\scriptstyle 1/2}} \newcommand{\Dphi}[1]{\partial_\pphi #1} \def\asigma{a} \def\pphi{\psi} \newcommand{\stheta}{{\theta^\star}} \newcommand{\htheta}{{\widehat{\theta}}}$$

1 Introduction

The dose amount can easily be defined a the function of some individual covariate, such as the weight.

In the two following examples, the dose amount is defined per kilo (2 mg per kilo) and the weight is used as the fraction which is absorbed.


2 Examples

2.1 Defining the weight in the Mlxtran model file

We use the function pkmodel in this example with the input argument p.

The weight w is defined as a covariate which is randomly sampled from the model defined in section [COVARIATE].

We use a PK model for iv bolus administration, assuming that the volume of the central compartment is equal to 1. The concentration at \(t=0\) is therefore the dose amount administrated at \(t=0\), i.e. twice the individual weight.

pkmodel1 <- inlineModel("
[LONGITUDINAL]
input = {V, k, w}
EQUATION:
Cc = pkmodel(V, k, p=w)

;----------------------------------------------
[COVARIATE]
input = {w_pop, omega_w}
DEFINITION:
w = {distribution = normal, mean = w_pop, sd = omega_w}
")

p   <- c(w_pop=70, omega_w=12, k=0.1, V=10)
dosePerKg <- 2
trtPerKg <- list(amt=dosePerKg, time=c(0, 12, 24))
Cc  <- list(name='Cc', time=seq(0, 36, by=1))
w   <- list(name='w')

res <- simulx(model     = pkmodel1, 
              parameter = p, 
              treatment = trtPerKg,
              output    = list(Cc,w),
              group     = list(size=3, level="covariate"),
              settings  = list(seed=123))

print(res$parameter)
##   id        w
## 1  1 71.55185
## 2  2 58.28215
## 3  3 91.86812
print(res$Cc[res$Cc$time==0,])
##    id time       Cc
## 1   1    0 14.31037
## 38  2    0 11.65643
## 75  3    0 18.37362
print(ggplot(data=res$Cc) + geom_line(aes(x=time, y=Cc, colour=id)) +
  theme(legend.position=c(.9, .8)))

2.2 Defining the individual weights in the R script

Of course, it is also possible to define the weights in the R script as a data frame and use it as an input argument of the model:

pkmodel2 <- inlineModel("
[LONGITUDINAL]
input = {V, k, w}
EQUATION:
Cc = pkmodel(V, k, p=w)
")

weight <- data.frame(id=(1:3), w=c(60,80,90))

res <- simulx(model     = pkmodel2, 
              parameter = list(p, weight),
              treatment = trtPerKg,
              output    = Cc)

print(res$Cc[res$Cc$time==0,])
##    id time Cc
## 1   1    0 12
## 38  2    0 16
## 75  3    0 18
print(ggplot(data=res$Cc) + geom_line(aes(x=time, y=Cc, colour=id)) +
  theme(legend.position=c(.9, .8)))

2.3 Defining the individual dose regimens in the R script

The doses can also be defined in the R script. In such case, the treatment should be defined a a data frame:

pkmodel3 <- inlineModel("
[LONGITUDINAL]
input = {V, k}
EQUATION:
Cc = pkmodel(V, k)
")

w <- c(60,80,90)
N <- length(w)
times <- c(0, 12, 24)
nbTimes <- length(times)
trt <- data.frame(id     = rep(1:N,each=nbTimes),
                  time   = rep(times,N),
                  amount = rep(dosePerKg*w,each=nbTimes))

res <- simulx(model     = pkmodel3, 
              parameter = p, 
              treatment = trt,
              output    = Cc)

print(res$Cc[res$Cc$time==0,])
##    id time Cc
## 1   1    0 12
## 38  2    0 16
## 75  3    0 18
print(ggplot(data=res$Cc) + geom_line(aes(x=time, y=Cc, colour=id)) +
  theme(legend.position=c(.9, .8)))


2.4 Using an ODE based model with depot


The same PK model is defined here by an ODE with the PK macro depot and the input argument p.

The individual weights w are defined as an input of the model.

pkmodel4 <- inlineModel("
[LONGITUDINAL]
input = {V, k, w}

PK:
depot(target=Ac, p=w)
EQUATION:
ddt_Ac = -k*Ac
Cc = Ac/V
")

res <- simulx(model     = pkmodel4, 
              parameter = list(p, weight),
              treatment = trtPerKg,
              output    = list(Cc))

print(res$Cc[res$Cc$time==0,])
##    id time Cc
## 1   1    0 12
## 38  2    0 16
## 75  3    0 18
print(ggplot(data=res$Cc) + geom_line(aes(x=time, y=Cc, colour=id)) +
  theme(legend.position=c(.9, .8)))