mrgsim | R Documentation |
This function sets up the simulation run from data stored in the model
object as well as arguments passed in. Use mrgsim_q()
instead
to benchmark mrgsolve or to do repeated quick simulation for tasks like
parameter optimization, sensitivity analyses, or optimal design. See
mrgsim_variants for other mrgsim-like functions that have more focused
inputs. mrgsim_df
coerces output to data.frame prior to returning.
mrgsim(x, data = NULL, idata = NULL, events = NULL, nid = NULL, ...)
mrgsim_df(..., output = "df")
do_mrgsim(
x,
data,
idata = no_idata_set(),
carry_out = carry.out,
carry.out = character(0),
recover = character(0),
seed = as.integer(NA),
Request = character(0),
output = NULL,
capture = NULL,
obsonly = FALSE,
obsaug = FALSE,
tgrid = NULL,
etasrc = "omega",
recsort = 1,
deslist = list(),
descol = character(0),
filbak = TRUE,
tad = FALSE,
nocb = TRUE,
skip_init_calc = FALSE,
ss_n = 500,
ss_fixed = FALSE,
interrupt = 256,
...
)
x |
the model object. |
data |
NMTRAN-like data set (see |
idata |
a matrix or data frame of model parameters,
one parameter per row (see |
events |
an event object. |
nid |
integer number of individuals to simulate; only used if idata and data are missing. |
... |
passed to |
output |
if |
carry_out |
numeric data items to copy into the output. |
carry.out |
soon to be deprecated; use |
recover |
character column names in either |
seed |
deprecated. |
Request |
compartments or captured variables to retain
in the simulated output; this is different than the |
capture |
character file name used for debugging (not related
to |
obsonly |
if |
obsaug |
augment the data set with time grid observations; when
|
tgrid |
a tgrid object; or a numeric vector of simulation times
or another object with an |
etasrc |
source for |
recsort |
record sorting flag. Default value is 1. Possible values
are 1,2,3,4: 1 and 2 put doses in a data set after padded observations at
the same time; 3 and 4 put those doses before padded observations at the
same time. 2 and 4 will put doses scheduled through |
deslist |
a list of tgrid objects. |
descol |
the name of a column for assigning designs. |
filbak |
carry data items backward when the first data set row has time greater than zero. |
tad |
when |
nocb |
if |
skip_init_calc |
don't use |
ss_n |
maximum number of iterations for determining steady state for
the PK system; a warning will be issued if steady state is not achieved
within |
ss_fixed |
if |
interrupt |
integer check user interrupt interval; when |
Use mrgsim_df()
to return a data frame rather than
mrgsims
object.
Both data
and idata
will be coerced to numeric matrix
carry_out
can be used to insert data columns into the output
data set. This is partially dependent on the nature of the data brought
into the problem.
When using data
and idata
together, an error is
generated if an ID occurs in data
but not idata
.
Also, when looking up data in idata
, ID in idata
is
assumed to be uniquely keyed to ID in data
. No error is
generated if ID is duplicated in data
; parameters will be used
from the first occurrence found in idata
.
carry_out
: idata
is assumed to be individual-level and variables that
are carried from idata
are repeated throughout the individual's simulated
data. Variables carried from data
are carried via last-observation carry
forward. NA
is returned from observations that are inserted into
simulated output that occur prior to the first record in data
.
recover
: this is similar to carry_out
with respect to
end result, but it uses a different process. Columns to be recovered are
cached prior to running the simulation, and then joined back on to the
simulated data. So, whereas carry_out
will only accept numeric
data items, recover
can handle data frame columns of any type. There
is a small decrease in performance with recover
compared to
carry_out
, but it is likely that the performance difference is
difficult to perceive (when the simulation runs very fast) or only a small
fractional increase in run time when the simulation is very large. And any
performance hit is likely to be well worth it in light of the convenience
gain. Just think carefully about using this feature when every millisecond
counts.
etasrc
: this argument lets you control where ETA(n)
come from in the
model. When etasrc
is set to "omega"
(the default), ETAs
will be
simulated from a multivariate normal distribution defined by the $OMEGA
blocks in the model. Alternatively, input data
or idata
sets can be used
to pass in fixed ETA(n)
by setting etasrc
to "data"
, "idata"
,
"data.all"
or "idata.all"
. When etasrc
is set to "data"
or "data.all"
,
the input data set will be scanned for columns called ETA1
, ETA2
, ...,
ETAn
and those values will be copied into the appropriate slot in the
ETA()
vector. Only the first record for each individual will be copied into
ETA()
; all records after the first will be ignored. When there are more
than 9
ETAs
in a model, NONMEM will start naming the outputs ET10
,
ET11
etc rather than ETA10
and ETA11
. When mrgsolve is looking for
these columns, it will first search, for example, ET10
and use that value
if it is found. If ET10
isn't found and there are more than 9
ETAs
,
then it will also search for ETA10
. An error will be generated in case
mrgsolve finds both the ETA
and ET
name variant for the tenth and higher
ETA
(e.g. it is an error to have both ETA10
and ET10
in the data set).
When mrgsolve is searching for ETA
columns in the data set, it will
only look for ETAn
up to the number of rows (or columns) in all the
model $OMEGA
blocks. For example, if $OMEGA
is 5x5, only ETA1
through
ETA5
will be searched. An error will be generated in case mrgsolve finds
no columns with ETAn
names and something other than etasrc = "omega"
was passed. When etasrc = "data"
and an ETAn
column is missing from the
data set, the missing ETA()
will be set to 0
. Alternatively, the user
can pass etasrc = "data.all"
which causes an error to be generated if any
ETAn
is missing from the data set. Use this option when you intend to have
all ETAs
attached to the data set and want an error generated if mrgsolve
finds one or more of them is missing. Using etasrc ="idata"
or
"idata.all"
, the behavior is identical to "data"
(or "data.all"
),
except mrgsolve will look at the idata set rather than data set.
An object of class mrgsims.
mrgsim_variants, mrgsim_q()
## example("mrgsim")
e <- ev(amt = 1000)
mod <- mrgsolve::house()
out <- mod %>% ev(e) %>% mrgsim()
plot(out)
out <- mod %>% ev(e) %>% mrgsim(end=22)
out
data(exTheoph)
out <- mod %>% data_set(exTheoph) %>% mrgsim()
out
out <- mod %>% mrgsim(data=exTheoph)
out <- mrgsim(mod, data=exTheoph, obsonly=TRUE)
out
out <- mod %>% mrgsim(data=exTheoph, obsaug=TRUE, carry_out="a.u.g")
out
out <- mod %>% ev(e) %>% mrgsim(outvars="CP,RESP")
out
a <- ev(amt = 1000, group = 'a')
b <- ev(amt = 750, group = 'b')
data <- as_data_set(a,b)
out <- mrgsim_d(mod, data, recover="group")
out
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.