Derive a new parameter computed from the value of other parameters

Use admiral::derive_param_computed() like a calculator to derive new parameters/rows based on existing ones
ADaM
Author

Kangjie Zhang

Published

June 27, 2023

Introduction

When creating ADaM Basic Data Structure (BDS) datasets, we often encounter deriving a new parameter based on the analysis values (e.g., AVAL) of other parameters.

The admiral function derive_param_computed() adds a parameter computed from the analysis value of other parameters.

It works like a calculator to derive new records without worrying about merging and combining datasets, all you need is a derivation formula, which also improves the readability of the code.

Example

A value level validation use case, where derive_param_computed() is used to validate a derived parameter - PARAMCD = ADPCYMG (Actual Dose per Cycle) in ADEX dataset.

Derivation

Actual Dose per Cycle is derived from the Total Amount of Dose (PARAMCD = TOTDOSE) / Number of Cycles (PARAMCD = NUMCYC)

In this example, ADEX.AVAL when ADEX.PARAMCD = ADPCYMG can be derived as:

\[ AVAL (PARAMCD = ADPCYMG) = \frac{AVAL (PARAMCD = TOTDOSE)}{AVAL (PARAMCD = NUMCYC)} \]

Loading Packages and Creating Example Data

library(tibble)
library(dplyr)
library(diffdf)
library(admiral)

adex <- tribble(
  ~USUBJID,  ~PARAMCD,  ~PARAM,                       ~AVAL,
  "101",     "TOTDOSE", "Total Amount of Dose (mg)",  180,
  "101",     "NUMCYC",  "Number of Cycles",           3
)

Derive New Parameter

adex_admiral <- derive_param_computed(
  adex,
  by_vars = exprs(USUBJID),
  parameters = c("TOTDOSE", "NUMCYC"),
  set_values_to = exprs(
    PARAMCD = "ADPCYMG",
    PARAM = "Actual Dose per Cycle (mg)",
    AVAL = AVAL.TOTDOSE / AVAL.NUMCYC
  )
)
# A tibble: 3 × 4
  USUBJID PARAMCD PARAM                       AVAL
  <chr>   <chr>   <chr>                      <dbl>
1 101     TOTDOSE Total Amount of Dose (mg)    180
2 101     NUMCYC  Number of Cycles               3
3 101     ADPCYMG Actual Dose per Cycle (mg)    60

Compare

For validation purpose, the diffdf package is used below to mimic SAS proc compare.

adex_expected <- bind_rows(
  adex,
  tribble(
    ~USUBJID,  ~PARAMCD,  ~PARAM,                       ~AVAL,
    "101",     "ADPCYMG", "Actual Dose per Cycle (mg)", 60
  )
)

diffdf(adex_expected, adex_admiral, keys = c("USUBJID", "PARAMCD"))
No issues were found!

Last updated

2024-12-13 13:36:26.827967

Details

Reuse

Citation

BibTeX citation:
@online{zhang2023,
  author = {Zhang, Kangjie},
  title = {Derive a New Parameter Computed from the Value of Other
    Parameters},
  date = {2023-06-27},
  url = {https://pharmaverse.github.io/blog/posts/2023-06-27_admiral/valuelevel/derive_param_computed.html},
  langid = {en}
}
For attribution, please cite this work as:
Zhang, Kangjie. 2023. “Derive a New Parameter Computed from the Value of Other Parameters.” June 27, 2023. https://pharmaverse.github.io/blog/posts/2023-06-27_admiral/valuelevel/derive_param_computed.html.