Input data sets are used in mrgsolve to allow the user to specify interventions and input data items.
Please see the mrgsolve help topic ?exdatasets for examples of all of the data sets discussed in this chapter. The example data sets are embedded in the mrgsolve package and may be used at any time.
4.1 Overview
Data sets are the primary mechanism for establishing the scope of your simulations in mrsolve, including individuals, interventions, observation times, and parameter values. For both data_set and idata_set (see below), you may include columns in the data sets that have the same names as the parameters in your model (Section 1.1, Section 2.2.4). mrgsolve can recognize these columns and update the parameter list as the simulation proceeds. This process is of key importance when planning and executing complex simulations and is further discussed in section Section 12.3.
4.2 Event data sets (data)
Event data sets are entered as data.frame, with one event per row. Events may be observations, doses, or other type events. In mrgsolve documentation, we refer to these data sets as data or data_set (after the function that is used to associate the data set with the model object prior to simulation).
Event data sets have several special column names that mrgsolve is always aware of:
ID the subject id. This id does not need to be unique in the data_set: mrgsolve detects an new individual when the current value of ID is different from the immediate preceding value of ID. However, we always recommend using unique ID.
time or TIME: states the time of the data record
evid or EVID: the event id indicator. evid can take the values:
0 = observation record
1 = dosing event (bolus or infusion)
2 = other type event, with solver stop and restart
3 = system reset
4 = reset and dose
8 = replace the amount in the compartment with amt
amt or AMT: the dose amount (if evid==1)
cmt or CMT: the dosing compartment number. This may also be a character value naming the compartment name. The compartment number must be consistent with the number of compartments in the model for dosing records (evid==1).
For observation records, a cmt value of 0 is acceptable. Use a negative compartment number with evid 2 to turn a compartment off.
rate or RATE: if non-zero and evid=1 or evid=4, implements a zero-order infusion of duration F_CMT*amt/rate, where F_CMT is the bioavailability fraction for the dosing compartment. Use rate = -1 to model the infusion rate and rate = -2 to model the infusion duration, both in $MAIN (see Section 2.2.8, Section 2.3.32, Section 2.3.34, Section 2.3.36).
ii or II: inter-dose interval; ii=24 means daily dosing when the model time unit is hours
addl or ADDL: additional doses; a non-zero value in addl requires non-zero ii on the same record
ss or SS steady state indicator; use 1 to implement steady-state dosing; 0 otherwise. mrgsolve also recognizes dosing records where ss=2. This allows combination of different steady state dosing regimens under linear kinetics (e.g. 10 mg QAM and 20 mg QPM daily to steady state).
The column names in the preceding list were written either as lower case form (e.g. amt) or upper case form (e.g. AMT). Either may be used, however the data set will be checked for consistency of usage. An error will be issued in case a mixture of lower and upper case names are found.
In addition to these special column names, mrgsolve will recognize columns in data_set that have the same name as items in the parameter list (see Section 2.2.4 and Section 1.1). When mrgsolve sees that the names match up, it will update the values of those matching names based on what it finds as it moves through the data set (see Section 12.3).
4.2.1 Two types of data_set
mrgsolve distinguishes between two types of data sets: data sets that have at least one observation record (evid=0) and data sets that have no records with evid=0.
Full data sets have a mix of observations and dosing events (likely, but not required). When mrgsolve finds one record with evid=0, it assumes that ALL output observation times are to come from the data set. In this case the simulation output time grid discussed in Section 1.3 is ignored and only observations found in the data set appear in the simulated output. Use full data sets when you want a highly customized sampling schedule or you are working with a clinical data set.
Condensed data sets have no records with evid=0. In this case, mrgsolve will fill the simulated output with observations at times specified by the output time grid (Section 1.3 and see Section 12.5 too). These are very convenient to use because there is less data assembly burden and output data sets can easily be created with very dense sampling scheme or highly customized sampling schemes with very little work. Use a condensed data set when you want a uniform set of sampling times for all subjects in the data set.
See ?exdatasets in the R help system after loading mrgsolve.
Augmenting observations in a clinical data set Occasionally, we want to simulate from a clinical data set (with observation records as actually observed in a population of patients) but we also want to augment those observations with a regular sequence of times (for example, to make a smooth profile on a plot). In that case, you can set obsaug = TRUE when calling mrgsim.
For example:
mod <-house()out <- mod %>%data_set(exTheoph, ID==1) %>%carry.out(a.u.g) %>% obsaug %>%mrgsim(end =24, delta =1)out
obsaug requests that the data set be augmented with observations from the simulation time grid. We can optionally request an indicator called a.u.g to appear in the output that takes value of 1 for augmented observations and 0 for observations from the data set.
4.2.2 Sorting requirements
The IDs in the data set can appear in any order. However, an error will be generated if time on any record is less that time on the previous record within any ID.
4.2.3 Creating data sets
There are several convenience functions provided to help you create data set inputs for your simulation.
4.2.3.1expand.ev()
The expand.ev function will create a data set with all combinations of your inputs. For example, to create a data set of 3 people receiving 250 mg and 3 individuals receiving 500 mg, with each dose administered every 8 hours for 12 total doses
data <-expand.ev(ID =1:3, amt =c(250, 500), ii =8, addl =11)data
Individual data sets carry individual-level data. This individual data is used in several different ways:
Individual-level parameters: Just prior to simulating any individual, mrgsolve checks the appropriate row in idata (if supplied) for any columns with parameter names. If parameter names are found, the parameter list is updated and that update remains in effect for the duration of that individual’s data records.
Individual- or group-level designs: Each individual or group of individual may be assigned a different sampling design. For example, individuals in arm 1 may need to be simulated for 4 weeks whereas individuals in arm 2 may need to be simulated for 8 weeks. idata may be used to identify one of several sampling designs for each individual or group of individuals.
Individual-level compartment initialization: if a model has a compartment called CMT and mrgsolve finds a column in idata called CMT_0, the value of CMT_0 will be used to initialize that compartment with, potentially a different value for each individual. Note that there are several other ways to initialize compartments detailed in Section 12.2.
idata_set are entered as data.frame with one unique ID per row. In mrgsolve documentation, we refer to individual data sets idata or idata_set to distinguish them from event data sets (see Section 4.2).
Here we have an idata_set with 10 subjects, one subject per row. The ID column connects the data in each row to the data in a data_set, which also requires an ID column.
The ID column is the only required column name in idata_set and ID should always be a unique identifier for that row.
4.3.1 Use case
idata_set is usually helpful for implementing a batch of simulations when a data_set is not used. The batch may be as a sensitivity analysis or for population simulation. Usually, an events object is used with idata, but it is not required.
Use the idata_set function to pass the data set into the problem.
For example:
mod <-house()mod %>%idata_set(exidata) %>%ev(amt =100) %>%mrgsim() %>%plot()
Because there were 10 subjects in the idata_set, we get 10 profiles in the output. Each “individual” or “unit” received the same 100 mg dose. We would use a data_set to assign different doses to different individuals.
4.4 Numeric data only
The data.frame holding the data_set or idata_set may have any type of data in its columns. However, only numeric data can actually get passed into the simulation engine. mrgsolve will automatically look for non-numeric columns and drop them from the data_set or idata_set with a warning.
4.5 Missing values
If missing values (NA) are found in columns which match parameter names, a warning will be issued and the user should expect NaN in the simulated output if these parameters factor into the advance of the system.
Starting with version 1.0.8, missing values in the following columns of input data_sets will be silently converted to 0
CMT
AMT
RATE
EVID
II
ADDL
SS
The lower case versions of these names may also include NA and will get converted to 0
cmt
amt
rate
evid
ii
addl
ss
idata_sets are not checked for missing values in these columns.
4.6 Data set validation
A the time of simulation, mrgsolve will validate the input data set, removing non-numeric columns, checking for missing values in parameter columns, checking compartment numbers, etc.
Users can pre-validate the data set so that this does not need to happen at run time.
This can improve efficiency when performing a very large number of replicate simulations on the same data set, but is unlikely to provide a meaningful speed-up for a single simulation or a small number of simulations.
4.7 Data sets for use with $PRED
Because there are no compartments involved, there are relaxed data set requirements for models that utilize $PRED.
time or TIME is not required as input; when this is not supplied, a time column will be included in output with value 0
When time or TIME is supplied, it may be negative; but records must still be sorted by time or TIME