Work with event objects
Event objects are simple ways to implement PK dosing events into your model simulation.
Let’s illustrate event objects with a one-compartment, PK model. We read this model from the mrgsolve internal model library.
Events
Events are constructed with the ev function
This will implement 100 unit doses every 24 hours for a total of 7 doses. e has class ev, but really it is just a data frame
We can implement this series of doses by passing e in as the events argument to mrgsim
The events can also be implemented with the ev constructor along the simulation pipeline
Event expectations
amtis requiredevid=0is forbidden- Default 
timeis 0 - Default 
evidis 1 - Default 
cmtis 1 
Also by default, rate, ss and ii are 0.
Combine events
mrgsolve has operators defined that allow you to combine events. Let’s first define some event objects.
We can combine e1 and e3 with a collection operator
mrgsolve also defines a %then$ operator that lets you execute one event and %then% a second event
Notice that e3 has both ii and addl defined. This is required for mrgsolve to know when to start e2.
Combine to create a data set
We can take several event objects and combine them into a single simulation data frame with the as_data_set function.
When combined into a data set, we get * N=5 IDs receiving 100 mg Q24h x7 * N=3 IDs receiving 50 mg Q12h x 14 * N=2 IDs receiving 200 mg Q48h x 3
.    ID time cmt evid amt ii addl
. 1   1    0   1    1 100 24    6
. 2   2    0   1    1 100 24    6
. 3   3    0   1    1 100 24    6
. 4   4    0   1    1 100 24    6
. 5   5    0   1    1 100 24    6
. 6   6    0   1    1  50 12   13
. 7   7    0   1    1  50 12   13
. 8   8    0   1    1  50 12   13
. 9   9    0   1    1 200 24    2
. 10 10    0   1    1 200 24    2
To simulate from this data set, we use the data_set function. First, let’s load a population PK model


