Learn R Programming

mapbayr (version 0.10.2)

adm_rows: Add administration lines to a dataset

Description

The adm_rows() function adds an one or several administration lines to a dataset provided as a proper data.frame or within a 'mrgsolve' model. Used in combination with obs_rows() and add_covariates(), it helps the creation of datasets in the proper format for simulations with 'mrgsolve' or parameter estimation with 'mapbayr', as explained in data_helpers.

Usage

adm_rows(x, ...)

# S3 method for data.frame adm_rows( x, ID = NULL, time = NULL, evid = 1L, cmt, amt, mdv = 1L, addl = NULL, ss = NULL, ii = NULL, rate = NULL, .datehour = NULL, ... )

# S3 method for missing adm_rows(...)

# S3 method for mrgmod adm_rows(x, cmt = adm_cmt(x), rate = NULL, ...)

Value

a data.frame, or a 'mrgsolve' model with a dataset in the @args$data slot (accessible with get_data()).

Arguments

x

either a data.frame or a 'mrgsolve' model object

...

additional columns or arguments for mrgsolve::ev()

ID

subject ID (default is 1)

time

event time. Default is 0 if no previous events. Mind consistency with .datehour.

evid

event identification (default is 1 for administration, 0 for observation)

cmt

compartment (no default, except if [ADM] was tagged in the $CMT block in model code. See examples.)

amt

dose amount (for administration records only)

mdv

missing dependent value (default is 1 for administration records)

addl

additional dose (optional)

ss

steady-state (optional, is this dose the last of an infinity of administration? Yes, 1, or no, 0)

ii

inter-dose interval (optional, use it with ss and addl)

rate

rate of administration (optional, set to -2 if you model zero-order infusion. See examples.)

.datehour

a object of class POSIXct, a number or a character vector that can be passed to parse_datehour(). Using .datehour will update the value of time in the dataset, with units in hours. Mind consistency with the time argument.

See Also

data_helpers

Examples

Run this code
# Create a dataset from scratch
adm_rows(amt = 100, cmt = 1)

# Pipe-friendly addition of administration record to a pre-existing dataset
library(magrittr)
adm_rows(amt = 100, cmt = 1) %>%
  adm_rows(time = 3, amt = 200, cmt = 1, addl = 3, ii = 1)

# Inform times using the `.datehour` argument:
adm_rows(.datehour = "2020-01-01 11:11", amt = 100, cmt = 1) %>%
  adm_rows(.datehour = "2020-01-02 22:22", amt = 200, cmt = 1) %>%
  adm_rows(time = 48, amt = 300, cmt = 1)

# Start from a 'mrgsolve' model
library(mrgsolve)
house() %>%
  adm_rows(amt = 100, cmt = 1) %>%
  adm_rows(time = 3, amt = 200, cmt = 1, addl = 3, ii = 1) %>%
  mrgsim(delta = 1)

# Default administration compartments
# Set default administration compartments in the code with `[ADM]`
model <- mcode("model", "
$CMT @annotated
DEPOT : Depot [ADM]
CENTR : Central
", compile = FALSE)
adm_cmt(model)

# Thus, no need to manually specify `cmt = 1` anymore.
model %>%
  adm_rows(amt = 100) %>%
  adm_rows(time = 3, amt = 200, addl = 3, ii = 1) %>%
  get_data()

# Automatic lines duplication if multiple depot compartments
# Automatic `rate = -2` increment if model with 0-order absorption
model <- mcode("model", "
$PARAM DUR = 1.0
$CMT @annotated
DEPOT : Depot [ADM]
CENTR : Central [ADM]
$MAIN
D_CENTR = DUR ;
", compile = FALSE)
adm_cmt(model)

model %>%
  adm_rows(amt = 100) %>%
  adm_rows(time = 3, amt = 200, addl = 3, ii = 1) %>%
  get_data()

Run the code above in your browser using DataLab