Automated Approach to PK and PKPD Dataset Assembly
This repository contains several R functions to support the assembly of PK(PD) datasets to be used in NONMEM. The functions will create a PK(PD) dataset with consistent column names and covariate labels. Additional functions are used to support covariate analysis, combine datasets to form a population dataset, and create dataset definition files to support regulatory submissions.
The latest CRAN release can be installed with the following commands:
install.packages("apmx")
library(apmx)
The current development package can be downloaded from GitHub with the following commands:
devtools::install_github("stephen-amori/apmx")
library(apmx)
pk_build() creates a PK(PD) dataset for analysis in NONMEM from source data. The functions is not intended to produce datasets for NCA.
The function automatically maps CDISC terminology to a uniform variable name (apmx name) appropriate for pharmacometric analysis.
The function issues a variety of warnings and errors to inform the user of problematic subjects and records.
General comments:
ex and pc domain may accept standard CDISC attribute names or apmx names. apmx names are required for pd events.DTIM (the date/time of the record) must be in ISO-8601 format to be processed correctly. All date/times assumed to be UTC. Accepted forms:
STUDY must be provided in either the ex domain or sl.cov domain.impute parameter.
impute can be left empty, which will not impute times for any event missing DTIM.impute = 1 will set all actual time variables equal to the nominal time for events where DTIM is missing. This method is appropriate for pre-clinical analysis when actual times may not be collected.impute = 2 will estimate actual time variables relative to other events occurring that day for events where DTIM is missing. This method is appropriate for phase I-III analyses when individual events are missing a date/time.apmx attribute names and definitions:
USUBJID: unique subject ID (character or numeric)DTIM: date-time of the event (character)NDAY: nominal day of event, derived from protocol-defined visit (numeric)
TPT: nominal timepoint of event, derived from protocol-defined timepoint (numeric)VISIT: visit label (character)TPTC: timepoint label (character)ROUTE: dose route description (character)FRQ: dose frequency description (character)AMT: administered dose amount for dose events only (numeric)CMT: compartment assignemt for each event (numeric)DVID: dependent variable label (character)
DVIDU: dependent variable unit label (character)
ODV: original dependent variable (numeric)LLOQ: lower limit of quantification (numeric)STUDY: study label (character)apmx derived attribute names and definitions:
SUBJID: numeric form of USUBJID
ID: ID counting variableATFD: actual time since first doseATLD: actual time since last (most recent) doseNTFD: nominal time since first doseNTLC: nominal time since last cycleNTLD: nominal time since last (most recent) doseEVID: event ID (NONMEM-required)MDV: missing dependent variable (NONMEM-required)DVID: numeric mapping of input DVIDLDV: log-transformed dependent variableBDV: baseline dependent variable (for PD events only)DDV: delta from baseline dependent variable (for PD events only)PDV: percent change from baseline dependent variable (for PD events only)BLQ: flag for BLQ records
BLQ = 0 when observation is not BLQBLQ = 1 when observation is BLQ and prior to first doseBLQ = 2 when observation is BLQ and after first doseDOSEA: most recently administered dose amountDOMAIN: event domainDVIDC: character label for DVIDTIMEU: units for all time variablesFDOSE: date/time of first doseVERSN: apmx package version numberBUILD: date of dataset constructionCOMBD: date of dataset combination (generated from apmx::pk_combine() only)apmx derived binary flag names and definitions:
PDOSEF: records that occur prior to first doseTIMEF: records with no TIME informationAMTF: dose events with missing AMT
DUPF: duplicated events within the same ID-ATFD-EVID-CMT
NOEXF: subjects with no dose eventsNODVNF: subjects with no observations in compartment n (one flag per observation compartment)SDF: subjects who are single-dose (as opposed to multi-dose)PLBOF: records where the most recent dose is placeboSPARSEF: records associated with sparse sampling (as opposed to serial)TREXF: dose records that trail the final observation recordIMPEX: time of last (most recent) dose event was imputedIMPDV: time of observation event was imputedIMPFEX: time of first dose event was imputedC: comment flag to indicate a record will be ignored in the analysispk_combine() will combine two PK(PD) datasets built by pk_build() to form a population dataset.
All categorical covariates are re-calculated to ensure they are consistently labeled throughout the population analysis.
The function confirms the analytes and compartments are in agreement between both studies.
cov_find() will identify the columns in a PK(PD) dataset that belong to a certain covariate class.
Covariates can be "categorical", "continuous", "exposure", "empirical bayes estimate", or "other".
Types can be "numeric" or "character".
cov_apply() will add additional covariates to a PK(PD) dataset already built by pk_build().
It can apply covariates of any type, either subject-level or time-varying.
Covariates can be merged by any ID variable (USUBJID, SUBJID, or ID) or any time variable (ATFD, ATLD, NTFD, NTLC, NTLD, NDAY, TPT).
The same prefix and suffix system is applied to covariates built with cov_apply()
pk_write() will write out a PK(PD) dataset as a .csv file to the filepath of your choice in a NONMEM-ready format.
pk_define() will create a definition file for a PK(PD) dataset built by pk_build(). It can be produced as a data frame in R or exported as a Word document.
The function requres a dataset and a list of variable definitions. For more information on this list, refer to variable_list_create().
Other arguments:
file: filepath to a .docx file to specify the file name and location of exported Word documentproject: character string to specify project name. This name will appear in the header of the definition file if the template contains the word "Project" in the header.data: character string to specify dataset name. This name will appear in the header of the definition file if the template contains the word "Dataset" in the header.variable.list: data frame of variable definitions you wish to use. The variable list should have the following columns in this order:
template: optional filepath to template .docx document you wish to use. The definition table will append to the end of the document. If you leave the template blank, the definition table will read into a blank document, and project and data parameters will be ignored.pk_summarize() will create summary tables (BLQ, categorical covariates, and continuous covariates) of the dataset created by pk_build() or pk_combine().
Summary tables can be exported as .csv files, .docx files, and/or .pptx files. They can be stratified by any variable in the dataset. You can filter the dataset prior to summary statistics.
version_log() will create a version log of datasets created by pk_build() or pk_combine(). The first time you call the function, it will create an initial entry. You can export the version log as a Word document. Then, after you create a new, updated dataset, you can call the version_log() again. If you provide the filepath to the current version log, the new dataset, and the old dataset, the version log will add the new dataset and provide a brief summary comparison of the two.
variable_list_create() is a helper function for pk_define() that creates a standard variable list. The standard apmx variable names and definitions are already included. You can add your own variables (custom covariates, etc.) so they are included in the definition file.
In addition to bug fixes and runtime improvements, future functions will focus on the following areas:
Mildred Afoumbom
Joyceline Afumbom
Stephen Amori
Ethan DellaMaestra
Michael Dick
Ekiti Ekote
Daniel Litow
Jonah Lyon