See below.
The underlying simulations are run using rxode2
, and as such we need
an rxode2
system object. From that we can either simulate subjects or
load them from a file. Next we need to define a set of rules. These will
be a set of conditions and actions. At each evaluation time point the
conditions are evaluated. When a condition is met the actions associated
with that condition are executed. For example, if during a visit (an
evaluation time point) the trough PK is below a certain level
(condition) we may want to increase the dosing regimen for the next
dosing cycle (action).
Creating subjects
Subjects are expected in a data frame with the following column headers:
mk_subjects()
— Creates subjects for simulation by sampling based on
between-subject variability and generating covariate information based
on user specifications.
Covariates
The covs
input is a list with the following structure:
type: Can be either “fixed”, “discrete”, or “continuous”.
sampling: This field is only needed for a “continuous” covariate ’
type and can be either “random”, “normal” or “log-normal”.
values: This field depends on the type and optional sampling above.
fixed: A single value.
discrete: A vector of possible discrete elements.
continuous, random: Two values the first is the lower bound and the
second is the upper bound.
continuous, normal: Two values the first is the mean and the second
is the variance.
continuous, log-normal: Two values the first is the mean and the
second is the variance.
This examples shows the SEX_ID
randomly sampled from the values
specified, SUBTYPE_ID
fixed at a value, and WT
sampled from a
log-normal distribution.
covs = list(
SEX_ID = list(type = "discrete",
values = c(0,1)),
SUBTYPE_ID = list(type = "fixed",
values = c(0)),
WT = list(type = "continuous",
sampling = "log-normal",
values = c(70, .15))
)
Rule-based simulations
simulate_rules()
— This will run simulations based on the rule
definitions below.
Rules
Rules are a named list where the list name can be a short descriptive
label used to remember what the rule does. These names will be returned
as columns in the simulated data frame.
condition
: Character string that evaluates to either TRUE
or
FALSE
. When true the action
portion will be triggered. For a list
of objects available see the Rule-evaluation environment below.
fail_flag
: Flag set in the rule_id
column when the condition is
not met (set to "false"
if not specified).
true_flag
: Flag set in the rule_id
column when the condition is
met (set to "true"
if not specified).
action
: This is what the rule will trigger can be any of the
following:
Based on the type
the action
field will expect different elements.
Dosing:
action
type
: "dose"
values
: Character string that evaluates as a numeric vector dosing
amounts (e.g. "c(3, 3, 3, 3)"
)
times
: Character string that evaluates as a numeric vector of
times (e.g. "c(0, 14, 28, 42)"
)
durations
: Character string that evaluates as a numeric vector of
durations (e.g. "c(0, 0, 0, 0)"
, zero for bolus dosing)
Changing a state value:
action
type
: "set state"
state
: Character string with the name of the state to set ("Ac"
)
value
: Character string that evaluates as a numeric value for
state (e.g. "Ac/2"
would set the state to half the value of Ac at
the evaluation point)
Manual modification of the simulation:
Rule-evaluation environment
Beyond simple simulations it will be necessary to execute actions based
on the current or previous state of the system. For this reason, when a
condition
or elements of the action (e.g., the values
, times
and
durations
of a dose action type) are being evaluated, the following
objects will be available at each evaluation point:
outputs: The value of each model output.
states: The value of each named state or compartment.
covariates: The value of each named covariate.
subject-level parameters: The value of each named parameter.
rule value: The last value the rule evaluated as.
id
: Current subject id.
time
: Current evaluation time.
SI_SUB_HISTORY
: A data frame of the simulation history of the
current subject up to the current evaluation point.
SI_subjects
: The subjects data frame.
SI_eval_times
: Vector of the evaluation times.
SI_interval_ev
: The events table in it’s current state for the given
simulation interval.
SI_ev_history
: This is the history of the event table containing all
the events leading up to the current interval.
SI_ud_history
: This is a free form object the user can define or
alter within the “manual”action type (ud-user defined, history).
The following functions will be available:
SI_fpd(id=id, state="Ac")
Time scales
You can include columns in your output for different time scales if you
wish. You need to create a list in the format below. One element should
be system
with a short name for the system time scale. The next should
be details
which is a list containing short names for each time scale
you want to include. Each of these is a list with a verbose name for the
time scale (verb
) and a numerical conversion indicating how that time
scale relates to the others. Here we define weeks and days on the basis
of seconds.
time_scales = list(system="days",
details= list(
weeks = list(verb="Weeks", conv=1/(60*60*24*7)),
days = list(verb="Days", conv=1/(60*60*24))))