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

We will use again the theophylline project, where the parameters have been estimated with Monolix, but with different numbers of patient.

Remark: in this project, the amount is given in mg per kilo.

project.file <- 'monolixRuns/theophylline_project.mlxtran'

Simulate a trial with N individuals: the designs and the weights of these N patients are sampled from the original dataset

N <- 30
res1  <- simulx(project = project.file,
                group   = list(size = N))

print(ggplot(data=res1$y1) + 
        geom_point(aes(x=time, y=y1, colour=id)) +
        geom_line(aes(x=time, y=y1, colour=id)) +
        scale_x_continuous("Time") + scale_y_continuous("Concentration") +
        theme(legend.position="none"))

The designs of the \(N=30\) individuals are sampled from the 12 original designs

print(res1$treatment)
##    id time amount
## 1   1    0    320
## 2   2    0    320
## 3   3    0    320
## 4   4    0    320
## 5   5    0    320
## 6   6    0    320
## 7   7    0    320
## 8   8    0    320
## 9   9    0    320
## 10 10    0    320
## 11 11    0    320
## 12 12    0    320
## 13 13    0    320
## 14 14    0    320
## 15 15    0    320
## 16 16    0    320
## 17 17    0    320
## 18 18    0    320
## 19 19    0    320
## 20 20    0    320
## 21 21    0    320
## 22 22    0    320
## 23 23    0    320
## 24 24    0    320
## 25 25    0    320
## 26 26    0    320
## 27 27    0    320
## 28 28    0    320
## 29 29    0    320
## 30 30    0    320

By default, settings$replacement=F, which means that the new id’s are sampled within the original ones without replacement

print(res1$originalId)
##    newId oriId
## 1      1     1
## 2      2     2
## 3      3     3
## 4      4     4
## 5      5     5
## 6      6     6
## 7      7     7
## 8      8     8
## 9      9     9
## 10    10    10
## 11    11    11
## 12    12    12
## 13    13     1
## 14    14     2
## 15    15     3
## 16    16     4
## 17    17     5
## 18    18     6
## 19    19     7
## 20    20     8
## 21    21     9
## 22    22    10
## 23    23    11
## 24    24    12
## 25    25     1
## 26    26     2
## 27    27     6
## 28    28     7
## 29    29     8
## 30    30    12

New id’s are sampled with replacement by setting settings$replacement=T

res2  <- simulx(project = project.file,
                group   = list(size = N),
                settings  = list(replacement=T))
print(res2$originalId)
##    newId oriId
## 1      1     7
## 2      2     1
## 3      3     7
## 4      4     8
## 5      5    11
## 6      6    11
## 7      7     1
## 8      8     8
## 9      9     2
## 10    10    11
## 11    11    10
## 12    12     7
## 13    13     3
## 14    14     7
## 15    15     8
## 16    16    10
## 17    17     8
## 18    18     1
## 19    19    10
## 20    20     4
## 21    21     7
## 22    22     6
## 23    23    11
## 24    24     8
## 25    25    12
## 26    26     6
## 27    27     6
## 28    28     6
## 29    29     7
## 30    30     7

When a new size group is defined, estimated individual parameters are resampled as well,

N <- 5
res3  <- simulx(project = project.file,
                parameter = "mode",
                group   = list(size = N))
print(res3$originalId)
##   newId oriId
## 1     1     1
## 2     2     2
## 3     3     3
## 4     4    10
## 5     5    12