Thank you Leonid and Andreas!
Can we have Nonmem support the combination of $ETAS and $SIMULATION
ONLYSIM? That would enable NMsim to completely automate simulations of
known subjects with residual variability, just like it already automates
simulation of new subjects with residual variability.
Currently, I am using the "mixed option" mentioned by Leonid. This is
only needed with NMsim if simulating "known" subjects (ETAs) or if the
Nonmem model for some reason does not produce a variable with residual
variability. See the "patch" below for examples.
*NMsim automates simulation with new or known subjects*
The reason why I am searching for a Nonmem-native method is that NMsim
automates simulation of Nonmem models based on the estimation control
stream and a simulation dataset. The idea is to avoid any
reimplementation but let Nonmem run the simulation. It works nicely and
can automatically grab ETAs from a phi file to simulate
estimated/"known" subjects. The syntax for this feature is
```
results.sim <- NMsim(file.mod="path/to/input/control.mod",
data=data.sim,
method.sim=NMsim_known)
```
Currently, it searches for a .phi file next to the control.mod (which
can be called control.ctl or anything) but this will be generalized in
next version so you can pull in other subjects.
If you omit `method.sim` it will use the default method which is
generation of new subjects (ETAs) using $SIMULATION ONLYSIM. In that
case the residual variability is simulated too.
*NMsim's patch called addResVar*
NMsim's addResVar() grabs the parameter estimates from .ext and adds
residual variability. The following example reproduces the residual
variability implemented in Nonmem with SIGMA parameters where SIGMA(1,1)
is the variance of the proportional error component, SIGMA(2,2) the one
of the additive component (and SIGMA(1,2) the covariance). `simres` is a
data.frame containing results from a simulation without residual
variability (but with IPRED):
```
simres.var <- addResVar(data=simres,
path.ext = "path/to/model.ext"
,prop = 1
,add = 2
,par.type = "SIGMA"
,log = FALSE)
```
If using par.type="THETA", prop and add (obviously not both if the error
model is not combined) have to provide the THETA element numbers in use.
If par.type="THETA", addResVar is by default interpreting the
parameters as standard devs, with SIGMAs, they are variances. This can
be modified using another argument, see help. log=TRUE means the
variability is on log scale, i.e. the "exponential error model".
`addResVar` is a last-resort patch. Since it reimplements the residual
error model, it is up to your QC to check that the right parameters are
selected etc. It would be way better if we can have Nonmem do the sim,
and we would know it is the exact same model that was used for
simulation and for estimation.
*Further interested?*
NMsim is on CRAN. If you are interested in discussions on these issues,
you are very welcome at https://github.com/philipdelff/NMsim/issues.
Thank you,
Philip
On 10/8/23 22:22, Leonid Gibiansky wrote:
The only way I know to simulate with residual variability is to use
$SIM SIMONLY
If ETAs need to be fixed, they have to be in the data file
$INPUT ,PKETA1,
CL=THETA(1)*EXP(PKETA1+0*ETA(1))
--
another option is to use mrgsolve or similar R packages (after reading
in estimated ETA values).
--
Mixed option is to simulate IPRED and then add noise in the R code after
reading IPRED.
Thank you
Leonid
On 10/8/2023 3:30 PM, Philip Harder Delff wrote:
Dear all,
I want to simulate subjects with ETAs estimated. I use the .phi file
using a $ETAS statement like:
$ETAS FILE=file.phi FORMAT=s1pE15.8 TBLN=1
As far as I understand that has to be accompanied by a $ESTIMATION
step that specifies FNLETA=2 like this:
$ESTIMATION MAXEVAL=0 NOABORT METHOD=1 INTERACTION FNLETA=2
$SIM ONLYSIM does not work with $ESTIMATION so instead I just do:
$SIMULATION (220412)
This however means that in the following from $ERROR we don't get the
ERR(1) and ERR(2) simulated and so Y=IPRED.
Y=F+F*ERR(1)+ERR(2)
I need to be able to edit the phi file to only simulate a subset of
the patients so I can't use msf based solutions. Can I somehow use
$ETAS without $ESTIMATION? Or how else can I get it to simulate the
residual variability?
Thank you,
Philip