Type: | Package |
Title: | Automated Population Pharmacokinetic Dataset Assembly |
Version: | 1.1.1 |
Date: | 2024-01-05 |
Maintainer: | Stephen Amori <stephen.amori@amadorbio.com> |
Description: | Automated methods to assemble population PK (pharmacokinetic) and PKPD (pharmacodynamic) datasets for analysis in 'NONMEM' (non-linear mixed effects modeling) by Bauer (2019) <doi:10.1002/psp4.12404>. The package includes functions to build datasets from SDTM (study data tabulation module) https://www.cdisc.org/standards/foundational/sdtm, ADaM (analysis dataset module) https://www.cdisc.org/standards/foundational/adam, or other dataset formats. The package will combine population datasets, add covariates, and create documentation to support regulatory submission and internal communication. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
LazyData: | true |
Imports: | dplyr, tidyr, purrr, this.path, flextable, officer, tidyselect, utils, arsenal |
RoxygenNote: | 7.2.3 |
URL: | https://github.com/stephen-amori/apmx |
BugReports: | https://github.com/stephen-amori/apmx/issues |
Depends: | R (≥ 4.00) |
Suggests: | rmarkdown, knitr, testthat, tibble |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2024-01-05 20:40:33 UTC; Stephen.Amori |
Author: | Stephen Amori [aut, cre, cph], Ethan DellaMaestra [aut], Michael Dick [aut], Daniel Litow [ctb], Jonah Lyon [ctb] |
Repository: | CRAN |
Date/Publication: | 2024-01-09 09:00:18 UTC |
DM
Description
Randomly generated demographic data domain
Usage
DM
Format
## 'DM' A data frame with 22 rows and 12 variables:
- STUDYID
study label
- SITEID
site code
- SUBJID
subject code
- USUBJID
unique subject ID
- SCRFL
screen fail flag
- ICFDT
informed consent date
- ICFDTC
informed consent date character form
- DOBDT
date of birth
- AGE
subject baseline age
- SEX
subject sex
- RACE
subject race
- ETHNIC
subject ethnicity
EX
Description
Randomly generated exposure domain
Usage
EX
Format
## 'EX' A data frame with 42 rows and 19 variables:
- STUDYID
study label
- SITEID
site code
- USUBJID
unique subject ID
- EXCAT
domain category
- VISIT
visit label
- EXSTDY
numeric study day
- VISCRFN
visit numeric code
- EXTRT
treatment label
- EXDOSE
treatment amount
- EXDOSU
treatment unit label
- EXROUTE
treatment route label
- EXDOSFRQ
treatment frequency
- EXDT
treatment administration date
- EXDTC
treatment administration date character form
- EXTM
treatment administration time
- EXTMC
treatment administration time character form
- EXSTDTC
treatment administration date and time
- EXTPT
treatment timepoint label
- EXTPTNUM
treatment numeric timepoint
LB
Description
Randomly generated laboratory data domain
Usage
LB
Format
## 'LB' A data frame with 2159 rows and 16 variables:
- STUDYID
study label
- SITEID
site code
- USUBJID
unique subject ID
- LBCAT
domain category
- LBCOMPFL
completion flag
- LBDT
date of assessment
- LBVST
visit label
- VISCRFN
visit numeric code
- LBTPT
timepoint label
- LBTPTN
timepoint numeric code
- LBPARAMCD
parameter code
- LBPARAM
parameter
- LBORRES
original parameter result
- LBORRESC
original parameter result, character form
- LBORRESU
original parameter unit label
PC
Description
Randomly generated pharmacokinetic observation domain
Usage
PC
Format
## 'PC' A data frame with 420 rows and 19 variables:
- STUDYID
study label
- SITEID
site code
- USUBJID
unique subject ID
- PCCAT
domain category
- PCTEST
analyte category
- VISIT
visit label
- PCDY
study numeric day
- VISCRFN
visit numeric code
- PCTPT
timepoint label
- PCTPTN
timepoint numeric code
- PCSTAT
completion status
- PCDT
observation date
- PCTM
observation time
- PCTMC
observation time character form
- PCDTC
observation date and time
- PCORRES
original pharmacokinetic observation
- PCORRESU
original pharmacokinetic observation unit label
- PCSTRESN
standardized pharmacokinetic numeric observation
- PCSTRESC
standardized pharmacokinetic character observation
- PCSTRESU
standardized pharmacokinetic observation unit label
- PCLLOQ
standardized pharmacokinetic observation lower limit of quantification
VL
Description
Variable list with apmx variables and definitions
Usage
VL
Format
## 'VL' A data frame with 66 rows and 4 variables:
- Variable
Column or variable name
- Categorization
Column or variable category
- Description
Column or variable description
- Comment
NA by default
Apply covariates to PK(PD) dataset
Description
Add covariates to a dataset built by pk_build() or pk_combine() Can add subject-level covariates (by any ID variable) or time-varying (by any time variable)
Usage
cov_apply(
df,
cov,
id.by = "USUBJID",
time.by = NA,
direction = "downup",
exp = FALSE,
ebe = FALSE,
cov.rnd = NA,
na = -999,
demo.map = TRUE,
keep.other = TRUE
)
Arguments
df |
PK(PD) dataframe generated by pk_build |
cov |
dataframe of covariates |
id.by |
id variable to merge covariates |
time.by |
time variable to merge covariates |
direction |
fill direction for time-varying covariates |
exp |
treats new covariates as exposure metrics when TRUE |
ebe |
treats new covariates as empirical bayes estimates when TRUE |
cov.rnd |
covariate rounding parameter |
na |
value to replace NA numeric covariates |
demo.map |
toggle pre-set numeric values for SEX, RACE, and ETHNIC demographic variables |
keep.other |
filter to keep or remove other events, EVID = 2 |
Value
PK(PD) dataset with additional covariates]
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df <- pk_build(ex, pc)
## Simple dm domain for the corresponding study
dm <- data.frame(USUBJID = c("ABC101-001",
"ABC101-002",
"ABC101-003"),
AGE = c(45,
37,
73),
AGEU = "years",
SEX = c("Male",
"Female",
"Male"),
RACE = c("White",
"White",
"Black"),
ETHNIC = c("Not Hispanic/Latino",
"Not Hispanic/Latino",
"Not Hispanic/Latino"))
## Add covariates with cov_apply()
df1 <- cov_apply(df, dm)
Find covariates of particular types
Description
Can filter for categorical, continuous, or other covariates. Can filter for numeric or character type.
Usage
cov_find(df, cov, type)
Arguments
df |
PK(PD) dataset |
cov |
covariate distribution |
type |
covariate type |
Value
vector of desired column names
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df <- pk_build(ex, pc)
## Simple dm domain for the corresponding study
dm <- data.frame(USUBJID = c("ABC101-001",
"ABC101-002",
"ABC101-003"),
AGE = c(45,
37,
73),
AGEU = "years",
SEX = c("Male",
"Female",
"Male"),
RACE = c("White",
"White",
"Black"),
ETHNIC = c("Not Hispanic/Latino",
"Not Hispanic/Latino",
"Not Hispanic/Latino"))
## Add covariates with cov_apply()
df1 <- cov_apply(df, dm)
## Find covariates with cov_find()
cov_find(df1, cov="categorical", type="numeric")
cov_find(df1, cov="categorical", type="character")
cov_find(df1, cov="continuous", type="numeric")
cov_find(df1, cov="units", type="character")
Create a NONMEM PK(PD) dataset
Description
Input a pre-processed ex and pc domain for combination into a NONMEM dataset. Additional pd endpoints, subject-level covariates, and time-varying covariates can also be added. Other parameters can customize some calculations and formatting.
Usage
pk_build(
ex,
pc = NA,
pd = NA,
sl.cov = NA,
tv.cov = NA,
time.units = "days",
cycle.length = NA,
na = -999,
time.rnd = NULL,
amt.rnd = NULL,
dv.rnd = NULL,
cov.rnd = NULL,
impute = NA,
BDV = FALSE,
DDV = FALSE,
PDV = FALSE,
sparse = 3,
demo.map = TRUE,
tv.cov.fill = "downup",
keep.other = TRUE
)
Arguments
ex |
dose event dataframe |
pc |
pc event dataframe |
pd |
pd event dataframe |
sl.cov |
subject-level covariate dataframe |
tv.cov |
time-varying covariate dataframe |
time.units |
units for time attributes |
cycle.length |
cycle length in units of days |
na |
value for missing numeric items |
time.rnd |
time attribute rounding parameter |
amt.rnd |
amount attribute rounding parameter |
dv.rnd |
dependent variable attribute rounding parameter |
cov.rnd |
covariate attribute rounding parameter |
impute |
imputation method |
BDV |
baseline pd attribute |
DDV |
change from baseline pd attribute |
PDV |
percent change from baseline pd attribute |
sparse |
threshold for sparse sampling |
demo.map |
toggle pre-set numeric values for SEX, RACE, and ETHNIC demographic variables |
tv.cov.fill |
time-varying covariate fill direction |
keep.other |
filter to keep or remove other events, EVID = 2 |
Value
PK(PD) dataset
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df <- pk_build(ex, pc)
combine study level datasets to form population dataset
Description
Input two datasets created by pk_build(). Any character descriptions that were numerically mapped will be re-mapped to the whole population.
Usage
pk_combine(df1, df2, demo.map = TRUE, na = -999)
Arguments
df1 |
original PK(PD) dataset |
df2 |
additional PK(PD) dataset |
demo.map |
toggle pre-set numeric values for SEX, RACE, and ETHNIC demographic variables |
na |
value for missing numeric items |
Value
population PK(PD) dataset
Examples
## Simple ex domain with 1 subject and 1 dose, study 101
ex101 <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple ex domain with 1 subject and 1 dose, study 102
ex102 <- data.frame(STUDYID = "ABC102",
USUBJID = "ABC102-001",
EXSTDTC = "2001-01-01 08:09:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 200,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "QW",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations, study 101
pc101 <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Simple pc domain with 1 subject and 3 observations, study 102
pc102 <- data.frame(USUBJID = "ABC102-001",
PCDTC = c("2001-01-01 08:05:00",
"2001-01-01 11:38:00",
"2001-01-02 08:11:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.125,
1),
PCSTRESN = c(NA,
1150,
591),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"2-4 hr post-dose",
"24 hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df101 <- pk_build(ex101, pc101)
df102 <- pk_build(ex102, pc102)
## Combine with pk_combine()
df_combine <- pk_combine(df101, df102)
Create definition file from published dataset
Description
Definition file table can be read into a template word document (.docx) or blank document if desired. Definitions are sourced from a variable list stored separately on your server. Please refer to apmx::variable_list_export() for a standard copy of the variable list.
Usage
pk_define(
df,
file = NULL,
project,
data,
variable.list,
template = NULL,
font = "Times New Roman",
size = 9,
na = -999
)
Arguments
df |
apmx analysis dataset |
file |
optional filepath for defintion file (.docx file) |
project |
project name |
data |
dataset name |
variable.list |
reference dataframe for variable definitions |
template |
optional filepath for definition file template (.docx file) |
font |
font for table contents |
size |
font size for table contents |
na |
value used for missing or na numeric covariates |
Value
dataset definition file
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create apmx dataset with pk_build()
df <- pk_build(ex, pc)
## Create variable definitions with variable_list_create()
vl <- variable_list_create()
## Create definition file
pk_define(df, variable.list = vl)
Produce summary tables for a PK(PD) dataset
Description
Summarize BLQ distributions, categorical covariates, and continuous covariates in three tables. Outputs are default .csv files, but can also be .docx and/or .pptx Tables are default stratified by study, but can be stratified by any variable requested by the user.
Usage
pk_summarize(
df,
dir = NA,
strat.by = "NSTUDYC",
ignore.c = TRUE,
na = -999,
docx = FALSE,
pptx = FALSE,
docx.font = "Times New Roman",
docx.size = 9,
docx.template = NULL,
pptx.template = NULL,
pptx.font = "Times New Roman",
pptx.size = 12,
docx.orientation = "portrait",
ignore.request = c()
)
Arguments
df |
dataset produced by pk_build(). |
dir |
filepath for output directory. |
strat.by |
vector of variables names to stratify the summary tables. |
ignore.c |
ignores records flagged in the C column when TRUE. |
na |
numeric value to be interpreted as NA or missing. |
docx |
creates summary tables as a Word document when TRUE. |
pptx |
creates summary tables as a PowerPoint document when TRUE. |
docx.font |
font for the summary tables in the Word document. |
docx.size |
font size for the summary tables in the Word document. |
docx.template |
filepath for template .docx file. When NULL, the summary tables print to a blank document. |
pptx.template |
filepath for template .pptx file. When NULL, the summary tables print to a blank slide. |
pptx.font |
font for the summary tables in the PowerPoint document. |
pptx.size |
font size for the summary tables in the PowerPoint document. |
docx.orientation |
orientation of .docx files. |
ignore.request |
vector of additional logical expressions to filter the datase prior to summary. |
Value
summary tables as .csv, .docx, and .pptx files
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df <- pk_build(ex, pc)
## Generate summary statistics with pk_summarize()
pk_summarize(df)
Write PK(PD) dataset to specified location
Description
Dataset created by pk_build() or pk_combine() will be outputted as a .csv file with NONMEM-standard formatting.
Usage
pk_write(df, file)
Arguments
df |
PK(PD) dataframe |
file |
filepath |
Value
writes dataset to specified location
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df <- pk_build(ex, pc)
## Write with pk_write()
name <- "dataset.csv"
pk_write(df, file.path(tempdir(), name))
Create a dataframe with standard variable names and definitions
Description
Variable list should be used as an input to the apmx::pk_define() function. The user should add additional definitions to the file for custom columns with apmx::variable_list_add().
Usage
variable_list_create(
variable = NULL,
categorization = NULL,
description = NULL,
comment = NA
)
Arguments
variable |
vector of variable names |
categorization |
vector of category names |
description |
vector of variable descriptions |
comment |
vector of variable comments (can be left NA) |
Value
dataframe of standard variable definitions
Examples
vl <- variable_list_create(variable = c("WEIGHT", "HEIGHT"),
categorization = rep("Covariate", 2),
description = c("weight", "height"))
Create and maintain a dataset version log
Description
Version log is outputted as a .docx file. Document tracks changes in subject count, record count, new variables, and changing variables. User comments in the word document are preserved between versions.
Usage
version_log(
df,
name,
file = NULL,
prevdata = NULL,
template = NULL,
comp_var,
src_data = "",
font = "Times New Roman",
size = 9,
orient = "landscape"
)
Arguments
df |
filepath of new dataset |
name |
name of the dataset (filename with .csv suffix) |
file |
filepath for version log file (.docx) |
prevdata |
comparison dataset filepath |
template |
template docx filepath |
comp_var |
grouping variables for comparison |
src_data |
string to describe source data |
font |
font style |
size |
font size |
orient |
document orientation |
Value
version log as a .docx file
Examples
## Simple ex domain with 1 subject and 1 dose
ex <- data.frame(STUDYID = "ABC101",
USUBJID = "ABC101-001",
EXSTDTC = "2000-01-01 10:00:00",
EXSTDY = 1,
EXTPTNUM = 0,
EXDOSE = 100,
CMT = 1,
EXTRT = "ABC",
EXDOSU = "mg",
VISIT = "Day 1",
EXTPT = "Dose",
EXDOSFRQ = "Once",
EXROUTE = "Oral")
## Simple pc domain with 1 subject and 3 observations
pc <- data.frame(USUBJID = "ABC101-001",
PCDTC = c("2000-01-01 09:40:00",
"2000-01-01 10:29:00",
"2000-01-01 12:05:00"),
PCDY = 1,
PCTPTNUM = c(0, ##Units of hours
0.021,
0.083),
PCSTRESN = c(NA,
469,
870),
PCLLOQ = 25,
CMT = 2,
VISIT = "Day 1",
PCTPT = c("Pre-dose",
"30-min post-dose",
"2-hr post-dose"),
PCTEST = "ABC",
PCSTRESU = "ug/mL")
## Create with pk_build()
df <- pk_build(ex, pc)
## Document with version_log()
vlog <- version_log(df, name = "PK_DATA_V01.csv")