From d95fe7dd5143e91091c7a1b58a5a9e4c376f1e0a Mon Sep 17 00:00:00 2001 From: "SPUJ (Siddhesh Pujari)" Date: Sat, 26 Oct 2024 13:03:58 +0200 Subject: [PATCH 1/4] #28: Updated criterion variables section to use restrict_derivation --- vignettes/advs.Rmd | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/vignettes/advs.Rmd b/vignettes/advs.Rmd index 001a5c3..88a3364 100644 --- a/vignettes/advs.Rmd +++ b/vignettes/advs.Rmd @@ -329,26 +329,32 @@ For deriving criterion variables (`CRITy`, `CRITyFL`, `CRITyFLN`) It ensures that they are derived in an ADaM-compliant way (see documentation of the function for details). -In most cases the criterion depends on the parameter. In the following -example, the criterion flags for weight based on percentage change in -weight reduction from baseline is derived. Additional criterion flags -can be added as needed. +In most cases the criterion depends on the parameter and in this case the higher order function [`restrict_derivation()`](https://pharmaverse.github.io/admiral/dev/reference/restrict_derivation.html) can be useful. +In the following example, the criterion flags for weight based on percentage change in weight reduction from baseline is derived. Additional criterion flags can be added as needed. ```{r eval=TRUE} advs <- advs %>% - derive_vars_crit_flag( - condition = PCHG <= -5 & PARAMCD == "WEIGHT", - description = "Achievement of ≥ 5% weight reduction from baseline", - crit_nr = 1, - values_yn = TRUE, - create_numeric_flag = FALSE + restrict_derivation( + derivation = derive_vars_crit_flag, + args = params( + condition = PCHG <= -5 & PARAMCD == "WEIGHT", + description = "Achievement of ≥ 5% weight reduction from baseline", + crit_nr = 1, + values_yn = TRUE, + create_numeric_flag = FALSE + ), + filter = VISITNUM > 0 & PARAMCD == "WEIGHT" ) %>% - derive_vars_crit_flag( - condition = PCHG <= -10 & PARAMCD == "WEIGHT", - description = "Achievement of ≥ 10% weight reduction from baseline", - crit_nr = 2, - values_yn = TRUE, - create_numeric_flag = FALSE + restrict_derivation( + derivation = derive_vars_crit_flag, + args = params( + condition = PCHG <= -10 & PARAMCD == "WEIGHT", + description = "Achievement of ≥ 10% weight reduction from baseline", + crit_nr = 2, + values_yn = TRUE, + create_numeric_flag = FALSE + ), + filter = VISITNUM > 0 & PARAMCD == "WEIGHT" ) ``` From 6ddccbeaf127ac2bd58ba6820b977b201c5fc892 Mon Sep 17 00:00:00 2001 From: "SPUJ (Siddhesh Pujari)" Date: Sat, 26 Oct 2024 13:09:54 +0200 Subject: [PATCH 2/4] #28: Updated PARCAT1 for all "Subject Characteristic" records to "Anthropometric measurement" --- vignettes/advs.Rmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vignettes/advs.Rmd b/vignettes/advs.Rmd index 88a3364..3c8ba7d 100644 --- a/vignettes/advs.Rmd +++ b/vignettes/advs.Rmd @@ -108,11 +108,11 @@ One key addition in metabolic trials are vital sign parameters associated to bod ```{r, echo=TRUE, message=FALSE} param_lookup <- tribble( ~VSTESTCD, ~PARAMCD, ~PARAM, ~PARAMN, ~PARCAT1, ~PARCAT1N, - "HEIGHT", "HEIGHT", "Height (cm)", 1, "Subject Characteristic", 1, - "WEIGHT", "WEIGHT", "Weight (kg)", 2, "Subject Characteristic", 1, - "BMI", "BMI", "Body Mass Index(kg/m^2)", 3, "Subject Characteristic", 1, - "HIPCIR", "HIPCIR", "Hip Circumference (cm)", 4, "Subject Characteristic", 1, - "WSTCIR", "WSTCIR", "Waist Circumference (cm)", 5, "Subject Characteristic", 1, + "HEIGHT", "HEIGHT", "Height (cm)", 1, "Anthropometric measurement", 1, + "WEIGHT", "WEIGHT", "Weight (kg)", 2, "Anthropometric measurement", 1, + "BMI", "BMI", "Body Mass Index(kg/m^2)", 3, "Anthropometric measurement", 1, + "HIPCIR", "HIPCIR", "Hip Circumference (cm)", 4, "Anthropometric measurement", 1, + "WSTCIR", "WSTCIR", "Waist Circumference (cm)", 5, "Anthropometric measurement", 1, "DIABP", "DIABP", "Diastolic Blood Pressure (mmHg)", 6, "Vital Sign", 2, "PULSE", "PULSE", "Pulse Rate (beats/min)", 7, "Vital Sign", 2, "SYSBP", "SYSBP", "Systolic Blood Pressure (mmHg)", 8, "Vital Sign", 2, From a4814d81afb523f1f7c5c6cdaad7ddad4ee1a09a Mon Sep 17 00:00:00 2001 From: "SPUJ (Siddhesh Pujari)" Date: Sat, 26 Oct 2024 14:31:44 +0200 Subject: [PATCH 3/4] #28: Updated categorization section to use derive_vars_cat and a minor update to parcat1 of BMI at a later section. --- vignettes/advs.Rmd | 86 +++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 50 deletions(-) diff --git a/vignettes/advs.Rmd b/vignettes/advs.Rmd index 3c8ba7d..6cbd500 100644 --- a/vignettes/advs.Rmd +++ b/vignettes/advs.Rmd @@ -175,7 +175,7 @@ advs <- derive_param_bmi( PARAMCD = "BMI", PARAM = "Body Mass Index (kg/m^2)", PARAMN = 3, - PARCAT1 = "Subject Characteristic", + PARCAT1 = "Anthropometric measurement", PARCAT1N = 1 ), get_unit_expr = VSSTRESU, @@ -240,36 +240,32 @@ outlined below. assigning `AVALCATy`/ `AVALCAvN` and `BASECATy`/ `BASECAvN` values. Below is a simple example of how these values may be assigned: +For deriving categorization variables (`AVALCATx`, `BASECATx`) +`{admiral}` provides +[`derive_vars_cat()`](https://pharmaverse.github.io/admiral/dev/reference/derive_vars_cat.html) (see +documentation of the function for details). + ```{r eval=TRUE} -avalcat_lookup <- tibble::tribble( - ~PARAMCD, ~AVALCA1N, ~AVALCAT1, - "BMI", 1, "Underweight", - "BMI", 2, "Normal weight", - "BMI", 3, "Overweight", - "BMI", 4, "Obesity class I", - "BMI", 5, "Obesity class II", - "BMI", 6, "Obesity class III", - "BMI", NA, NA_character_ -) -format_avalcat1n <- function(param, aval) { - case_when( - param == "BMI" & aval < 18.5 ~ 1, - param == "BMI" & aval >= 18.5 & aval < 25 ~ 2, - param == "BMI" & aval >= 25 & aval < 30 ~ 3, - param == "BMI" & aval >= 30 & aval < 35 ~ 4, - param == "BMI" & aval >= 35 & aval < 40 ~ 5, - param == "BMI" & aval >= 40 ~ 6, - TRUE ~ NA_real_ - ) -} +avalcat_lookup <- exprs( + ~PARAMCD, ~condition, ~AVALCAT1, ~AVALCA1N, + "BMI", AVAL < 18.5, "Underweight", 1, + "BMI", AVAL >= 18.5 & AVAL < 25, "Normal weight", 2, + "BMI", AVAL >= 25 & AVAL < 30, "Overweight", 3, + "BMI", AVAL >= 30 & AVAL < 35, "Obesity class I", 4, + "BMI", AVAL >= 35 & AVAL < 40, "Obesity class II", 5, + "BMI", AVAL >= 40, "Obesity class III", 6, + "BMI", is.na(AVAL), NA_character_, NA_integer_ +) +# Derive BMI class (AVALCAT1, AVALCA1N) advs <- advs %>% - mutate(AVALCA1N = format_avalcat1n(param = PARAMCD, aval = AVAL)) %>% - derive_vars_merged( - avalcat_lookup, - by = exprs(PARAMCD, AVALCA1N) + derive_vars_cat( + definition = avalcat_lookup, + by_vars = exprs(PARAMCD) ) + + ``` ```{r eval=TRUE, echo=FALSE} @@ -283,33 +279,23 @@ dataset_vignette( In a similar way, we will create `BASECATy`/ `BASECAvN` variables. ```{r eval=TRUE} -basecat_lookup <- tibble::tribble( - ~PARAMCD, ~BASECA1N, ~BASECAT1, - "BMI", 1, "Underweight", - "BMI", 2, "Normal weight", - "BMI", 3, "Overweight", - "BMI", 4, "Obesity class I", - "BMI", 5, "Obesity class II", - "BMI", 6, "Obesity class III", - "BMI", NA, NA_character_ + +basecat_lookup <- exprs( + ~PARAMCD, ~condition, ~BASECAT1, ~BASECA1N, + "BMI", BASE < 18.5, "Underweight", 1, + "BMI", BASE >= 18.5 & BASE < 25, "Normal weight", 2, + "BMI", BASE >= 25 & BASE < 30, "Overweight", 3, + "BMI", BASE >= 30 & BASE < 35, "Obesity class I", 4, + "BMI", BASE >= 35 & BASE < 40, "Obesity class II", 5, + "BMI", BASE >= 40, "Obesity class III", 6, + "BMI", is.na(BASE), NA_character_, NA_integer_ ) -format_basecat1n <- function(param, base) { - case_when( - param == "BMI" & base < 18.5 ~ 1, - param == "BMI" & base >= 18.5 & base < 25 ~ 2, - param == "BMI" & base >= 25 & base < 30 ~ 3, - param == "BMI" & base >= 30 & base < 35 ~ 4, - param == "BMI" & base >= 35 & base < 40 ~ 5, - param == "BMI" & base >= 40 ~ 6, - TRUE ~ NA_real_ - ) -} +# Derive baseline BMI class (BASECAT1, BASECA1N) advs <- advs %>% - mutate(BASECA1N = format_basecat1n(param = PARAMCD, base = BASE)) %>% - derive_vars_merged( - basecat_lookup, - by = exprs(PARAMCD, BASECA1N) + derive_vars_cat( + definition = basecat_lookup, + by_vars = exprs(PARAMCD) ) ``` From cf7bac489c2c9f98725ad0cc208254f981fcd3ef Mon Sep 17 00:00:00 2001 From: "SPUJ (Siddhesh Pujari)" Date: Sat, 26 Oct 2024 14:33:03 +0200 Subject: [PATCH 4/4] #28: Styler update --- vignettes/advs.Rmd | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vignettes/advs.Rmd b/vignettes/advs.Rmd index 6cbd500..7031522 100644 --- a/vignettes/advs.Rmd +++ b/vignettes/advs.Rmd @@ -246,7 +246,6 @@ For deriving categorization variables (`AVALCATx`, `BASECATx`) documentation of the function for details). ```{r eval=TRUE} - avalcat_lookup <- exprs( ~PARAMCD, ~condition, ~AVALCAT1, ~AVALCA1N, "BMI", AVAL < 18.5, "Underweight", 1, @@ -264,8 +263,6 @@ advs <- advs %>% definition = avalcat_lookup, by_vars = exprs(PARAMCD) ) - - ``` ```{r eval=TRUE, echo=FALSE} @@ -279,7 +276,6 @@ dataset_vignette( In a similar way, we will create `BASECATy`/ `BASECAvN` variables. ```{r eval=TRUE} - basecat_lookup <- exprs( ~PARAMCD, ~condition, ~BASECAT1, ~BASECA1N, "BMI", BASE < 18.5, "Underweight", 1,