diff --git a/adam/ader.R b/adam/ader.R new file mode 100644 index 00000000..9617966c --- /dev/null +++ b/adam/ader.R @@ -0,0 +1,290 @@ +## ----r echo=TRUE, message=FALSE----------------------------------------------- +# Load Packages +library(admiral) +library(admiralonco) +# pharmaverseadam contains example datasets generated from the CDISC pilot +# project SDTM ran through admiral templates +library(pharmaverseadam) +library(dplyr) +library(lubridate) +library(stringr) +library(metacore) +library(metatools) +library(xportr) + +## ----r echo=TRUE, message=FALSE----------------------------------------------- +# ---- Load Specs for Metacore ---- +metacore <- spec_to_metacore("./metadata/pk_spec.xlsx") %>% + select_dataset("ADER") + +## ----r------------------------------------------------------------------------ +# ---- Load source datasets ---- +# Load ADRS, ADTTE, ADSL, ADLB, ADVS, ADEX, ADPP and ADAE +adrs <- pharmaverseadam::adrs_onco +adtte <- pharmaverseadam::adtte_onco +adsl <- pharmaverseadam::adsl +adlb <- pharmaverseadam::adlb +advs <- pharmaverseadam::advs +adex <- pharmaverseadam::adex %>% + filter(PARCAT1 == "INDIVIDUAL") +adpp <- pharmaverseadam::adpp +adae <- pharmaverseadam::adae + +## ----r------------------------------------------------------------------------ +# ---- Derive Covariates ---- +# Include numeric values for STUDYIDN, USUBJIDN, SEXN, RACEN etc. + +covar <- adsl %>% + create_var_from_codelist(metacore, input_var = STUDYID, out_var = STUDYIDN) %>% + create_var_from_codelist(metacore, input_var = SEX, out_var = SEXN) %>% + create_var_from_codelist(metacore, input_var = RACE, out_var = RACEN) %>% + create_var_from_codelist(metacore, input_var = ETHNIC, out_var = ETHNICN) %>% + create_var_from_codelist(metacore, input_var = ARMCD, out_var = COHORT) %>% + create_var_from_codelist(metacore, input_var = ARMCD, out_var = COHORTC) %>% + create_var_from_codelist(metacore, input_var = ARM, out_var = ARMN) %>% + create_var_from_codelist(metacore, input_var = ACTARM, out_var = ACTARMN) %>% + create_var_from_codelist(metacore, input_var = COUNTRY, out_var = COUNTRYN) %>% + create_var_from_codelist(metacore, input_var = COUNTRY, out_var = COUNTRYL) %>% + mutate( + STUDYIDN = as.numeric(word(USUBJID, 1, sep = fixed("-"))), + SITEIDN = as.numeric(word(USUBJID, 2, sep = fixed("-"))), + USUBJIDN = as.numeric(word(USUBJID, 3, sep = fixed("-"))), + SUBJIDN = as.numeric(SUBJID), + ROUTE = unique(adex$EXROUTE)[1], + FORM = unique(adex$EXDOSFRM)[1], + REGION1 = COUNTRY, + REGION1N = COUNTRYN, + ) %>% + create_var_from_codelist(metacore, input_var = FORM, out_var = FORMN) %>% + create_var_from_codelist(metacore, input_var = ROUTE, out_var = ROUTEN) + +## ----r------------------------------------------------------------------------ +# ---- Derive additional baselines from ADVS and ADLB ---- + +labsbl <- adlb %>% + filter(ABLFL == "Y" & PARAMCD %in% c("CREAT", "ALT", "AST", "BILI")) %>% + mutate(PARAMCDB = paste0(PARAMCD, "BL")) %>% + select(STUDYID, USUBJID, PARAMCDB, AVAL) + +covar_vslb <- covar %>% + derive_vars_merged( + dataset_add = advs, + filter_add = PARAMCD == "HEIGHT" & ABLFL == "Y", + by_vars = exprs(STUDYID, USUBJID), + new_vars = exprs(HTBL = AVAL) + ) %>% + derive_vars_merged( + dataset_add = advs, + filter_add = PARAMCD == "WEIGHT" & ABLFL == "Y", + by_vars = exprs(STUDYID, USUBJID), + new_vars = exprs(WTBL = AVAL) + ) %>% + derive_vars_transposed( + dataset_merge = labsbl, + by_vars = exprs(STUDYID, USUBJID), + key_var = PARAMCDB, + value_var = AVAL + ) %>% + mutate( + BMIBL = compute_bmi(height = HTBL, weight = WTBL), + BSABL = compute_bsa( + height = HTBL, + weight = WTBL, + method = "Mosteller" + ), + CRCLBL = compute_egfr( + creat = CREATBL, creatu = "SI", age = AGE, weight = WTBL, sex = SEX, + method = "CRCL" + ), + EGFRBL = compute_egfr( + creat = CREATBL, creatu = "SI", age = AGE, weight = WTBL, sex = SEX, + method = "CKD-EPI" + ) + ) %>% + rename(TBILBL = BILIBL) + +## ----r------------------------------------------------------------------------ +# ---- Add Exposure Metrics ---- +covar_auc <- covar_vslb %>% + derive_vars_transposed( + dataset_merge = adpp, + filter = PARAMCD %in% c("AUCLST", "CMAX"), + by_vars = get_admiral_option("subject_keys"), + key_var = PARAMCD, + value_var = AVAL + ) %>% + rename(AUCSS = AUCLST, CMAXSS = CMAX) + +## ----r------------------------------------------------------------------------ +# ---- Derivations ---- +# For ADTTE censor variables add "IND" to PARAMCD +adttei <- adtte %>% + mutate(PARAMCD = paste0(PARAMCD, "IND")) + +ader_tte <- adsl %>% + select(!!!get_admiral_option("subject_keys")) %>% + # Create OS and PFS variables from ADTTE + derive_vars_transposed( + dataset_merge = adtte, + by_vars = get_admiral_option("subject_keys"), + key_var = PARAMCD, + value_var = AVAL + ) %>% + # Create OS and PFS censor variables + derive_vars_transposed( + dataset_merge = adttei, + by_vars = get_admiral_option("subject_keys"), + key_var = PARAMCD, + value_var = CNSR + ) + +## ----r------------------------------------------------------------------------ +# ---- Add ADRS data ---- +# Add response date to ADSL for duration of response calculation +ader_bor <- ader_tte %>% + derive_vars_merged( + dataset_add = adrs, + filter_add = PARAMCD == "BOR" & ANL01FL == "Y", + by_vars = get_admiral_option("subject_keys"), + new_vars = exprs(BOR = AVAL, BORC = AVALC) + ) + +## ----r------------------------------------------------------------------------ +# ---- Add Sequence Number ---- +ader_aseq <- ader_bor %>% + derive_var_obs_number( + by_vars = get_admiral_option("subject_keys"), + check_type = "error" + ) + +## ----r------------------------------------------------------------------------ +# Combine covariates with ADER data + +ader_prefinal <- ader_aseq %>% + derive_vars_merged( + dataset_add = covar_auc, + by_vars = exprs(STUDYID, USUBJID) + ) + +## ----r------------------------------------------------------------------------ +ader <- ader_prefinal %>% + drop_unspec_vars(metacore) %>% # Drop unspecified variables from specs + check_variables(metacore) %>% # Check all variables specified are present and no more + check_ct_data(metacore) %>% # Checks all variables with CT only contain values within the CT + order_cols(metacore) %>% # Orders the columns according to the spec + sort_by_key(metacore) # Sorts the rows by the sort keys + +## ----r------------------------------------------------------------------------ +dir <- tempdir() # Change to whichever directory you want to save the dataset in + +ader_xpt <- ader %>% + xportr_type(metacore, domain = "ADER") %>% # Coerce variable type to match spec + xportr_length(metacore) %>% # Assigns SAS length from a variable level metadata + xportr_label(metacore) %>% # Assigns variable label from metacore specifications + xportr_format(metacore) %>% # Assigns variable format from metacore specifications + xportr_df_label(metacore) %>% # Assigns dataset label from metacore specifications + xportr_write(file.path(dir, "ader.xpt")) # Write xpt v5 transport file + +## ----r echo=TRUE, message=FALSE----------------------------------------------- +metacore <- spec_to_metacore("./metadata/pk_spec.xlsx") %>% + select_dataset("ADEE") + +## ----r------------------------------------------------------------------------ +# ---- Create adee base dataset + +# Get variable names from both datasets +adsl_vars <- names(adsl) +adtte_vars <- names(adtte) + +# Find common variables +common_vars <- intersect(adsl_vars, adtte_vars) + +# Remove key variables to get variables to drop +vars_to_drop <- setdiff(common_vars, c("STUDYID", "USUBJID")) + +# Ensure PARAMN exists in ADTTE +if (!"PARAMN" %in% names(adtte)) { + adtte <- adtte %>% + mutate( + PARAMN = case_when( + PARAMCD == "PFS" ~ 1, + PARAMCD == "OS" ~ 2, + PARAMCD == "TTP" ~ 3, + PARAMCD == "TTNT" ~ 4, + TRUE ~ 99 + ) + ) +} + +# ---- Create ADEE Base + +adee_base <- adtte %>% + # Filter to efficacy endpoints + filter(PARAMCD %in% c("OS", "PFS", "TTP", "TTNT")) %>% + # Add derived variables + mutate( + EVENT = 1 - CNSR, + AVALU = if_else(!is.na(AVAL), "DAYS", NA_character_), + ) %>% + # Remove overlapping variables (use clean method) + select(-any_of(vars_to_drop)) + + +## ----r------------------------------------------------------------------------ +# ---- Add Analysis variables + +adee_aseq <- adee_base %>% + # Analysis flags + mutate( + ANL01FL = if_else(PARAMCD == "PFS", "Y", ""), + ANL02FL = if_else(PARAMCD == "OS", "Y", ""), + ANL03FL = if_else(PARAMCD == "TTP", "Y", ""), + ANL04FL = if_else(PARAMCD == "TTNT", "Y", "") + ) %>% + # Parameter categories + mutate( + PARCAT1 = "EFFICACY", + PARCAT2 = "TIME TO EVENT" + ) %>% + # Sequence number + derive_var_obs_number( + by_vars = exprs(STUDYID, USUBJID), + order = exprs(PARAMCD), + new_var = ASEQ, + check_type = "error" + ) + + +## ----r------------------------------------------------------------------------ +# Combine covariates with ADER data + +adee_prefinal <- adee_aseq %>% + derive_vars_merged( + dataset_add = covar_auc, + by_vars = exprs(STUDYID, USUBJID) + ) + +## ----r------------------------------------------------------------------------ +adee <- adee_prefinal %>% + drop_unspec_vars(metacore) %>% # Drop unspecified variables from specs + check_variables(metacore) %>% # Check all variables specified are present and no more + check_ct_data(metacore) %>% # Checks all variables with CT only contain values within the CT + order_cols(metacore) %>% # Orders the columns according to the spec + sort_by_key(metacore) # Sorts the rows by the sort keys + +## ----r------------------------------------------------------------------------ +dir <- tempdir() # Change to whichever directory you want to save the dataset in + +adee_xpt <- adee %>% + xportr_type(metacore, domain = "ADEE") %>% # Coerce variable type to match spec + xportr_length(metacore) %>% # Assigns SAS length from a variable level metadata + xportr_label(metacore) %>% # Assigns variable label from metacore specifications + xportr_format(metacore) %>% # Assigns variable format from metacore specifications + xportr_df_label(metacore) %>% # Assigns dataset label from metacore specifications + xportr_write(file.path(dir, "adee.xpt")) # Write xpt v5 transport file + +## ----r------------------------------------------------------------------------ +# [Similar structure...] + +## ----r------------------------------------------------------------------------ +# [Similar structure...] diff --git a/adam/ader.qmd b/adam/ader.qmd new file mode 100644 index 00000000..57d31e7a --- /dev/null +++ b/adam/ader.qmd @@ -0,0 +1,474 @@ +--- +title: "Exposure-Response" +order: 12 +--- + +```{r setup script, include=FALSE, purl=FALSE} +invisible_hook_purl <- function(before, options, ...) { + knitr::hook_purl(before, options, ...) + NULL +} +knitr::knit_hooks$set(purl = invisible_hook_purl) +source("functions/print_df.R") +``` + +# Introduction + +Exposure-Response (ER) modeling is a critical tool in drug development for evaluating the relationships between drug exposure, safety, and efficacy. These analyses help characterize dose-response relationships, optimize dosing regimens, and support regulatory decision-making. + +While CDISC released the Population Pharmacokinetic (PopPK) Implementation Guide in 2023 (see [Basic Data Structure for ADaM Population PK](https://www.cdisc.org/standards/foundational/adam/basic-data-structure-adam-poppk-implementation-guide-v1-0)), no equivalent standards currently exist specifically for ER data. However, ER datasets share many structural similarities with PopPK datasets, including numeric covariates, relative time variables, and pharmacokinetic exposure metrics. The examples below demonstrate how PopPK principles can be extended to create standardized ER analysis datasets. + +The following four specialized datasets support different aspects of exposure-response analysis: + +| Dataset | Full Name | Primary Purpose | Key Features | +|------------------|------------------|-------------------|------------------| +| **ADER** | Exposure-Response Analysis Dataset | Integrated exposure-response relationships across safety and efficacy endpoints | Combines PK metrics (AUC, Cmax) with time-to-event outcomes (OS, PFS), tumor response, and baseline covariates | +| **ADEE** | Exposure-Efficacy Analysis Dataset | Exposure relationships with efficacy and tumor response endpoints | Focuses on efficacy outcomes such as tumor measurements, response rates, and progression metrics linked to drug exposure | +| **ADES** | Exposure-Safety Analysis Dataset | Exposure relationships with adverse events and safety endpoints | Links exposure metrics to adverse event occurrence, severity, and time-to-onset for safety signal detection | +| **ADTRR** | Exposure-Tumor Response Rate Analysis Dataset | Exposure relationships with categorical tumor response metrics | Analyzes exposure impact on response categories (CR, PR, SD, PD) and best overall response | + +Each dataset builds upon standard ADaM datasets (ADSL, ADRS, ADTTE, ADAE, ADLB, ADVS) and incorporates pharmacokinetic parameters from ADPC/ADPP to create analysis-ready datasets for exposure-response modeling. + +## First Load Packages + +First we will load the packages required for our project. We will use `{admiral}` and `{admiralonco}` for the creation of analysis data. We will source these from `{pharmaverseadam}`. `{admiral}` requires `{dplyr}`, `{lubridate}` and `{stringr}`. Find other `{admiral}` functions and related variables by searching [admiraldiscovery](https://pharmaverse.github.io/admiraldiscovery/articles/reactable.html). We will use `{metacore}` and `{metatools}` to store and manipulate metadata from our specifications. We will use `{xportr}` to perform checks on the final data and export to a transport file. + +Exposure Response data typically use ADaM data as source, so this example will depend on `{pharmaverseadam}` with data from existing `{admiral}` and `{admiralonco}` templates. + +```{r echo=TRUE, message=FALSE} +#| label: Load Packages +# Load Packages +library(admiral) +library(admiralonco) +# pharmaverseadam contains example datasets generated from the CDISC pilot +# project SDTM ran through admiral templates +library(pharmaverseadam) +library(dplyr) +library(lubridate) +library(stringr) +library(metacore) +library(metatools) +library(xportr) +``` + +## Next Load Specifications for Metacore + +We have saved our specifications in an Excel file and will load them into `{metacore}` with the `metacore::spec_to_metacore()` function. + +```{r echo=TRUE, message=FALSE} +#| label: Load Specs +#| warning: false +# ---- Load Specs for Metacore ---- +metacore <- spec_to_metacore("./metadata/pk_spec.xlsx") %>% + select_dataset("ADER") +``` + +## Load Source Datasets + +We will load are ADaM data from `{pharmaverseadam}`. The main source will be `ADRS` and `ADTTE`. We will use `ADSL` for baseline characteristics and we will derive additional baselines from vital signs `ADVS` and laboratory data `ADLB`. + +```{r} +#| label: Load Source +# ---- Load source datasets ---- +# Load ADRS, ADTTE, ADSL, ADLB, ADVS, ADEX, ADPP and ADAE +adrs <- pharmaverseadam::adrs_onco +adtte <- pharmaverseadam::adtte_onco +adsl <- pharmaverseadam::adsl +adlb <- pharmaverseadam::adlb +advs <- pharmaverseadam::advs +adex <- pharmaverseadam::adex %>% + filter(PARCAT1 == "INDIVIDUAL") +adpp <- pharmaverseadam::adpp +adae <- pharmaverseadam::adae +``` + +## Common Derivations + +We will include common derivations for all exposure-response datasets first. These include covariates and exposure metrics. + +## Derive Covariates Using `{metatools}` + +In this step we will create our numeric covariates using the `metatools::create_var_from_codelist()` function. + +```{r} +#| label: Common Covariates +# ---- Derive Covariates ---- +# Include numeric values for STUDYIDN, USUBJIDN, SEXN, RACEN etc. + +covar <- adsl %>% + create_var_from_codelist(metacore, input_var = STUDYID, out_var = STUDYIDN) %>% + create_var_from_codelist(metacore, input_var = SEX, out_var = SEXN) %>% + create_var_from_codelist(metacore, input_var = RACE, out_var = RACEN) %>% + create_var_from_codelist(metacore, input_var = ETHNIC, out_var = ETHNICN) %>% + create_var_from_codelist(metacore, input_var = ARMCD, out_var = COHORT) %>% + create_var_from_codelist(metacore, input_var = ARMCD, out_var = COHORTC) %>% + create_var_from_codelist(metacore, input_var = ARM, out_var = ARMN) %>% + create_var_from_codelist(metacore, input_var = ACTARM, out_var = ACTARMN) %>% + create_var_from_codelist(metacore, input_var = COUNTRY, out_var = COUNTRYN) %>% + create_var_from_codelist(metacore, input_var = COUNTRY, out_var = COUNTRYL) %>% + mutate( + STUDYIDN = as.numeric(word(USUBJID, 1, sep = fixed("-"))), + SITEIDN = as.numeric(word(USUBJID, 2, sep = fixed("-"))), + USUBJIDN = as.numeric(word(USUBJID, 3, sep = fixed("-"))), + SUBJIDN = as.numeric(SUBJID), + ROUTE = unique(adex$EXROUTE)[1], + FORM = unique(adex$EXDOSFRM)[1], + REGION1 = COUNTRY, + REGION1N = COUNTRYN, + ) %>% + create_var_from_codelist(metacore, input_var = FORM, out_var = FORMN) %>% + create_var_from_codelist(metacore, input_var = ROUTE, out_var = ROUTEN) +``` + +```{r eval=TRUE, echo=FALSE, purl=FALSE} +print_df(covar %>% select(USUBJID, SEX, SEXN, RACE, RACEN, FORM, FORMN)) +``` + +### Derive Additional Baselines + +Next we add additional baselines from vital signs and laboratory data. + +```{r} +#| label: Baselines +# ---- Derive additional baselines from ADVS and ADLB ---- + +labsbl <- adlb %>% + filter(ABLFL == "Y" & PARAMCD %in% c("CREAT", "ALT", "AST", "BILI")) %>% + mutate(PARAMCDB = paste0(PARAMCD, "BL")) %>% + select(STUDYID, USUBJID, PARAMCDB, AVAL) + +covar_vslb <- covar %>% + derive_vars_merged( + dataset_add = advs, + filter_add = PARAMCD == "HEIGHT" & ABLFL == "Y", + by_vars = exprs(STUDYID, USUBJID), + new_vars = exprs(HTBL = AVAL) + ) %>% + derive_vars_merged( + dataset_add = advs, + filter_add = PARAMCD == "WEIGHT" & ABLFL == "Y", + by_vars = exprs(STUDYID, USUBJID), + new_vars = exprs(WTBL = AVAL) + ) %>% + derive_vars_transposed( + dataset_merge = labsbl, + by_vars = exprs(STUDYID, USUBJID), + key_var = PARAMCDB, + value_var = AVAL + ) %>% + mutate( + BMIBL = compute_bmi(height = HTBL, weight = WTBL), + BSABL = compute_bsa( + height = HTBL, + weight = WTBL, + method = "Mosteller" + ), + CRCLBL = compute_egfr( + creat = CREATBL, creatu = "SI", age = AGE, weight = WTBL, sex = SEX, + method = "CRCL" + ), + EGFRBL = compute_egfr( + creat = CREATBL, creatu = "SI", age = AGE, weight = WTBL, sex = SEX, + method = "CKD-EPI" + ) + ) %>% + rename(TBILBL = BILIBL) +``` + +```{r eval=TRUE, echo=FALSE, purl=FALSE} +print_df(covar_vslb %>% select(USUBJID, WTBL, HTBL, BMIBL, CRCLBL)) +``` + +## Add Exposure Metrics from `ADPP` + +An essential component of ER modeling is the exposure metrics calculated from the PK concentration data in `ADPC` or `ADPPK`. Here we will use `AUCLST` and `CMAX` from the `ADPP` template from `{admiral}` in `{pharmaverseadam}`. See the `{aNCA}` package for details about calculating `AUC`, `CMAX`, and other parameters. + +```{r} +#| label: AUCSS +# ---- Add Exposure Metrics ---- +covar_auc <- covar_vslb %>% + derive_vars_transposed( + dataset_merge = adpp, + filter = PARAMCD %in% c("AUCLST", "CMAX"), + by_vars = get_admiral_option("subject_keys"), + key_var = PARAMCD, + value_var = AVAL + ) %>% + rename(AUCSS = AUCLST, CMAXSS = CMAX) +``` + +```{r eval=TRUE, echo=FALSE, purl=FALSE} +print_df(covar_auc %>% select( + USUBJID, TRT01A, SEX, WTBL, HTBL, AUCSS, CMAXSS +)) +``` + +# Code for Individual Datasets + +Derivations specific to each dataset continue below. Select the appropriate tab to view. + +## Dataset-Specific Derivations + +::: {.panel-tabset} + +## ADER + +### Derive Time to Event Variables from `ADTTE` + +We will use parameters from from `ADTTE` for Overall Survival, Progression Free Survival and Duration of Response. We will use `admiral::derive_vars_transposed()` to transpose the `AVAL` for each `PARAMCD`. + +```{r} +#| label: ADER Add ADTTE variables +# ---- Derivations ---- +# For ADTTE censor variables add "IND" to PARAMCD +adttei <- adtte %>% + mutate(PARAMCD = paste0(PARAMCD, "IND")) + +ader_tte <- adsl %>% + select(!!!get_admiral_option("subject_keys")) %>% + # Create OS and PFS variables from ADTTE + derive_vars_transposed( + dataset_merge = adtte, + by_vars = get_admiral_option("subject_keys"), + key_var = PARAMCD, + value_var = AVAL + ) %>% + # Create OS and PFS censor variables + derive_vars_transposed( + dataset_merge = adttei, + by_vars = get_admiral_option("subject_keys"), + key_var = PARAMCD, + value_var = CNSR + ) +``` + +```{r eval=TRUE, echo=FALSE, purl=FALSE} +print_df(ader_tte %>% select(USUBJID, OS, OSIND, PFS, PFSIND, RSD, RSDIND)) +``` + +We will use Best Overall Response by Investigator (BOR) from `ADRS`. We attach this to the data with `admiral::derive_vars_merged()`. Note that `derive_vars_transposed()` and `derive_vars_merged()` will be our primary ways of combining data from the different `{admiral}` and `{admiralonco}` templates. + +```{r} +#| label: ADER Add ADRS +# ---- Add ADRS data ---- +# Add response date to ADSL for duration of response calculation +ader_bor <- ader_tte %>% + derive_vars_merged( + dataset_add = adrs, + filter_add = PARAMCD == "BOR" & ANL01FL == "Y", + by_vars = get_admiral_option("subject_keys"), + new_vars = exprs(BOR = AVAL, BORC = AVALC) + ) +``` + +Add Analysis Sequence Number using `admiral::derive_var_obs_number()`. + +```{r} +#| label: ADER ASEQ +# ---- Add Sequence Number ---- +ader_aseq <- ader_bor %>% + derive_var_obs_number( + by_vars = get_admiral_option("subject_keys"), + check_type = "error" + ) +``` + +```{r eval=TRUE, echo=FALSE, purl=FALSE} +print_df(ader_bor %>% select( + USUBJID, BOR, BORC +)) +``` + +### Combine with Covariates + +We combine our covariates with the rest of the data + +```{r} +#| label: ADER Combine with Covariates +# Combine covariates with ADER data + +ader_prefinal <- ader_aseq %>% + derive_vars_merged( + dataset_add = covar_auc, + by_vars = exprs(STUDYID, USUBJID) + ) +``` + +### Check Data With metacore and metatools + +We use `{metacore}` objects with `{metatools}` functions to perform a number of checks on the data. We will drop variables not in the specs and make sure all the variables from the specs are included. + +```{r} +#| label: ADER Metacore +#| warning: false + +ader <- ader_prefinal %>% + drop_unspec_vars(metacore) %>% # Drop unspecified variables from specs + check_variables(metacore) %>% # Check all variables specified are present and no more + check_ct_data(metacore) %>% # Checks all variables with CT only contain values within the CT + order_cols(metacore) %>% # Orders the columns according to the spec + sort_by_key(metacore) # Sorts the rows by the sort keys +``` + +### Apply Labels and Formats with xportr + +Using {xportr} we check variable type, assign variable length, add variable labels, add variable formats, and save a transport file with `xportr::xportr_write()`. + +```{r} +#| label: ADER xportr +dir <- tempdir() # Change to whichever directory you want to save the dataset in + +ader_xpt <- ader %>% + xportr_type(metacore, domain = "ADER") %>% # Coerce variable type to match spec + xportr_length(metacore) %>% # Assigns SAS length from a variable level metadata + xportr_label(metacore) %>% # Assigns variable label from metacore specifications + xportr_format(metacore) %>% # Assigns variable format from metacore specifications + xportr_df_label(metacore) %>% # Assigns dataset label from metacore specifications + xportr_write(file.path(dir, "ader.xpt")) # Write xpt v5 transport file +``` + +## ADEE + +### Load Specifications +```{r echo=TRUE, message=FALSE} +#| label: ADEE Load Specs +#| warning: false +metacore <- spec_to_metacore("./metadata/pk_spec.xlsx") %>% + select_dataset("ADEE") +``` + +```{r} +#| label: ADEE Base dataset +# ---- Create adee base dataset + +# Get variable names from both datasets +adsl_vars <- names(adsl) +adtte_vars <- names(adtte) + +# Find common variables +common_vars <- intersect(adsl_vars, adtte_vars) + +# Remove key variables to get variables to drop +vars_to_drop <- setdiff(common_vars, c("STUDYID", "USUBJID")) + +# Ensure PARAMN exists in ADTTE +if (!"PARAMN" %in% names(adtte)) { + adtte <- adtte %>% + mutate( + PARAMN = case_when( + PARAMCD == "PFS" ~ 1, + PARAMCD == "OS" ~ 2, + PARAMCD == "TTP" ~ 3, + PARAMCD == "TTNT" ~ 4, + TRUE ~ 99 + ) + ) +} + +# ---- Create ADEE Base + +adee_base <- adtte %>% + # Filter to efficacy endpoints + filter(PARAMCD %in% c("OS", "PFS", "TTP", "TTNT")) %>% + # Add derived variables + mutate( + EVENT = 1 - CNSR, + AVALU = if_else(!is.na(AVAL), "DAYS", NA_character_), + ) %>% + # Remove overlapping variables (use clean method) + select(-any_of(vars_to_drop)) +``` + +### Add Analysis Variables + +```{r} +#| label: ADEE Analysis variables +# ---- Add Analysis variables + +adee_aseq <- adee_base %>% + # Analysis flags + mutate( + ANL01FL = if_else(PARAMCD == "PFS", "Y", ""), + ANL02FL = if_else(PARAMCD == "OS", "Y", ""), + ANL03FL = if_else(PARAMCD == "TTP", "Y", ""), + ANL04FL = if_else(PARAMCD == "TTNT", "Y", "") + ) %>% + # Parameter categories + mutate( + PARCAT1 = "EFFICACY", + PARCAT2 = "TIME TO EVENT" + ) %>% + # Sequence number + derive_var_obs_number( + by_vars = exprs(STUDYID, USUBJID), + order = exprs(PARAMCD), + new_var = ASEQ, + check_type = "error" + ) +``` + +### Combine with Covariates and Exposure + +We combine our covariates with the rest of the data + +```{r} +#| label: ADEE Combine with Covariates +# Combine covariates with ADER data + +adee_prefinal <- adee_aseq %>% + derive_vars_merged( + dataset_add = covar_auc, + by_vars = exprs(STUDYID, USUBJID) + ) +``` + + + +### Check Data With metacore and metatools + +We use `{metacore}` objects with `{metatools}` functions to perform a number of checks on the data. We will drop variables not in the specs and make sure all the variables from the specs are included. + +```{r} +#| label: Metacore +#| warning: false + +adee <- adee_prefinal %>% + drop_unspec_vars(metacore) %>% # Drop unspecified variables from specs + check_variables(metacore) %>% # Check all variables specified are present and no more + check_ct_data(metacore) %>% # Checks all variables with CT only contain values within the CT + order_cols(metacore) %>% # Orders the columns according to the spec + sort_by_key(metacore) # Sorts the rows by the sort keys +``` + +### Apply Labels and Formats with xportr + +Using {xportr} we check variable type, assign variable length, add variable labels, add variable formats, and save a transport file with `xportr::xportr_write()`. + +```{r} +#| label: xportr +dir <- tempdir() # Change to whichever directory you want to save the dataset in + +adee_xpt <- adee %>% + xportr_type(metacore, domain = "ADEE") %>% # Coerce variable type to match spec + xportr_length(metacore) %>% # Assigns SAS length from a variable level metadata + xportr_label(metacore) %>% # Assigns variable label from metacore specifications + xportr_format(metacore) %>% # Assigns variable format from metacore specifications + xportr_df_label(metacore) %>% # Assigns dataset label from metacore specifications + xportr_write(file.path(dir, "adee.xpt")) # Write xpt v5 transport file +``` + + +## ADES + +```{r} +# [Similar structure...] +``` + +## ADTRR + +```{r} +# [Similar structure...] +``` + + +::: diff --git a/inst/WORDLIST b/inst/WORDLIST index 2c098312..4f050385 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -3,6 +3,8 @@ ABLFL aCRF ACTARM ACTARMCD +ACTARMN +ACTARMN adae ADAE adam @@ -12,6 +14,12 @@ ADaMs addadsl ADDL addparams +ADEE +ader +ADER +ADES +adex +ADEX adlb ADLB admiraldiscovery @@ -20,6 +28,8 @@ admiralophtha admiralvaccine adpc ADPC +adpp +ADPP adppk ADPPK ADRG @@ -32,8 +42,10 @@ adslvars ADT ADTF ADTM -adtte +ADTRR ADTTE +adtte +adttei ADURN ADURU advs @@ -43,8 +55,8 @@ ae AE AEACN AEBDSYCD -aebodsys AEBODSYS +aebodsys AEDECOD AEDIS AEDTC @@ -86,8 +98,8 @@ AESOD AESTDAT AESTDTC AESTDY -AETERM aeterm +AETERM AETHNIC AETHNICN AFRLT @@ -99,6 +111,8 @@ Alanine ALLOQ AMBUL Aminotransferase +analyte +Analyte aNCA anl ANL @@ -106,23 +120,22 @@ anldates anldur anlflags ANLzzFL -analyte -Analyte +ANRHI anrind ANRIND -ANRHI ANRLO AOCCIFL APPPK Appsilon -aprlt APRLT +aprlt ard ARD ARDs arg args ARMCD +ARMN arrlt ARRLT articlehere @@ -140,17 +153,20 @@ ATPT ATPTN ATPTREF attr +auc +AUCLST +AUCSS autofit autolog autoslider autoslideR AutoslideR -aval AVAL +aval AVALC AVALCA -avalcat AVALCAT +avalcat AVALCATy AVALU avalvars @@ -166,9 +182,9 @@ BASETYPE basetypes bds BDS +bigN BILI BILIBL -bigN BLAS blq BLQ @@ -181,6 +197,9 @@ BMIBL BMIBLU BMRKR BNRIND +bor +BOR +BORC br bsa BSABL @@ -192,15 +211,19 @@ cairoFT callr callout categorizationvars -cdisc CDISC +cdisc CDISCPILOT chgpchg CKD cli clst +Cmax +CMAX +CMAXSS CMT CNSDTDSC +CNSR codebases codelist codelists @@ -239,11 +262,11 @@ datacutr dataname datanames datasetjson -datetime Datetime +datetime datetimes -Davide davidblair +Davide de DEATHDT deathvars @@ -268,10 +291,10 @@ DM DMDTC DMDY dmvars +docx DOSEA DOSEP DOSEU -docx dplyr ds DS @@ -298,8 +321,8 @@ DTHDTC DTHDTF DTHFL DTHSEQ -dtm DTM +dtm dtype DTYPE DV @@ -310,9 +333,9 @@ dy dylib DYTPE ec -eCTD ECENDAT ECSTDAT +eCTD ectd edelarua eg @@ -327,6 +350,7 @@ EPI esub eSub eSubmission +ETHNICN eval Evaluable EVID @@ -435,8 +459,8 @@ libRblas libRlapack lifecycle lineplot -linter Linter +linter lintr lintR lm @@ -469,8 +493,8 @@ Metacore metatools miniUI minumum -mmm mmHg +mmm Mosteller MRRLT mtcars @@ -494,10 +518,10 @@ nPK NPRLT nProtocol nr -nrrlt NRRLT -ns +nrrlt Ns +ns nSampling nTime num @@ -510,10 +534,11 @@ occflags OID onco ONCO -ontrtfl ONTRTFL +ontrtfl ord os +OSIND othgrpvars outfile outputId @@ -528,6 +553,7 @@ param PARAM paramcd PARAMCD +PARAMCDB PARAMN params paramval @@ -536,8 +562,8 @@ PARCAT PATNUM pc PCDTC -pchg PCHG +pchg PCLLOQ PCRFTDT PCRFTDTM @@ -552,8 +578,9 @@ PCTESTCD PCTPT PCTPTNUM pcts -pfs PFS +pfs +PFSIND pharma pharmacokinetic Pharmacokinetic @@ -572,11 +599,12 @@ plotOutput PN png poc +PopPK pos POSIXct POSIXlt -pptx PPTX +pptx pre Pre preconfigured @@ -602,8 +630,8 @@ QD qmd QNAM qtc -racegr RACEGR +racegr RACEN RACEx RANDDT @@ -654,6 +682,8 @@ ROUTEN rowcounts RRLTU Rscript +RSD +RSDIND RSDTC RSEVAL RSSEQ @@ -672,15 +702,15 @@ SASFL SCRFDT sd sdi -sdtm SDTM +sdtm sdtmchecks SDTMs selectInput sep SER -sessioninfo sessionInfo +sessioninfo setdiff setequal SEXN @@ -739,7 +769,6 @@ tempfile TEMPLOC TESTCD tf -tfrmt tformat tfrmt tgdt @@ -749,8 +778,8 @@ tibble tidyr tidyselect tidyverse -timepoint Timepoint +timepoint timingvars TLG TLGs @@ -768,15 +797,15 @@ traceback TRE treatmentvars tribble -trt TRT +trt TRTA -trtdurd TRTDURD +trtdurd TRTEDT TRTEDTM -trtemfl TRTEMFL +trtemfl TRTETMF TRTP TRTSDT @@ -808,6 +837,7 @@ USUBJID USUBJIDN utf vapply +vards varlabels vctrs viewerHeight diff --git a/metadata/pk_spec.xlsx b/metadata/pk_spec.xlsx index 00f2e241..18acc382 100644 Binary files a/metadata/pk_spec.xlsx and b/metadata/pk_spec.xlsx differ