R scripts: newoutput.R

Mlxtran codes: model/newoutput.txt

Monolix project: theophylline_project.mlxtran


$$ \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}}}$$

Imagine that we want to define as output of simulx some variables which are not defined in the Mlxtran model code. It is then possible to create a new model file with additional lines defined in the R script.

The new input argument addlines of simulx is a list (or a list of lists) with fields * section: “[LONGITUDINAL]” (default), “[INDIVIDUAL]”, “[COVARIATE]” or “[POPULATION]” * block: “EQUATION:” or “DEFINITION:” * formula: a single string (e.g. formula = "ddt_auc=Cc"), or a vector of strings e.g. formula = c("lc = log(Cc)", "ddt_auc=Cc")

1 Example 1

We are using in this example the model “newoutput.txt”:

[LONGITUDINAL]
input = {V, k, a}
EQUATION:
Cc = pkmodel(V,k)
DEFINITION:
y = {distribution=lognormal, prediction=Cc, sd=a}

[INDIVIDUAL]
input = {V_pop, omega_V, w}
EQUATION:
Vpred=V_pop*(w/70)
DEFINITION:
V = {distribution=lognormal, prediction=Vpred, sd=omega_V}

Suppose that we want to compute a variable which is not defined in the model:

We just need for that to define the input argument addlines with an additional formula:

Then, auc is part of the outputs:

## [1] "Cc"        "auc"       "treatment"
##   time        Cc       auc
## 1  0.0 11.031547  0.000000
## 2  0.5  9.981757  5.248911
## 3  1.0  9.031867  9.998270
## 4  1.5  8.172371 14.295832
## 5  2.0  7.394667 18.184554
## 6  2.5  6.690972 21.703141


We could also define \(Vn\) as a new individual parameter:

## [1] "Cc"        "auc"       "parameter" "group"     "treatment"
##   id       Vn         V
## 1  1 5.806074 10.821595
## 2  2 7.012061  9.270943
## 3  3 6.543728  8.575489
## 4  4 6.204833  9.782001
## 5  5 7.054005  5.981496


We can also create groups with different outputs which are not defined in the original model (\(\log(Cc)\) for group 1 and \(\int Cc\) for group2 in this example):

## [1] "y"         "Cc"        "lc"        "auc"       "parameter" "group"    
## [7] "treatment"


2 Example 2

This feature is particularly useful when simulx is used with a Monolix project and when we don’t want to modify the original model used by Monolix.

Computing the AUC, for instance, only requires defining this new variable in addlines:

## [1] "CONC"       "Cc"         "auc"        "treatment"  "originalId"
## [6] "population"
##   id time       Cc       auc
## 1  1  0.0 0.000000 0.0000000
## 2  1  0.1 1.020864 0.0518490
## 3  1  0.2 1.949228 0.2010905
## 4  1  0.3 2.792796 0.4388658
## 5  1  0.4 3.558635 0.7570530
## 6  1  0.5 4.253227 1.1481971