R: Select and modify a data set for simulation

data_set {mrgsolve} | R Documentation

## Select and modify a data set for simulation

### Description

The input data set (`data_set`) is a data frame that specifies observations, model events, and / or parameter values for a population of individuals.

### Usage

    data_set(x, data, ...)

    ## S4 method for signature 'mrgmod,data.frame'
    data_set(
      x,
      data,
      .subset = TRUE,
      .select = TRUE,
      object = NULL,
      need = NULL,
      ...
    )

    ## S4 method for signature 'mrgmod,ANY'
    data_set(x, data, ...)

    ## S4 method for signature 'mrgmod,ev'
    data_set(x, data, ...)

    ## S4 method for signature 'mrgmod,missing'
    data_set(x, object, ...)

### Arguments

`x` | model object
`data` | data set
`...` | passed along
`.subset` | an unquoted expression passed to `dplyr::filter`; retain only certain rows in the data set
`.select` | passed to `dplyr::select`; retain only certain columns in the data set; this should be the result of a call to `dplyr::vars()`
`object` | character name of an object existing in `$ENV` to use for the data set
`need` | passed to `inventory`

### Details

Input data sets are `R` data frames that can include columns with any valid name, however columns with selected names are treated specially by `mrgsolve` and incorporated into the simulation.

`ID` specifies the subject ID and is required for every input data set.

When columns have the same name as parameters (`$PARAM` in the model specification file), the values in those columns will be used to update the corresponding parameter as the simulation progresses.

Input data set may include the following columns related to PK dosing events: `time`, `cmt`, `amt`, `rate`, `ii`, `addl`, `ss`. Along with `ID`, `time` is a required column in the input data set unless `$PRED` is in use. Upper case PK dosing column names including `TIME`, `CMT`, `AMT`, `RATE`, `II`, `ADDL`, `SS` are also recognized. However, an error will be generated if a mix of upper case and lower case columns in this family are found.

`time` is the observation or event time, `cmt` is the compartment number (see `init`), `amt` is the dosing amount, `rate` is the infusion rate, `ii` is the dosing interval, `addl` specifies additional doses to administer, and `ss` is a flag for steady state dosing. These column names operate similarly to other non-linear mixed effects modeling software.

An error will be generated when mrgsolve detects that the data set is not sorted by `time` within an individual.

Only numeric data can be brought in to the problem. Any non-numeric data columns will be dropped with warning. See `numerics_only`, which is used to prepare the data set.

An error will be generated if any parameter columns in the input data set contain `NA`. Likewise, and error will be generated if missing values are found in the following columns: `ID`, `time`/`TIME`, `rate`/`RATE`.

See `exdatasets` for different example data sets.

### See Also

`idata_set`, `ev`, `valid_data_set`, `valid_idata_set`

### Examples

    mod <- mrgsolve::house()

    data <- expand.ev(ID=seq(3), amt=c(10, 20))

    mod %>% data_set(data, ID > 1) %>% mrgsim()

    data(extran1)
    head(extran1)

    mod %>% data_set(extran1) %>% mrgsim()
    mod %>% mrgsim(data = extran1)

[Package mrgsolve version 1.0.0 Index]