prepareInputData: Transformation of a NONMEM-readable dataset to a...

View source: R/InputData.R

prepareInputDataR Documentation

Transformation of a NONMEM-readable dataset to a Stan-readable list

Description

Prepares input data (a list) for the model-specific Stan code from a conventional PK/PD dataset for NONMEM (usually a table in .txt or .csv format).

Usage

prepareInputData(data.type = "population", data.source = NULL,
  data.file = NULL, model = NULL, inits = NULL, covar = NULL)

Arguments

data.type

a string to specify the type of the data ("population" or "individual").

data.source

the name of an R data frame that serves as the source data. If not provided, the next argument data.file will be checked to locate the data in the system.

data.file

a string to specify the path of the data file. It will be ignored if the previous argument data.source is already provided; but it will be required if data.source is not provided.

model

a PMXStanModel object that will be fitted to the current dataset.

inits

a string providing the colume name of initial values of the observed state variable for each individual in the current dataset, or a numerical vector of initial values for each individual.

covar

a string or a vector of strings providing colume name(s) of covariate(s) in the current dataset, which needs to be used either in model building or post-processing (e.g. goodness-of-fit plotting obs.vs.pred and rsd.vs.pred for a PMXStanFit object), or both.

Details

prepareInputData rewrites a table consisting of relevant columns according to NONMEM conventions to a list consisting of named vectors compatible to the auto-generated model-specific Stan code. It also allows users to specify column names for initial values of the observed state variable for an ODE system, and column names for relevant covariates that will be explored more through modeling or post-processing.

Currently, prepareInputData takes two different formats (.txt or .csv) of a NONMEM data file. The minimally required columns in this data file are: TIME, DV, AMT,and EVID. If data.type is set to "population", a column ID is also required. If the route of drug administration is set to "IV_infusion" (through argument route for PMXStanModel), a column RATE is also required.

For more details on the data structure of the returned list, please see Value section.

Value

The returned list contains four elements:

data.type

a string indicating the data type for future reference; the same as the argument data.type.

standata

a list by itself to be fed into the model-specific Stan code.

ID

a vector of IDs whose observations have been included in standata above. Note that a proof checking step has been performed to make sure that every subject included in Stan input data has both valid dosing and observation records; therefore, this set of ID's might be the same as those in the original data table, but it might also be a subset only. The purpose of this step is to avoid errors at the future sampling step due to lack of dosing records or observations.

d.cov

a data frame with columns of subject IDs and values for each selected covariates defined by the covar

A special consideration should be noted when handling data from a single subject, i.e. when data.type is set to "individual". Due to the strict requirement with data type specification in Stan grammar and the underlying mechanisms how C++ handles different data types, to avoid the comlexity caused by data from a single subject, a "dummy" subject has been attached in these cases, with a single dose of 0 and the initial observation set the same as the real subject.

Author(s)

Yuan Xiong and Wenping Wang

See Also

list for general information on R lists; PMXStanModel for the initialization of a PMXStanModel object; PMXStanFit for the generation of a PMXStanFit object, running a model-specific Stan executable and linking to an input data list to generate posterior samples of parameters.

Examples

m <- PMXStanModel(path = tempfile("pk_m1"))
data("examples_data")
dat <- prepareInputData(data.source = d1_nm_poppk, model = m)
str(dat)

stanette documentation built on May 11, 2022, 5:11 p.m.