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 = 1, ...)mrgsim_df(..., output = "df")
do_mrgsim(x, data, idata = no_idata_set(), carry_out = carry.out,
carry.out = character(0), seed = as.integer(NA),
Request = character(0), output = NULL, capture = NULL,
obsonly = FALSE, obsaug = FALSE, tgrid = NULL, recsort = 1,
deslist = list(), descol = character(0), filbak = TRUE,
tad = FALSE, nocb = TRUE, skip_init_calc = FALSE, ...)
the model object
NMTRAN-like data set (see data_set
)
a matrix or data frame of model parameters,
one parameter per row (see idata_set
)
an event object
integer number of individuals to simulate; only used if idata and data are missing
if NULL
(the default) a mrgsims object is returned;
otherwise, pass df
to return a data.frame or matrix
to
return a matrix
data items to copy into the output
soon to be deprecated; use carry_out
instead
deprecated
compartments or captured variables to retain
in the simulated output; this is different than the request
slot in the model object, which refers only to model compartments
character file name used for debugging (not related
to $CAPTURE
)
if TRUE
, dosing records are not included
in the output
augment the data set with time grid observations; when
TRUE
and a full data set is used, the simulated output is augmented
with an observation at each time in stime
(). When using
obsaug
, a flag indicating augmented observations can be requested by
including a.u.g
in carry_out
a tgrid object; or a numeric vector of simulation times
or another object with an stime
method
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 addl
after
observations at the same time; 1 and 3 put doses scheduled through
addl
before observations at the same time. recsort
will
not change the order of your input data set if both doses and observations
are given.
a list of tgrid objects
the name of a column for assigning designs
carry data items backward when the first data set row has time greater than zero
when TRUE
a column is added to simulated
output is added showing the time since the last dose. Only data records
with evid == 1
will be considered doses for the purposes of
tad
calculation. The tad
can be properly calculated with
a dosing lag time in the model as long as the dosing lag time (specified
in $MAIN
) is always appropriate for any subsequent doses scheduled
through addl
. This will always be true if the lag time doesn't
change over time. But it might (possibly) not hold if the lag time changes
prior to the last dose in the addl
sequence. This known limitation
shouldn't affect tad
calculation in most common dosing lag time
implementations.
if TRUE
, use next observation carry
backward method; otherwise, use locf
.
don't use $MAIN
to
calculate initial conditions
An object of class mrgsims
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
.
# NOT RUN {
## 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(req="CENT")
out
out <- mrgsim(mod, Req="CP,RESP", events = e)
out
# }
Run the code above in your browser using DataLab