Learn R Programming

mrgsolve (version 0.8.9)

mrgsim: Simulate from a model object.

Description

This function sets up the simulation run from data stored in the model object as well as arguments passed in. Note that there are many non-formal arguments to this function that can be used to customize the simulation run and it's output.

Usage

mrgsim(x, data = NULL, idata = NULL, nid = 1, ...)

Value

an object of class mrgsims

Additional arguments

  • mtime numeric vector of times where the model is evaluated (with solver reset), but results are not included in simulated output

  • Request a vector of compartment or table names to take in simulated output; if this is specified, request is ignored

  • obsonly omit records with evid != 0 from simulated output

  • obsaug logical; 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

  • recsort 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.

  • filbak For each ID, carry the first record data backward to start of the simulation

  • tad logical; 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.

Details

  • Both data and idata will be coreced 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 invidivual'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.

Examples

Run this code
# NOT RUN {
## example("mrgsim")

mod <- mrgsolve:::house() %>%  ev(amt=1000, cmt=1)
out <- mod %>% mrgsim()
plot(out)

out <- mod %>% 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 %>% mrgsim(req="CENT")
out

out <- mrgsim(mod, Req="CP,RESP")
out



# }

Run the code above in your browser using DataLab