From c048d0341ec375f8819aa11c33aa6c8a84f6d134 Mon Sep 17 00:00:00 2001 From: Jeffrey Dickinson Date: Tue, 13 Jun 2023 21:41:14 +0000 Subject: [PATCH 1/5] feat: #1228 Produce BMI records for more visits: Add constant_height parameter --- R/derive_advs_params.R | 138 +++++-- man/derive_param_bmi.Rd | 35 +- man/derive_param_bsa.Rd | 33 +- tests/testthat/test-derive_advs_params.R | 456 +++++++++++++++-------- 4 files changed, 479 insertions(+), 183 deletions(-) diff --git a/R/derive_advs_params.R b/R/derive_advs_params.R index 1c269ea56f..d7b5bbd2d7 100644 --- a/R/derive_advs_params.R +++ b/R/derive_advs_params.R @@ -255,6 +255,15 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' #' Permitted Values: character value #' +#' @param constant_height HEIGHT parameter is constant +#' +#' If the HEIGHT value is considered constant (e.g. measured once at screening), +#' the values of BSA will be calculated for each WEIGHT value. +#' +#' Permitted Values: logical scalar +#' +#' Default Values: FALSE +#' #' @inheritParams derive_param_computed #' #' @inheritParams derive_param_qtc @@ -305,6 +314,19 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' ), #' get_unit_expr = extract_unit(PARAM) #' ) +#' +#' derive_param_bsa( +#' advs, +#' by_vars = exprs(USUBJID, VISIT), +#' method = "Mosteller", +#' set_values_to = exprs( +#' PARAMCD = "BSA", +#' PARAM = "Body Surface Area (m^2)" +#' ), +#' get_unit_expr = extract_unit(PARAM), +#' constant_height = TRUE, +#' constant_by_vars = exprs(USUBJID) +#' ) derive_param_bsa <- function(dataset, by_vars, method, @@ -312,7 +334,9 @@ derive_param_bsa <- function(dataset, height_code = "HEIGHT", weight_code = "WEIGHT", get_unit_expr, - filter = NULL) { + filter = NULL, + constant_height = FALSE, + constant_by_vars = NULL) { assert_vars(by_vars) assert_data_frame(dataset, required_vars = exprs(!!!by_vars, PARAMCD, AVAL)) assert_character_scalar( @@ -328,6 +352,8 @@ derive_param_bsa <- function(dataset, assert_character_scalar(weight_code) get_unit_expr <- assert_expr(enexpr(get_unit_expr)) filter <- assert_filter_cond(enexpr(filter), optional = TRUE) + assert_vars(constant_by_vars, optional = TRUE) + assert_logical_scalar(constant_height) assert_unit( dataset, @@ -350,14 +376,33 @@ derive_param_bsa <- function(dataset, ) ) - derive_param_computed( - dataset, - filter = !!filter, - parameters = c(height_code, weight_code), - by_vars = by_vars, - analysis_value = !!bsa_formula, - set_values_to = set_values_to - ) + if (constant_height == FALSE) { + derive_param_computed( + dataset, + filter = !!filter, + parameters = c(height_code, weight_code), + by_vars = by_vars, + analysis_value = !!bsa_formula, + set_values_to = set_values_to + ) + } else { + if (is.null(constant_by_vars)) { + abort( + "constant_by_vars is expected when constant_height is TRUE" + ) + } else { + derive_param_computed( + dataset, + filter = !!filter, + parameters = c(weight_code), + by_vars = by_vars, + analysis_value = !!bsa_formula, + set_values_to = set_values_to, + constant_parameters = c(height_code), + constant_by_vars = constant_by_vars + ) + } + } } #' Compute Body Surface Area (BSA) @@ -486,6 +531,15 @@ compute_bsa <- function(height = height, #' #' Permitted Values: character value #' +#' @param constant_height HEIGHT parameter is constant +#' +#' If the HEIGHT value is considered constant (e.g. measured once at screening), +#' the values of BSA will be calculated for each WEIGHT value. +#' +#' Permitted Values: logical scalar +#' +#' Default Values: FALSE +#' #' @inheritParams derive_param_computed #' #' @inheritParams derive_param_qtc @@ -530,13 +584,30 @@ compute_bsa <- function(height = height, #' ), #' get_unit_expr = extract_unit(PARAM) #' ) +#' +#' # Example 2: Derive BMI where height is measured only once +#' derive_param_bmi( +#' advs, +#' by_vars = exprs(USUBJID, AVISIT), +#' weight_code = "WEIGHT", +#' height_code = "HEIGHT", +#' set_values_to = exprs( +#' PARAMCD = "BMI", +#' PARAM = "Body Mass Index (kg/m^2)" +#' ), +#' get_unit_expr = extract_unit(PARAM), +#' constant_height = TRUE, +#' constant_by_vars = exprs(USUBJID) +#' ) derive_param_bmi <- function(dataset, by_vars, set_values_to = exprs(PARAMCD = "BMI"), weight_code = "WEIGHT", height_code = "HEIGHT", get_unit_expr, - filter = NULL) { + filter = NULL, + constant_height = FALSE, + constant_by_vars = NULL) { assert_vars(by_vars) assert_data_frame(dataset, required_vars = exprs(!!!by_vars, PARAMCD, AVAL)) assert_varval_list(set_values_to, required_elements = "PARAMCD") @@ -545,6 +616,9 @@ derive_param_bmi <- function(dataset, assert_character_scalar(height_code) get_unit_expr <- assert_expr(enexpr(get_unit_expr)) filter <- assert_filter_cond(enexpr(filter), optional = TRUE) + assert_vars(constant_by_vars, optional = TRUE) + assert_logical_scalar(constant_height) + assert_unit( dataset, @@ -559,17 +633,39 @@ derive_param_bmi <- function(dataset, get_unit_expr = !!get_unit_expr ) - derive_param_computed( - dataset, - filter = !!filter, - parameters = c(weight_code, height_code), - by_vars = by_vars, - analysis_value = compute_bmi( - height = !!sym(paste0("AVAL.", height_code)), - weight = !!sym(paste0("AVAL.", weight_code)) - ), - set_values_to = set_values_to - ) + if (constant_height == FALSE) { + derive_param_computed( + dataset, + filter = !!filter, + parameters = c(weight_code, height_code), + by_vars = by_vars, + analysis_value = compute_bmi( + height = !!sym(paste0("AVAL.", height_code)), + weight = !!sym(paste0("AVAL.", weight_code)) + ), + set_values_to = set_values_to + ) + } else { + if (is.null(constant_by_vars)) { + abort( + "constant_by_vars is expected when constant_height is TRUE" + ) + } else { + derive_param_computed( + dataset, + filter = !!filter, + parameters = c(weight_code), + by_vars = by_vars, + analysis_value = compute_bmi( + height = !!sym(paste0("AVAL.", height_code)), + weight = !!sym(paste0("AVAL.", weight_code)) + ), + set_values_to = set_values_to, + constant_parameters = c(height_code), + constant_by_vars = constant_by_vars + ) + } + } } #' Compute Body Mass Index (BMI) diff --git a/man/derive_param_bmi.Rd b/man/derive_param_bmi.Rd index fb8a3ee12e..d1161e54e2 100644 --- a/man/derive_param_bmi.Rd +++ b/man/derive_param_bmi.Rd @@ -11,7 +11,9 @@ derive_param_bmi( weight_code = "WEIGHT", height_code = "HEIGHT", get_unit_expr, - filter = NULL + filter = NULL, + constant_height = FALSE, + constant_by_vars = NULL ) } \arguments{ @@ -67,6 +69,22 @@ new parameter, i.e., only observations fulfilling the condition are taken into account. \emph{Permitted Values:} a condition} + +\item{constant_height}{HEIGHT parameter is constant + +If the HEIGHT value is considered constant (e.g. measured once at screening), +the values of BSA will be calculated for each WEIGHT value. + +Permitted Values: logical scalar + +Default Values: FALSE} + +\item{constant_by_vars}{By variables for constant parameters + +The constant parameters (parameters that are measured only once) are merged +to the other parameters using the specified variables. (Refer to Example 2) + +\emph{Permitted Values:} list of variables} } \value{ The input dataset with the new parameter added. Note, a variable will only @@ -108,6 +126,21 @@ derive_param_bmi( ), get_unit_expr = extract_unit(PARAM) ) + +# Example 2: Derive BMI where height is measured only once +derive_param_bmi( + advs, + by_vars = exprs(USUBJID, AVISIT), + weight_code = "WEIGHT", + height_code = "HEIGHT", + set_values_to = exprs( + PARAMCD = "BMI", + PARAM = "Body Mass Index (kg/m^2)" + ), + get_unit_expr = extract_unit(PARAM), + constant_height = TRUE, + constant_by_vars = exprs(USUBJID) +) } \seealso{ BDS-Findings Functions for adding Parameters/Records: diff --git a/man/derive_param_bsa.Rd b/man/derive_param_bsa.Rd index 9fd45fd2c1..49dde86316 100644 --- a/man/derive_param_bsa.Rd +++ b/man/derive_param_bsa.Rd @@ -12,7 +12,9 @@ derive_param_bsa( height_code = "HEIGHT", weight_code = "WEIGHT", get_unit_expr, - filter = NULL + filter = NULL, + constant_height = FALSE, + constant_by_vars = NULL ) } \arguments{ @@ -87,6 +89,22 @@ new parameter, i.e., only observations fulfilling the condition are taken into account. \emph{Permitted Values:} a condition} + +\item{constant_height}{HEIGHT parameter is constant + +If the HEIGHT value is considered constant (e.g. measured once at screening), +the values of BSA will be calculated for each WEIGHT value. + +Permitted Values: logical scalar + +Default Values: FALSE} + +\item{constant_by_vars}{By variables for constant parameters + +The constant parameters (parameters that are measured only once) are merged +to the other parameters using the specified variables. (Refer to Example 2) + +\emph{Permitted Values:} list of variables} } \value{ The input dataset with the new parameter added. Note, a variable will only @@ -135,6 +153,19 @@ derive_param_bsa( ), get_unit_expr = extract_unit(PARAM) ) + +derive_param_bsa( + advs, + by_vars = exprs(USUBJID, VISIT), + method = "Mosteller", + set_values_to = exprs( + PARAMCD = "BSA", + PARAM = "Body Surface Area (m^2)" + ), + get_unit_expr = extract_unit(PARAM), + constant_height = TRUE, + constant_by_vars = exprs(USUBJID) +) } \seealso{ BDS-Findings Functions for adding Parameters/Records: diff --git a/tests/testthat/test-derive_advs_params.R b/tests/testthat/test-derive_advs_params.R index 0bec22a8d4..48a667993e 100644 --- a/tests/testthat/test-derive_advs_params.R +++ b/tests/testthat/test-derive_advs_params.R @@ -1,20 +1,23 @@ -# compute_bmi: (Test 01.xx) ---- +# compute_bmi ---- -test_that("compute_bmi Test 01.01: BMI calculation - single height and weight values", { +## Test 1: BMI calculation - single height & weight values ---- +test_that("compute_bmi Test 1: BMI calculation - single height & weight values", { # Expected values are taken from the Center of Disease Control and Prevention's # (CDC) 'Adult BMI Calculator' at # https://cdc.gov/healthyweight/assessing/bmi/adult_bmi/metric_bmi_calculator/bmi_calculator.html expect_equal(round(compute_bmi(height = 180, weight = 75), 3L), 23.148) }) -test_that("compute_bmi Test 01.02: BMI calculation - height and weight vectors", { +## Test 2: compute_bmi BMI calculation - height & weight vectors ---- +test_that("compute_bmi Test 2: compute_bmi BMI calculation - height & weight vectors", { expect_equal( round(compute_bmi(height = c(180, 200), weight = c(75, 100)), 3L), c(23.148, 25) ) }) -test_that("compute_bmi Test 01.03: BMI calculation - height and weight vectors - missing values", { +## Test 3: BMI height & weight vectors - missing values ---- +test_that("compute_bmi Test 3: BMI height & weight vectors - missing values", { expect_equal( compute_bmi(height = c(NA, 200, 0), weight = c(75, NA, 75)), c(NA_real_, NA_real_, NA_real_) @@ -23,48 +26,54 @@ test_that("compute_bmi Test 01.03: BMI calculation - height and weight vectors - # compute_bsa ---- -## compute_bsa: Mosteller method (Test 01.xx) ---- +## compute_bsa: Mosteller method ---- # sqrt (Height x Weight / 3600) -test_that("compute_bsa Test 01.01: Mosteller method - single height and weight values", { +## Test 4: Mosteller method - single height & weight values ---- +test_that("compute_bsa Test 4: Mosteller method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "Mosteller"), 3L), 1.882 ) }) -test_that("compute_bsa Test 01.02: Mosteller method - height and weight vectors", { +## Test 5: Mosteller method - height & weight vectors ---- +test_that("compute_bsa Test 5: Mosteller method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "Mosteller"), 3L), c(1.882, 2.151) ) }) -test_that("compute_bsa Test 01.03: Mosteller method - height and weight vectors - missing values", { +## Test 6: Mosteller method - height & weight vectors - missing values ---- +test_that("compute_bsa Test 6: Mosteller method - height & weight vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "Mosteller"), c(NA_real_, NA_real_) ) }) -## compute_bsa: DuBois-DuBois method (Test 02.xx) ---- +## compute_bsa: DuBois-DuBois method ---- # FORMULA : 0.20247 x (HGT/100)^0.725 x WGT^0.425 -test_that("compute_bsa Test 02.01: DuBois-DuBois method - single height and weight values", { +## Test 7: DuBois-DuBois method - single height & weight values ---- +test_that("compute_bsa Test 7: DuBois-DuBois method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "DuBois-DuBois"), 3L), 1.864 ) }) -test_that("compute_bsa Test 02.02: DuBois-DuBois method - height and weight vectors", { +## Test 8: DuBois-DuBois method - height & weight vectors ---- +test_that("compute_bsa Test 8: DuBois-DuBois method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "DuBois-DuBois"), 3L), c(1.864, 2.141) ) }) -test_that("compute_bsa Test 02.03: DuBois-DuBois method - hgt and wgt vectors - missing values", { +## Test 9: DuBois-DuBois method - hgt and wgt vectors - missing values ---- +test_that("compute_bsa Test 9: DuBois-DuBois method - hgt and wgt vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "DuBois-DuBois"), c(NA_real_, NA_real_) @@ -74,129 +83,142 @@ test_that("compute_bsa Test 02.03: DuBois-DuBois method - hgt and wgt vectors - ## compute_bsa: Haycock method (Test 03.xx) ---- # 0.024265 x HGT^0.3964 x WGT^0.5378 -test_that("compute_bsa Test 03.01: Haycock method - single height and weight values", { +## Test 10: Haycock method - single height & weight values ---- +test_that("compute_bsa Test 10: Haycock method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "Haycock"), 3L), 1.895 ) }) -test_that("compute_bsa Test 03.02: Haycock method - height and weight vectors", { +## Test 11: Haycock method - height & weight vectors ---- +test_that("compute_bsa Test 11: Haycock method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "Haycock"), 3L), c(1.895, 2.161) ) }) -test_that("compute_bsa Test 03.03: Haycock method - height and weight vectors - missing values", { +## Test 12: Haycock method - height & weight vectors - missing values ---- +test_that("compute_bsa Test 12: Haycock method - height & weight vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "Haycock"), c(NA_real_, NA_real_) ) }) -## compute_bsa: Gehan-George method (Test 04.xx) ---- +## compute_bsa: Gehan-George method ---- # 0.0235 x HGT^0.42246 x WGT^0.51456 -test_that("compute_bsa Test 04.01: Gehan-George method - single height and weight values", { +## Test 13: Gehan-George method - single height & weight values ---- +test_that("compute_bsa Test 13: Gehan-George method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "Gehan-George"), 3L), 1.897 ) }) -test_that("compute_bsa Test 04.02: Gehan-George method - height and weight vectors", { +## Test 14: Gehan-George method - height & weight vectors ---- +test_that("compute_bsa Test 14: Gehan-George method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "Gehan-George"), 3L), c(1.897, 2.16) ) }) -test_that(paste( - "compute_bsa Test 04.03: Gehan-George method - height and", - "weight vectors - missing values" -), { +## Test 15: Gehan-George method - height & weight vectors - missing values ---- +test_that("compute_bsa Test 15: Gehan-George method - height & weight vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "Gehan-George"), c(NA_real_, NA_real_) ) }) -## compute_bsa: Boyd method (Test 05.xx) ---- +## compute_bsa: Boyd method ---- # 0.0003207 x (HGT^0.3) x (1000 x WGT)^(0.7285 - (0.0188 x log10(1000 x WGT))) -test_that("compute_bsa Test 05.01: Boyd method - single height and weight values", { +## Test 16: Boyd method - single height & weight values ---- +test_that("compute_bsa Test 16: Boyd method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "Boyd"), 3L), 1.905 ) }) -test_that("compute_bsa Test 05.02: Boyd method - height and weight vectors", { +## Test 17: Boyd method - height & weight vectors ---- +test_that("compute_bsa Test 17: Boyd method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "Boyd"), 3L), c(1.905, 2.158) ) }) -test_that("compute_bsa Test 05.03: Boyd method - height and weight vectors - missing values", { +## Test 18: Boyd method - height & weight vectors - missing values ---- +test_that("compute_bsa Test 18: Boyd method - height & weight vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "Boyd"), c(NA_real_, NA_real_) ) }) -## compute_bsa: Fujimoto method (Test 06.xx) ---- +## compute_bsa: Fujimoto method ---- # 0.008883 x HGT^0.663 x WGT^0.444 -test_that("compute_bsa Test 06.01: Fujimoto method - single height and weight values", { +## Test 19: Fujimoto method - single height & weight values ---- +test_that("compute_bsa Test 19: Fujimoto method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "Fujimoto"), 3L), 1.819 ) }) -test_that("compute_bsa Test 06.02: Fujimoto method - height and weight vectors", { +## Test 20: Fujimoto method - height & weight vectors ---- +test_that("compute_bsa Test 20: Fujimoto method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "Fujimoto"), 3L), c(1.819, 2.086) ) }) -test_that("compute_bsa Test 06.03: Fujimoto method - height and weight vectors - missing values", { +## Test 21: Fujimoto method - height & weight vectors - missing values ---- +test_that("compute_bsa Test 21: Fujimoto method - height & weight vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "Fujimoto"), c(NA_real_, NA_real_) ) }) -## compute_bsa: Takahira method (Test 07.xx) ---- +## compute_bsa: Takahira method ---- # 0.007241 x HGT^0.725 x WGT^0.425 -test_that("compute_bsa Test 07.01: Takahira method - single height and weight values", { +## Test 22: Takahira method - single height & weight values ---- +test_that("compute_bsa Test 22: Takahira method - single height & weight values", { expect_equal( round(compute_bsa(height = 170, weight = 75, method = "Takahira"), 3L), 1.878 ) }) -test_that("compute_bsa Test 07.02: Takahira method - height and weight vectors", { +## Test 23: Takahira method - height & weight vectors ---- +test_that("compute_bsa Test 23: Takahira method - height & weight vectors", { expect_equal( round(compute_bsa(height = c(170, 185), weight = c(75, 90), method = "Takahira"), 3L), c(1.878, 2.158) ) }) -test_that("compute_bsa Test 07.03: Takahira method - height and weight vectors - missing values", { +## Test 24: Takahira method - height & weight vectors - missing values ---- +test_that("compute_bsa Test 24: Takahira method - height & weight vectors - missing values", { expect_equal( compute_bsa(height = c(NA, 185), weight = c(75, NA), method = "Takahira"), c(NA_real_, NA_real_) ) }) -## compute_bsa: Check error messages (Test 08.xx) ---- +## compute_bsa: Check error messages ---- -test_that("compute_bsa Test 08.01: an error is issued if an invalid method is specified", { +## Test 25: an error is issued if an invalid method is specified ---- +test_that("compute_bsa Test 25: an error is issued if an invalid method is specified", { expect_error( compute_bsa(height = c(170, 185), weight = c(75, 90), method = "unknown-method"), paste( @@ -208,74 +230,60 @@ test_that("compute_bsa Test 08.01: an error is issued if an invalid method is sp # compute_map ---- -## compute_map: DBP & SBP (Test 01.xx) ---- +## compute_map: DBP & SBP ---- # ((2 x DBP) + SBP) / 3 -test_that(paste( - "compute_map Test 01.01: Mean Arterial Pressure based on diastolic", - "& systolic BP - single values" -), { +## Test 26: MAP based on diastolic & systolic BP - single values ---- +test_that("compute_map Test 26: MAP based on diastolic & systolic BP - single values", { expect_equal(round(compute_map(diabp = 51, sysbp = 121), 3L), 74.333) }) -test_that(paste( - "compute_map Test 01.02: Mean Arterial Pressure based on diastolic", - "& systolic BP - vectors" -), { +## Test 27: MAP based on diastolic & systolic BP - vectors ---- +test_that("compute_map Test 27: MAP based on diastolic & systolic BP - vectors", { expect_equal( round(compute_map(diabp = c(51, 61), sysbp = c(121, 141)), 3L), c(74.333, 87.667) ) }) -test_that(paste( - "compute_map Test 01.03: Mean Arterial Pressure based on diastolic", - "& systolic BP - vectors with missing values" -), { +## Test 28: MAP based on diastolic & systolic BP with missing values ---- +test_that("compute_map Test 28: MAP based on diastolic & systolic BP with missing values", { expect_equal( compute_map(diabp = c(NA, 61), sysbp = c(121, NA)), c(NA_real_, NA_real_) ) }) -## compute_map: DBP, SBP & HR (Test 02.xx) ---- +## compute_map: DBP, SBP & HR ---- # DBP + 0.01 x exp(4.14 - 40.74 / PULSE) x (SBP - DBP) -test_that(paste( - "compute_map Test 02.01: Mean Arterial Pressure based on diastolic,", - "systolic BP & heart rate - single values" -), { +## Test 29: MAP based on DBP & SBP & heart rate - single values ---- +test_that("compute_map Test 29: MAP based on DBP & SBP & heart rate - single values", { expect_equal( round(compute_map(diabp = 51, sysbp = 121, hr = 59), 3L), 73.039 ) }) -test_that(paste( - "compute_map Test 02.02: Mean Arterial Pressure based on diastolic,", - "systolic BP & heart rate - vectors" -), { +## Test 30: MAP based on diastolic, systolic BP & heart rate - vectors ---- +test_that("compute_map Test 30: MAP based on diastolic, systolic BP & heart rate - vectors", { expect_equal( round(compute_map(diabp = c(51, 91), sysbp = c(121, 101), hr = c(59, 62)), 3L), c(73.039, 94.255) ) }) -test_that(paste( - "compute_map Test 02.03: Mean Arterial Pressure based on diastolic,", - "systolic blood BP & heart rate - vectors with missing values" -), { +## Test 31: MAP based on DBP, SBP & heart rate - with missing values ---- +test_that("compute_map Test 31: MAP based on DBP, SBP & heart rate - with missing values", { expect_equal( compute_map(diabp = c(NA, 61, 51), sysbp = c(121, NA, 121), hr = c(59, 62, NA)), c(NA_real_, NA_real_, NA_real_) ) }) -# derive_param_bmi ---- +# derive_param_bmi ---- -## derive_param_bmi: Error checks (Test 01.xx) ---- +## derive_param_bmi: Error checks ---- -test_that(paste( - "derive_param_bmi Test 01.01: BMI parameter NOT added to input dataset", - "- wrong unit for hgt" -), { +## Test 32: BMI parameter NOT added - wrong hgt unit ---- +test_that("derive_param_bmi Test 32: BMI parameter NOT added - wrong hgt unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, # Wrong unit for HEIGHT should be cm @@ -292,10 +300,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_bmi Test 01.02: BMI parameter NOT added to input dataset", - "- wrong unit for wgt" -), { +## Test 33: BMI parameter NOT added - wrong wgt unit ---- +test_that("derive_param_bmi Test 33: BMI parameter NOT added - wrong wgt unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -312,10 +318,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_bmi Test 01.03: BMI parameter NOT added to input dataset", - "- multiple unit for wgt" -), { +## Test 34: BMI parameter NOT added - multiple unit for wgt ---- +test_that("derive_param_bmi Test 34: BMI parameter NOT added - multiple unit for wgt", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -333,10 +337,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_bmi Test 01.04: BMI parameter NOT added to input dataset", - "- PARAMCD not set" -), { +## Test 35: BMI parameter NOT added - PARAMCD not set ---- +test_that("derive_param_bmi Test 35: BMI parameter NOT added - PARAMCD not set", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -354,9 +356,10 @@ test_that(paste( ) }) -## derive_param_bmi: No obs added (Test 02.xx) ---- +## derive_param_bmi: No obs added ---- -test_that("derive_param_bmi Test 02.01: BMI parameter NOT added to input dataset", { +## Test 36: BMI parameter NOT added ---- +test_that("derive_param_bmi Test 36: BMI parameter NOT added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -378,13 +381,14 @@ test_that("derive_param_bmi Test 02.01: BMI parameter NOT added to input dataset ) }) -## derive_param_bmi: Obs created (Test 03.xx) ---- +## derive_param_bmi: Obs created ---- bmi <- function(hgt, wgt) { wgt / (hgt / 100)^2 } -test_that("derive_param_bmi Test 03.01: BMI parameter is correctly added to input dataset", { +## Test 37: BMI parameter is correctly added ---- +test_that("derive_param_bmi Test 37: BMI parameter is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -410,14 +414,94 @@ test_that("derive_param_bmi Test 03.01: BMI parameter is correctly added to inpu ) }) + +# Derive BMI where height is measured only once +## Test 38: Derive BMI where height is measured only once ---- +test_that("derive_param_bmi Test 38: Derive BMI where height is measured only once", { + input <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, + "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "kg", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "kg", "BASELINE", + "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "kg", "WEEK 2", + "01-701-1028", "HEIGHT", "Height (cm)", 163.0, "cm", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "kg", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "kg", "BASELINE", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "kg", "WEEK 2" + ) + + expected_output <- derive_param_computed( + input, + by_vars = exprs(USUBJID, VISIT), + parameters = "WEIGHT", + analysis_value = AVAL.WEIGHT / (AVAL.HEIGHT / 100)^2, + set_values_to = exprs( + PARAMCD = "BMI", + PARAM = "Body Mass Index (kg/m^2)", + AVALU = "kg/m^2" + ), + constant_parameters = c("HEIGHT"), + constant_by_vars = exprs(USUBJID) + ) + + expect_dfs_equal( + expected_output, + derive_param_bmi( + input, + by_vars = exprs(USUBJID, VISIT), + weight_code = "WEIGHT", + height_code = "HEIGHT", + set_values_to = exprs( + PARAMCD = "BMI", + PARAM = "Body Mass Index (kg/m^2)", + AVALU = "kg/m^2" + ), + get_unit_expr = extract_unit(PARAM), + constant_height = TRUE, + constant_by_vars = exprs(USUBJID) + ), + keys = c("USUBJID", "PARAMCD", "VISIT") + ) +}) + +## Test 39: constant_by_vars is expected when constant_height is TRUE ---- +test_that("derive_param_bmi Test 39: constant_by_vars is expected when constant_height is TRUE", { + input <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, + "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "kg", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "kg", "BASELINE", + "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "kg", "WEEK 2", + "01-701-1028", "HEIGHT", "Height (cm)", 163.0, "cm", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "kg", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "kg", "BASELINE", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "kg", "WEEK 2" + ) + + expect_error( + derive_param_bmi( + input, + by_vars = exprs(USUBJID, VISIT), + weight_code = "WEIGHT", + height_code = "HEIGHT", + set_values_to = exprs( + PARAMCD = "BMI", + PARAM = "Body Mass Index (kg/m^2)", + AVALU = "kg/m^2" + ), + get_unit_expr = extract_unit(PARAM), + constant_height = TRUE + ), + "constant_by_vars is expected when constant_height is TRUE" + ) +}) + # derive_param_bsa ---- -## derive_param_bsa: Error checks (Test 01.xx) ---- +## derive_param_bsa: Error checks ---- -test_that(paste( - "derive_param_bsa Test 01.01: BSA parameter NOT added to input dataset", - "- wrong unit for height" -), { +## Test 40: BSA parameter NOT added - wrong unit for height ---- +test_that("derive_param_bsa Test 40: BSA parameter NOT added - wrong unit for height", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, # Wrong unit for HEIGHT should be cm @@ -439,10 +523,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_bsa Test 01.02: BSA parameter NOT added to input dataset", - "- wrong unit for weight" -), { +## Test 41: BSA parameter NOT added - wrong unit for weight ---- +test_that("derive_param_bsa Test 41: BSA parameter NOT added - wrong unit for weight", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -464,10 +546,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_bsa Test 01.03: BSA parameter NOT added to input dataset", - "- multiple unit for weight" -), { +## Test 42: BSA parameter NOT added - multiple unit for weight ---- +test_that("derive_param_bsa Test 42: BSA parameter NOT added - multiple unit for weight", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -490,10 +570,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_bsa Test 01.04: BSA parameter NOT added to input dataset", - "- PARAMCD not set" -), { +## Test 43: BSA parameter NOT added - PARAMCD not set ---- +test_that("derive_param_bsa Test 43: BSA parameter NOT added - PARAMCD not set", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -515,9 +593,10 @@ test_that(paste( ) }) -## derive_param_bsa: No obs added (Test 02.xx) ---- +## derive_param_bsa: No obs added ---- -test_that("derive_param_bsa Test 02.01: BSA parameter NOT added to input dataset", { +## Test 44: BSA parameter NOT added ---- +test_that("derive_param_bsa Test 44: BSA parameter NOT added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -544,16 +623,14 @@ test_that("derive_param_bsa Test 02.01: BSA parameter NOT added to input dataset ) }) -## derive_param_bsa: Obs created (Test 03.xx) ---- +## derive_param_bsa: Obs created ---- mosteller <- function(hgt, wgt) { sqrt(hgt * wgt / 3600) } -test_that(paste( - "derive_param_bsa Test 03.01: BSA parameter (Mosteller method) is", - "correctly added to input dataset" -), { +## Test 45: BSA parameter (Mosteller Method) is correctly added ---- +test_that("derive_param_bsa Test 45: BSA parameter (Mosteller Method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -587,10 +664,8 @@ dubois <- function(hgt, wgt) { 0.20247 * (hgt / 100)^0.725 * wgt^0.425 } -test_that(paste( - "derive_param_bsa Test 03.02: BSA parameter (DuBois-DuBois method)", - "is correctly added to input dataset" -), { +## Test 46: BSA parameter (DuBois-DuBois method) is correctly added ---- +test_that("derive_param_bsa Test 46: BSA parameter (DuBois-DuBois method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -625,10 +700,8 @@ haycock <- function(hgt, wgt) { 0.024265 * hgt^0.3964 * wgt^0.5378 } -test_that(paste( - "derive_param_bsa Test 03.03: BSA parameter (Haycock method) is", - "correctly added to input dataset" -), { +## Test 47: BSA parameter (Haycock method) is correctly added ---- +test_that("derive_param_bsa Test 47: BSA parameter (Haycock method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -662,10 +735,8 @@ gehan <- function(hgt, wgt) { 0.0235 * hgt^0.42246 * wgt^0.51456 } -test_that(paste( - "derive_param_bsa Test 03.04: BSA parameter (Gehan-George method)", - "is correctly added to input dataset" -), { +## Test 48: BSA parameter (Gehan-George method) is correctly added ---- +test_that("derive_param_bsa Test 48: BSA parameter (Gehan-George method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -700,10 +771,8 @@ boyd <- function(hgt, wgt) { 0.0003207 * (hgt^0.3) * (1000 * wgt)^(0.7285 - (0.0188 * log10(1000 * wgt))) # nolint } -test_that(paste( - "derive_param_bsa Test 03.05: BSA parameter (Boyd method) is ", - "correctly added to input dataset" -), { +## Test 49: BSA parameter (Boyd method) is correctly added ---- +test_that("derive_param_bsa Test 49: BSA parameter (Boyd method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -737,10 +806,8 @@ fujimoto <- function(hgt, wgt) { 0.008883 * hgt^0.663 * wgt^0.444 } -test_that(paste( - "derive_param_bsa Test 03.06: BSA parameter (Fujimoto method) is", - "correctly added to input dataset" -), { +## Test 50: BSA parameter (Fujimoto method) is correctly added ---- +test_that("derive_param_bsa Test 50: BSA parameter (Fujimoto method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -774,10 +841,9 @@ test_that(paste( takahira <- function(hgt, wgt) { 0.007241 * hgt^0.725 * wgt^0.425 } -test_that(paste( - "derive_param_bsa Test 03.07: BSA parameter (Takahira method) is", - "correctly added to input dataset" -), { + +## Test 51: BSA parameter (Takahira method) is correctly added ---- +test_that("derive_param_bsa Test 51: BSA parameter (Takahira method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -808,14 +874,93 @@ test_that(paste( ) }) +## Test 52: Derive BSA where height is measured only once ---- +test_that("derive_param_bsa Test 52: Derive BSA where height is measured only once", { + input <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, + "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "kg", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "kg", "BASELINE", + "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "kg", "WEEK 2", + "01-701-1028", "HEIGHT", "Height (cm)", 163.0, "cm", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "kg", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "kg", "BASELINE", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "kg", "WEEK 2" + ) + + expected_output <- derive_param_computed( + input, + by_vars = exprs(USUBJID, VISIT), + parameters = "WEIGHT", + analysis_value = compute_bsa( + height = AVAL.HEIGHT, weight = AVAL.WEIGHT, + method = "Mosteller" + ), + set_values_to = exprs( + PARAMCD = "BSA", + PARAM = "Body Surface Area (m^2)", + AVALU = "m^2" + ), + constant_parameters = c("HEIGHT"), + constant_by_vars = exprs(USUBJID) + ) + + expect_dfs_equal( + expected_output, + derive_param_bsa( + input, + by_vars = exprs(USUBJID, VISIT), + method = "Mosteller", + set_values_to = exprs( + PARAMCD = "BSA", + PARAM = "Body Surface Area (m^2)", + AVALU = "m^2" + ), + get_unit_expr = extract_unit(PARAM), + constant_height = TRUE, + constant_by_vars = exprs(USUBJID) + ), + keys = c("USUBJID", "PARAMCD", "VISIT") + ) +}) + +## Test 53: constant_by_vars is expected when constant_height is TRUE ---- +test_that("derive_param_bsa Test 53: constant_by_vars is expected when constant_height is TRUE", { + input <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, + "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "kg", "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "kg", "BASELINE", + "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "kg", "WEEK 2", + "01-701-1028", "HEIGHT", "Height (cm)", 163.0, "cm", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "kg", "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "kg", "BASELINE", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "kg", "WEEK 2" + ) + + expect_error( + derive_param_bsa( + input, + by_vars = exprs(USUBJID, VISIT), + method = "Mosteller", + set_values_to = exprs( + PARAMCD = "BSA", + PARAM = "Body Surface Area (m^2)", + AVALU = "m^2" + ), + get_unit_expr = extract_unit(PARAM), + constant_height = TRUE + ), + "constant_by_vars is expected when constant_height is TRUE" + ) +}) + # derive_param_map ---- -## derive_param_map: Error checks (Test 01.xx) ---- +## derive_param_map: Error checks ---- -test_that(paste( - "derive_param_map Test 01.01: MAP parameter NOT added to input dataset", - "- wrong unit for DIABP" -), { +## Test 54: MAP parameter NOT added - wrong DIABP unit ---- +test_that("derive_param_map Test 54: MAP parameter NOT added - wrong DIABP unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mHg)", 51, "BASELINE", @@ -835,10 +980,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_map Test 01.02: MAP parameter NOT added to input dataset", - "- wrong unit for SYSBP" -), { +## Test 55: MAP parameter NOT added - wrong SYSBP unit ---- +test_that("derive_param_map Test 55: MAP parameter NOT added - wrong SYSBP unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", 51, "BASELINE", @@ -858,10 +1001,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_map Test 01.03: MAP parameter NOT added to input dataset", - "- wrong unit for PULSE" -), { +## Test 56: MAP parameter NOT added - wrong PULSE unit ---- +test_that("derive_param_map Test 56: MAP parameter NOT added - wrong PULSE unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", 51, "BASELINE", @@ -883,10 +1024,8 @@ test_that(paste( ) }) -test_that(paste( - "derive_param_map Test 01.04: MAP parameter NOT added to input dataset", - "- PARAMCD not set" -), { +## Test 57: MAP parameter NOT added - PARAMCD not set ---- +test_that("derive_param_map Test 57: MAP parameter NOT added - PARAMCD not set", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", 51, "BASELINE", @@ -907,9 +1046,10 @@ test_that(paste( ) }) -## derive_param_map: No obs added (Test 02.xx) ---- +## derive_param_map: No obs added ---- -test_that("derive_param_map Test 02.01: MAP parameter NOT added to input dataset", { +## Test 58: MAP parameter NOT added ---- +test_that("derive_param_map Test 58: MAP parameter NOT added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", NA, "BASELINE", @@ -937,16 +1077,14 @@ test_that("derive_param_map Test 02.01: MAP parameter NOT added to input dataset ) }) -## derive_param_map: Obs created (Test 03.xx) ---- +## derive_param_map: Obs created ---- maphr <- function(sbp, dbp, hr) { dbp + 0.01 * exp(4.14 - 40.74 / hr) * (sbp - dbp) } -test_that(paste( - "derive_param_map Test 03.01: MAP parameter (DBP/SBP/PULSE) is correctly", - "added to input dataset" -), { +## Test 59: MAP parameter (DBP/SBP/PULSE) is correctly added ---- +test_that("derive_param_map Test 59: MAP parameter (DBP/SBP/PULSE) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, "01-701-1015", "PULSE", "Pulse (beats/min)", "BASELINE", 59, @@ -981,10 +1119,8 @@ map <- function(sbp, dbp) { (2 * dbp + sbp) / 3 } -test_that(paste( - "derive_param_map Test 03.02: MAP parameter (DBP/SBP) is correctly", - "added to input dataset" -), { +## Test 60: MAP parameter (DBP/SBP) is correctly added ---- +test_that("derive_param_map Test 60: MAP parameter (DBP/SBP) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", "BASELINE", 51, From c84a877b3118f1c4988fbccee56d86a8f2ce9f3a Mon Sep 17 00:00:00 2001 From: Jeffrey Dickinson Date: Thu, 15 Jun 2023 13:56:28 +0000 Subject: [PATCH 2/5] feat: #1228 Produce BMI records for more visits: Update to use constant_by_vars as switch and update examples with more detail. --- NEWS.md | 8 + R/derive_advs_params.R | 247 +++++++++++++---------- man/compute_bmi.Rd | 4 +- man/compute_bsa.Rd | 6 +- man/derive_param_bmi.Rd | 84 +++++--- man/derive_param_bsa.Rd | 62 ++++-- man/derive_param_map.Rd | 8 +- tests/testthat/test-derive_advs_params.R | 144 ++++--------- 8 files changed, 295 insertions(+), 268 deletions(-) diff --git a/NEWS.md b/NEWS.md index 95d3e2c6d3..48d076dffe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# admiral 0.12.0 + +## New Features + +## Updates of Existing Functions + +- The functions `derive_param_bmi()` and `derive_param_bsa() are updated to have the option of producing more values at visits when only weight is collected (#1228). + # admiral 0.11.0 ## New Features diff --git a/R/derive_advs_params.R b/R/derive_advs_params.R index d7b5bbd2d7..f28fcad448 100644 --- a/R/derive_advs_params.R +++ b/R/derive_advs_params.R @@ -20,21 +20,21 @@ #' The observations where `PARAMCD` equals the specified value are considered #' as the systolic blood pressure assessments. #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' @param diabp_code Diastolic blood pressure parameter code #' #' The observations where `PARAMCD` equals the specified value are considered #' as the diastolic blood pressure assessments. #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' @param hr_code Heart rate parameter code #' #' The observations where `PARAMCD` equals the specified value are considered #' as the heart rate assessments. #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' @inheritParams derive_param_computed #' @@ -62,7 +62,7 @@ #' library(tibble) #' library(dplyr, warn.conflicts = FALSE) #' -#' advs <- tribble( +#' advs <- tibble::tribble( #' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, #' "01-701-1015", "PULSE", "Pulse (beats/min)", 59, "BASELINE", #' "01-701-1015", "PULSE", "Pulse (beats/min)", 61, "WEEK 2", @@ -239,30 +239,33 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' #' Takahira: `0.007241 * height ^ 0.725 * weight ^ 0.425` #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' @param height_code HEIGHT parameter code #' #' The observations where `PARAMCD` equals the specified value are considered #' as the HEIGHT assessments. It is expected that HEIGHT is measured in cm. #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' @param weight_code WEIGHT parameter code #' #' The observations where `PARAMCD` equals the specified value are considered #' as the WEIGHT assessments. It is expected that WEIGHT is measured in kg. #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' -#' @param constant_height HEIGHT parameter is constant +#' @param constant_by_vars By variables for when HEIGHT is constant #' -#' If the HEIGHT value is considered constant (e.g. measured once at screening), -#' the values of BSA will be calculated for each WEIGHT value. +#' When HEIGHT is constant, the HEIGHT parameters (measured only once) are merged +#' to the other parameters using the specified variables. #' -#' Permitted Values: logical scalar +#' If height is constant (e.g. only measured once at screening or baseline) then +#' use `constant_by_vars` to select the subject-level variable to merge on (e.g. USUBJID). +#' This will produce BSA at all visits where weight is measured. Otherwise +#' it will only be calculated at visits with both height and weight collected. #' -#' Default Values: FALSE +#' *Permitted Values:* list of variables #' #' @inheritParams derive_param_computed #' @@ -281,7 +284,8 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' @examples #' library(tibble) #' -#' advs <- tribble( +#' # Example 1: Derive BSA where height is measured only once using constant_by_vars +#' advs <- tibble::tribble( #' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, #' "01-701-1015", "HEIGHT", "Height (cm)", 170, "BASELINE", #' "01-701-1015", "WEIGHT", "Weight (kg)", 75, "BASELINE", @@ -301,7 +305,8 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' PARAMCD = "BSA", #' PARAM = "Body Surface Area (m^2)" #' ), -#' get_unit_expr = extract_unit(PARAM) +#' get_unit_expr = extract_unit(PARAM), +#' constant_by_vars = exprs(USUBJID) #' ) #' #' derive_param_bsa( @@ -312,9 +317,36 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' PARAMCD = "BSA", #' PARAM = "Body Surface Area (m^2)" #' ), +#' get_unit_expr = extract_unit(PARAM), +#' constant_by_vars = exprs(USUBJID) +#' ) +#' +#' # Example 2: Derive BSA where height is measured only once and keep only one record +#' # where both height and weight are measured. +#' +#' derive_param_bsa( +#' advs, +#' by_vars = exprs(USUBJID, VISIT), +#' method = "Mosteller", +#' set_values_to = exprs( +#' PARAMCD = "BSA", +#' PARAM = "Body Surface Area (m^2)" +#' ), #' get_unit_expr = extract_unit(PARAM) #' ) #' +#' # Example 3: Pediatric study where height and weight are measured multiple times +#' advs <- tibble::tribble( +#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, +#' "01-101-1001", "HEIGHT", "Height (cm)", 47.1, "BASELINE", +#' "01-101-1001", "HEIGHT", "Height (cm)", 59.1, "WEEK 12", +#' "01-101-1001", "HEIGHT", "Height (cm)", 64.7, "WEEK 24", +#' "01-101-1001", "HEIGHT", "Height (cm)", 68.2, "WEEK 48", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 2.6, "BASELINE", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 5.3, "WEEK 12", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 6.7, "WEEK 24", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 7.4, "WEEK 48", +#' ) #' derive_param_bsa( #' advs, #' by_vars = exprs(USUBJID, VISIT), @@ -323,9 +355,7 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' PARAMCD = "BSA", #' PARAM = "Body Surface Area (m^2)" #' ), -#' get_unit_expr = extract_unit(PARAM), -#' constant_height = TRUE, -#' constant_by_vars = exprs(USUBJID) +#' get_unit_expr = extract_unit(PARAM) #' ) derive_param_bsa <- function(dataset, by_vars, @@ -335,7 +365,6 @@ derive_param_bsa <- function(dataset, weight_code = "WEIGHT", get_unit_expr, filter = NULL, - constant_height = FALSE, constant_by_vars = NULL) { assert_vars(by_vars) assert_data_frame(dataset, required_vars = exprs(!!!by_vars, PARAMCD, AVAL)) @@ -353,7 +382,6 @@ derive_param_bsa <- function(dataset, get_unit_expr <- assert_expr(enexpr(get_unit_expr)) filter <- assert_filter_cond(enexpr(filter), optional = TRUE) assert_vars(constant_by_vars, optional = TRUE) - assert_logical_scalar(constant_height) assert_unit( dataset, @@ -376,33 +404,24 @@ derive_param_bsa <- function(dataset, ) ) - if (constant_height == FALSE) { - derive_param_computed( - dataset, - filter = !!filter, - parameters = c(height_code, weight_code), - by_vars = by_vars, - analysis_value = !!bsa_formula, - set_values_to = set_values_to - ) + if (is.null(constant_by_vars)) { + parameters <- c(weight_code, height_code) + constant_parameters <- NULL } else { - if (is.null(constant_by_vars)) { - abort( - "constant_by_vars is expected when constant_height is TRUE" - ) - } else { - derive_param_computed( - dataset, - filter = !!filter, - parameters = c(weight_code), - by_vars = by_vars, - analysis_value = !!bsa_formula, - set_values_to = set_values_to, - constant_parameters = c(height_code), - constant_by_vars = constant_by_vars - ) - } + parameters <- c(weight_code) + constant_parameters <- c(height_code) } + + derive_param_computed( + dataset, + filter = !!filter, + parameters = parameters, + by_vars = by_vars, + analysis_value = !!bsa_formula, + set_values_to = set_values_to, + constant_parameters = constant_parameters, + constant_by_vars = constant_by_vars + ) } #' Compute Body Surface Area (BSA) @@ -413,13 +432,13 @@ derive_param_bsa <- function(dataset, #' #' It is expected that HEIGHT is in cm. #' -#' Permitted Values: numeric vector +#' *Permitted Values:* numeric vector #' #' @param weight WEIGHT value #' #' It is expected that WEIGHT is in kg. #' -#' Permitted Values: numeric vector +#' *Permitted Values:* numeric vector #' #' @param method Derivation method to use: #' @@ -437,7 +456,7 @@ derive_param_bsa <- function(dataset, #' #' Takahira: 0.007241 * height ^ 0.725 * weight ^ 0.425 #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' #' @details Usually this computation function can not be used with `%>%`. @@ -522,23 +541,28 @@ compute_bsa <- function(height = height, #' The observations where `PARAMCD` equals the specified value are considered #' as the WEIGHT. It is expected that WEIGHT is measured in kg #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' #' @param height_code HEIGHT parameter code #' #' The observations where `PARAMCD` equals the specified value are considered #' as the HEIGHT. It is expected that HEIGHT is measured in cm #' -#' Permitted Values: character value +#' *Permitted Values:* character value #' -#' @param constant_height HEIGHT parameter is constant +#' *Permitted Values:* logical scalar #' -#' If the HEIGHT value is considered constant (e.g. measured once at screening), -#' the values of BSA will be calculated for each WEIGHT value. +#' @param constant_by_vars By variables for when HEIGHT is constant #' -#' Permitted Values: logical scalar +#' When HEIGHT is constant, the HEIGHT parameters (measured only once) are merged +#' to the other parameters using the specified variables. #' -#' Default Values: FALSE +#' If height is constant (e.g. only measured once at screening or baseline) then +#' use `constant_by_vars` to select the subject-level variable to merge on (e.g. USUBJID). +#' This will produce BMI at all visits where weight is measured. Otherwise +#' it will only be calculated at visits with both height and weight collected. +#' +#' *Permitted Values:* list of variables #' #' @inheritParams derive_param_computed #' @@ -559,18 +583,18 @@ compute_bsa <- function(height = height, #' @export #' #' @examples -#' library(tibble) #' -#' advs <- tribble( -#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVISIT, -#' "01-701-1015", "HEIGHT", "Height (cm)", 147, "SCREENING", -#' "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "SCREENING", -#' "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "BASELINE", -#' "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "WEEK 2", -#' "01-701-1028", "HEIGHT", "Height (cm)", 163, "SCREENING", -#' "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "SCREENING", -#' "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "BASELINE", -#' "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "WEEK 2" +#' # Example 1: Derive BMI where height is measured only once using constant_by_vars +#' advs <- tibble::tribble( +#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVISIT, +#' "01-701-1015", "HEIGHT", "Height (cm)", 147, "SCREENING", +#' "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "SCREENING", +#' "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "BASELINE", +#' "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "WEEK 2", +#' "01-701-1028", "HEIGHT", "Height (cm)", 163, "SCREENING", +#' "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "SCREENING", +#' "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "BASELINE", +#' "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "WEEK 2" #' ) #' #' derive_param_bmi( @@ -582,10 +606,12 @@ compute_bsa <- function(height = height, #' PARAMCD = "BMI", #' PARAM = "Body Mass Index (kg/m^2)" #' ), -#' get_unit_expr = extract_unit(PARAM) +#' get_unit_expr = extract_unit(PARAM), +#' constant_by_vars = exprs(USUBJID) #' ) #' -#' # Example 2: Derive BMI where height is measured only once +#' # Example 2: Derive BMI where height is measured only once and keep only one record +#' # where both height and weight are measured. #' derive_param_bmi( #' advs, #' by_vars = exprs(USUBJID, AVISIT), @@ -595,9 +621,32 @@ compute_bsa <- function(height = height, #' PARAMCD = "BMI", #' PARAM = "Body Mass Index (kg/m^2)" #' ), -#' get_unit_expr = extract_unit(PARAM), -#' constant_height = TRUE, -#' constant_by_vars = exprs(USUBJID) +#' get_unit_expr = extract_unit(PARAM) +#' ) +#' +#' # Example 3: Pediatric study where height and weight are measured multiple times +#' advs <- tibble::tribble( +#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, +#' "01-101-1001", "HEIGHT", "Height (cm)", 47.1, "BASELINE", +#' "01-101-1001", "HEIGHT", "Height (cm)", 59.1, "WEEK 12", +#' "01-101-1001", "HEIGHT", "Height (cm)", 64.7, "WEEK 24", +#' "01-101-1001", "HEIGHT", "Height (cm)", 68.2, "WEEK 48", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 2.6, "BASELINE", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 5.3, "WEEK 12", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 6.7, "WEEK 24", +#' "01-101-1001", "WEIGHT", "Weight (kg)", 7.4, "WEEK 48", +#' ) +#' +#' derive_param_bmi( +#' advs, +#' by_vars = exprs(USUBJID, VISIT), +#' weight_code = "WEIGHT", +#' height_code = "HEIGHT", +#' set_values_to = exprs( +#' PARAMCD = "BMI", +#' PARAM = "Body Mass Index (kg/m^2)" +#' ), +#' get_unit_expr = extract_unit(PARAM) #' ) derive_param_bmi <- function(dataset, by_vars, @@ -606,7 +655,6 @@ derive_param_bmi <- function(dataset, height_code = "HEIGHT", get_unit_expr, filter = NULL, - constant_height = FALSE, constant_by_vars = NULL) { assert_vars(by_vars) assert_data_frame(dataset, required_vars = exprs(!!!by_vars, PARAMCD, AVAL)) @@ -617,7 +665,6 @@ derive_param_bmi <- function(dataset, get_unit_expr <- assert_expr(enexpr(get_unit_expr)) filter <- assert_filter_cond(enexpr(filter), optional = TRUE) assert_vars(constant_by_vars, optional = TRUE) - assert_logical_scalar(constant_height) assert_unit( @@ -633,39 +680,31 @@ derive_param_bmi <- function(dataset, get_unit_expr = !!get_unit_expr ) - if (constant_height == FALSE) { - derive_param_computed( - dataset, - filter = !!filter, - parameters = c(weight_code, height_code), - by_vars = by_vars, - analysis_value = compute_bmi( - height = !!sym(paste0("AVAL.", height_code)), - weight = !!sym(paste0("AVAL.", weight_code)) - ), - set_values_to = set_values_to + bmi_formula <- expr( + compute_bmi( + height = !!sym(paste0("AVAL.", height_code)), + weight = !!sym(paste0("AVAL.", weight_code)) ) + ) + + if (is.null(constant_by_vars)) { + parameters <- c(weight_code, height_code) + constant_parameters <- NULL } else { - if (is.null(constant_by_vars)) { - abort( - "constant_by_vars is expected when constant_height is TRUE" - ) - } else { - derive_param_computed( - dataset, - filter = !!filter, - parameters = c(weight_code), - by_vars = by_vars, - analysis_value = compute_bmi( - height = !!sym(paste0("AVAL.", height_code)), - weight = !!sym(paste0("AVAL.", weight_code)) - ), - set_values_to = set_values_to, - constant_parameters = c(height_code), - constant_by_vars = constant_by_vars - ) - } + parameters <- c(weight_code) + constant_parameters <- c(height_code) } + + derive_param_computed( + dataset, + filter = !!filter, + parameters = parameters, + by_vars = by_vars, + analysis_value = !!bmi_formula, + set_values_to = set_values_to, + constant_parameters = constant_parameters, + constant_by_vars = constant_by_vars + ) } #' Compute Body Mass Index (BMI) @@ -676,13 +715,13 @@ derive_param_bmi <- function(dataset, #' #' It is expected that HEIGHT is in cm. #' -#' Permitted Values: numeric vector +#' *Permitted Values:* numeric vector #' #' @param weight WEIGHT value #' #' It is expected that WEIGHT is in kg. #' -#' Permitted Values: numeric vector +#' *Permitted Values:* numeric vector #' #' #' @details Usually this computation function can not be used with `%>%`. diff --git a/man/compute_bmi.Rd b/man/compute_bmi.Rd index aa6177f15b..9d02f9cff3 100644 --- a/man/compute_bmi.Rd +++ b/man/compute_bmi.Rd @@ -11,13 +11,13 @@ compute_bmi(height, weight) It is expected that HEIGHT is in cm. -Permitted Values: numeric vector} +\emph{Permitted Values:} numeric vector} \item{weight}{WEIGHT value It is expected that WEIGHT is in kg. -Permitted Values: numeric vector} +\emph{Permitted Values:} numeric vector} } \value{ The BMI (Body Mass Index Area) in kg/m^2. diff --git a/man/compute_bsa.Rd b/man/compute_bsa.Rd index a8b3c9fe9e..f427486525 100644 --- a/man/compute_bsa.Rd +++ b/man/compute_bsa.Rd @@ -11,13 +11,13 @@ compute_bsa(height = height, weight = weight, method) It is expected that HEIGHT is in cm. -Permitted Values: numeric vector} +\emph{Permitted Values:} numeric vector} \item{weight}{WEIGHT value It is expected that WEIGHT is in kg. -Permitted Values: numeric vector} +\emph{Permitted Values:} numeric vector} \item{method}{Derivation method to use: @@ -35,7 +35,7 @@ Fujimoto: 0.008883 * height ^ 0.663 * weight ^ 0.444 Takahira: 0.007241 * height ^ 0.725 * weight ^ 0.425 -Permitted Values: character value} +\emph{Permitted Values:} character value} } \value{ The BSA (Body Surface Area) in m^2. diff --git a/man/derive_param_bmi.Rd b/man/derive_param_bmi.Rd index d1161e54e2..5829d764b7 100644 --- a/man/derive_param_bmi.Rd +++ b/man/derive_param_bmi.Rd @@ -12,7 +12,6 @@ derive_param_bmi( height_code = "HEIGHT", get_unit_expr, filter = NULL, - constant_height = FALSE, constant_by_vars = NULL ) } @@ -47,14 +46,16 @@ code for the new parameter. The observations where \code{PARAMCD} equals the specified value are considered as the WEIGHT. It is expected that WEIGHT is measured in kg -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{height_code}{HEIGHT parameter code The observations where \code{PARAMCD} equals the specified value are considered as the HEIGHT. It is expected that HEIGHT is measured in cm -Permitted Values: character value} +\emph{Permitted Values:} character value + +\emph{Permitted Values:} logical scalar} \item{get_unit_expr}{An expression providing the unit of the parameter @@ -70,19 +71,15 @@ into account. \emph{Permitted Values:} a condition} -\item{constant_height}{HEIGHT parameter is constant - -If the HEIGHT value is considered constant (e.g. measured once at screening), -the values of BSA will be calculated for each WEIGHT value. - -Permitted Values: logical scalar +\item{constant_by_vars}{By variables for when HEIGHT is constant -Default Values: FALSE} +When HEIGHT is constant, the HEIGHT parameters (measured only once) are merged +to the other parameters using the specified variables. -\item{constant_by_vars}{By variables for constant parameters - -The constant parameters (parameters that are measured only once) are merged -to the other parameters using the specified variables. (Refer to Example 2) +If height is constant (e.g. only measured once at screening or baseline) then +use \code{constant_by_vars} to select the subject-level variable to merge on (e.g. USUBJID). +This will produce BMI at all visits where weight is measured. Otherwise +it will only be calculated at visits with both height and weight collected. \emph{Permitted Values:} list of variables} } @@ -101,18 +98,18 @@ The analysis value of the new parameter is derived as \deqn{BMI = \frac{WEIGHT}{HEIGHT^2}} } \examples{ -library(tibble) - -advs <- tribble( - ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVISIT, - "01-701-1015", "HEIGHT", "Height (cm)", 147, "SCREENING", - "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "SCREENING", - "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "BASELINE", - "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "WEEK 2", - "01-701-1028", "HEIGHT", "Height (cm)", 163, "SCREENING", - "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "SCREENING", - "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "BASELINE", - "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "WEEK 2" + +# Example 1: Derive BMI where height is measured only once using constant_by_vars +advs <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVISIT, + "01-701-1015", "HEIGHT", "Height (cm)", 147, "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "SCREENING", + "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "BASELINE", + "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "WEEK 2", + "01-701-1028", "HEIGHT", "Height (cm)", 163, "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "SCREENING", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "BASELINE", + "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "WEEK 2" ) derive_param_bmi( @@ -124,10 +121,12 @@ derive_param_bmi( PARAMCD = "BMI", PARAM = "Body Mass Index (kg/m^2)" ), - get_unit_expr = extract_unit(PARAM) + get_unit_expr = extract_unit(PARAM), + constant_by_vars = exprs(USUBJID) ) -# Example 2: Derive BMI where height is measured only once +# Example 2: Derive BMI where height is measured only once and keep only one record +# where both height and weight are measured. derive_param_bmi( advs, by_vars = exprs(USUBJID, AVISIT), @@ -137,9 +136,32 @@ derive_param_bmi( PARAMCD = "BMI", PARAM = "Body Mass Index (kg/m^2)" ), - get_unit_expr = extract_unit(PARAM), - constant_height = TRUE, - constant_by_vars = exprs(USUBJID) + get_unit_expr = extract_unit(PARAM) +) + +# Example 3: Pediatric study where height and weight are measured multiple times +advs <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, + "01-101-1001", "HEIGHT", "Height (cm)", 47.1, "BASELINE", + "01-101-1001", "HEIGHT", "Height (cm)", 59.1, "WEEK 12", + "01-101-1001", "HEIGHT", "Height (cm)", 64.7, "WEEK 24", + "01-101-1001", "HEIGHT", "Height (cm)", 68.2, "WEEK 48", + "01-101-1001", "WEIGHT", "Weight (kg)", 2.6, "BASELINE", + "01-101-1001", "WEIGHT", "Weight (kg)", 5.3, "WEEK 12", + "01-101-1001", "WEIGHT", "Weight (kg)", 6.7, "WEEK 24", + "01-101-1001", "WEIGHT", "Weight (kg)", 7.4, "WEEK 48", +) + +derive_param_bmi( + advs, + by_vars = exprs(USUBJID, VISIT), + weight_code = "WEIGHT", + height_code = "HEIGHT", + set_values_to = exprs( + PARAMCD = "BMI", + PARAM = "Body Mass Index (kg/m^2)" + ), + get_unit_expr = extract_unit(PARAM) ) } \seealso{ diff --git a/man/derive_param_bsa.Rd b/man/derive_param_bsa.Rd index 49dde86316..5913bfb221 100644 --- a/man/derive_param_bsa.Rd +++ b/man/derive_param_bsa.Rd @@ -13,7 +13,6 @@ derive_param_bsa( weight_code = "WEIGHT", get_unit_expr, filter = NULL, - constant_height = FALSE, constant_by_vars = NULL ) } @@ -52,7 +51,7 @@ Fujimoto: \code{0.008883 * height ^ 0.663 * weight ^ 0.444} Takahira: \code{0.007241 * height ^ 0.725 * weight ^ 0.425} -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{set_values_to}{Variables to be set @@ -67,14 +66,14 @@ code for the new parameter. The observations where \code{PARAMCD} equals the specified value are considered as the HEIGHT assessments. It is expected that HEIGHT is measured in cm. -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{weight_code}{WEIGHT parameter code The observations where \code{PARAMCD} equals the specified value are considered as the WEIGHT assessments. It is expected that WEIGHT is measured in kg. -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{get_unit_expr}{An expression providing the unit of the parameter @@ -90,19 +89,15 @@ into account. \emph{Permitted Values:} a condition} -\item{constant_height}{HEIGHT parameter is constant +\item{constant_by_vars}{By variables for when HEIGHT is constant -If the HEIGHT value is considered constant (e.g. measured once at screening), -the values of BSA will be calculated for each WEIGHT value. +When HEIGHT is constant, the HEIGHT parameters (measured only once) are merged +to the other parameters using the specified variables. -Permitted Values: logical scalar - -Default Values: FALSE} - -\item{constant_by_vars}{By variables for constant parameters - -The constant parameters (parameters that are measured only once) are merged -to the other parameters using the specified variables. (Refer to Example 2) +If height is constant (e.g. only measured once at screening or baseline) then +use \code{constant_by_vars} to select the subject-level variable to merge on (e.g. USUBJID). +This will produce BSA at all visits where weight is measured. Otherwise +it will only be calculated at visits with both height and weight collected. \emph{Permitted Values:} list of variables} } @@ -120,7 +115,8 @@ available. \examples{ library(tibble) -advs <- tribble( +# Example 1: Derive BSA where height is measured only once using constant_by_vars +advs <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "HEIGHT", "Height (cm)", 170, "BASELINE", "01-701-1015", "WEIGHT", "Weight (kg)", 75, "BASELINE", @@ -140,7 +136,8 @@ derive_param_bsa( PARAMCD = "BSA", PARAM = "Body Surface Area (m^2)" ), - get_unit_expr = extract_unit(PARAM) + get_unit_expr = extract_unit(PARAM), + constant_by_vars = exprs(USUBJID) ) derive_param_bsa( @@ -151,9 +148,36 @@ derive_param_bsa( PARAMCD = "BSA", PARAM = "Body Surface Area (m^2)" ), + get_unit_expr = extract_unit(PARAM), + constant_by_vars = exprs(USUBJID) +) + +# Example 2: Derive BSA where height is measured only once and keep only one record +# where both height and weight are measured. + +derive_param_bsa( + advs, + by_vars = exprs(USUBJID, VISIT), + method = "Mosteller", + set_values_to = exprs( + PARAMCD = "BSA", + PARAM = "Body Surface Area (m^2)" + ), get_unit_expr = extract_unit(PARAM) ) +# Example 3: Pediatric study where height and weight are measured multiple times +advs <- tibble::tribble( + ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, + "01-101-1001", "HEIGHT", "Height (cm)", 47.1, "BASELINE", + "01-101-1001", "HEIGHT", "Height (cm)", 59.1, "WEEK 12", + "01-101-1001", "HEIGHT", "Height (cm)", 64.7, "WEEK 24", + "01-101-1001", "HEIGHT", "Height (cm)", 68.2, "WEEK 48", + "01-101-1001", "WEIGHT", "Weight (kg)", 2.6, "BASELINE", + "01-101-1001", "WEIGHT", "Weight (kg)", 5.3, "WEEK 12", + "01-101-1001", "WEIGHT", "Weight (kg)", 6.7, "WEEK 24", + "01-101-1001", "WEIGHT", "Weight (kg)", 7.4, "WEEK 48", +) derive_param_bsa( advs, by_vars = exprs(USUBJID, VISIT), @@ -162,9 +186,7 @@ derive_param_bsa( PARAMCD = "BSA", PARAM = "Body Surface Area (m^2)" ), - get_unit_expr = extract_unit(PARAM), - constant_height = TRUE, - constant_by_vars = exprs(USUBJID) + get_unit_expr = extract_unit(PARAM) ) } \seealso{ diff --git a/man/derive_param_map.Rd b/man/derive_param_map.Rd index f019558f0e..348cffffff 100644 --- a/man/derive_param_map.Rd +++ b/man/derive_param_map.Rd @@ -47,21 +47,21 @@ code for the new parameter. The observations where \code{PARAMCD} equals the specified value are considered as the systolic blood pressure assessments. -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{diabp_code}{Diastolic blood pressure parameter code The observations where \code{PARAMCD} equals the specified value are considered as the diastolic blood pressure assessments. -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{hr_code}{Heart rate parameter code The observations where \code{PARAMCD} equals the specified value are considered as the heart rate assessments. -Permitted Values: character value} +\emph{Permitted Values:} character value} \item{get_unit_expr}{An expression providing the unit of the parameter @@ -99,7 +99,7 @@ if it is based on diastolic, systolic blood pressure, and heart rate. library(tibble) library(dplyr, warn.conflicts = FALSE) -advs <- tribble( +advs <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "PULSE", "Pulse (beats/min)", 59, "BASELINE", "01-701-1015", "PULSE", "Pulse (beats/min)", 61, "WEEK 2", diff --git a/tests/testthat/test-derive_advs_params.R b/tests/testthat/test-derive_advs_params.R index 48a667993e..8cfc255bcd 100644 --- a/tests/testthat/test-derive_advs_params.R +++ b/tests/testthat/test-derive_advs_params.R @@ -457,51 +457,18 @@ test_that("derive_param_bmi Test 38: Derive BMI where height is measured only on AVALU = "kg/m^2" ), get_unit_expr = extract_unit(PARAM), - constant_height = TRUE, constant_by_vars = exprs(USUBJID) ), keys = c("USUBJID", "PARAMCD", "VISIT") ) }) -## Test 39: constant_by_vars is expected when constant_height is TRUE ---- -test_that("derive_param_bmi Test 39: constant_by_vars is expected when constant_height is TRUE", { - input <- tibble::tribble( - ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, - "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", - "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "kg", "SCREENING", - "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "kg", "BASELINE", - "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "kg", "WEEK 2", - "01-701-1028", "HEIGHT", "Height (cm)", 163.0, "cm", "SCREENING", - "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "kg", "SCREENING", - "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "kg", "BASELINE", - "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "kg", "WEEK 2" - ) - - expect_error( - derive_param_bmi( - input, - by_vars = exprs(USUBJID, VISIT), - weight_code = "WEIGHT", - height_code = "HEIGHT", - set_values_to = exprs( - PARAMCD = "BMI", - PARAM = "Body Mass Index (kg/m^2)", - AVALU = "kg/m^2" - ), - get_unit_expr = extract_unit(PARAM), - constant_height = TRUE - ), - "constant_by_vars is expected when constant_height is TRUE" - ) -}) - # derive_param_bsa ---- ## derive_param_bsa: Error checks ---- -## Test 40: BSA parameter NOT added - wrong unit for height ---- -test_that("derive_param_bsa Test 40: BSA parameter NOT added - wrong unit for height", { +## Test 39: BSA parameter NOT added - wrong unit for height ---- +test_that("derive_param_bsa Test 39: BSA parameter NOT added - wrong unit for height", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, # Wrong unit for HEIGHT should be cm @@ -523,8 +490,8 @@ test_that("derive_param_bsa Test 40: BSA parameter NOT added - wrong unit for he ) }) -## Test 41: BSA parameter NOT added - wrong unit for weight ---- -test_that("derive_param_bsa Test 41: BSA parameter NOT added - wrong unit for weight", { +## Test 40: BSA parameter NOT added - wrong unit for weight ---- +test_that("derive_param_bsa Test 40: BSA parameter NOT added - wrong unit for weight", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -546,8 +513,8 @@ test_that("derive_param_bsa Test 41: BSA parameter NOT added - wrong unit for we ) }) -## Test 42: BSA parameter NOT added - multiple unit for weight ---- -test_that("derive_param_bsa Test 42: BSA parameter NOT added - multiple unit for weight", { +## Test 41: BSA parameter NOT added - multiple unit for weight ---- +test_that("derive_param_bsa Test 41: BSA parameter NOT added - multiple unit for weight", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -570,8 +537,8 @@ test_that("derive_param_bsa Test 42: BSA parameter NOT added - multiple unit for ) }) -## Test 43: BSA parameter NOT added - PARAMCD not set ---- -test_that("derive_param_bsa Test 43: BSA parameter NOT added - PARAMCD not set", { +## Test 42: BSA parameter NOT added - PARAMCD not set ---- +test_that("derive_param_bsa Test 42: BSA parameter NOT added - PARAMCD not set", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -595,8 +562,8 @@ test_that("derive_param_bsa Test 43: BSA parameter NOT added - PARAMCD not set", ## derive_param_bsa: No obs added ---- -## Test 44: BSA parameter NOT added ---- -test_that("derive_param_bsa Test 44: BSA parameter NOT added", { +## Test 43: BSA parameter NOT added ---- +test_that("derive_param_bsa Test 43: BSA parameter NOT added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -629,8 +596,8 @@ mosteller <- function(hgt, wgt) { sqrt(hgt * wgt / 3600) } -## Test 45: BSA parameter (Mosteller Method) is correctly added ---- -test_that("derive_param_bsa Test 45: BSA parameter (Mosteller Method) is correctly added", { +## Test 44: BSA parameter (Mosteller Method) is correctly added ---- +test_that("derive_param_bsa Test 44: BSA parameter (Mosteller Method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -664,8 +631,8 @@ dubois <- function(hgt, wgt) { 0.20247 * (hgt / 100)^0.725 * wgt^0.425 } -## Test 46: BSA parameter (DuBois-DuBois method) is correctly added ---- -test_that("derive_param_bsa Test 46: BSA parameter (DuBois-DuBois method) is correctly added", { +## Test 45: BSA parameter (DuBois-DuBois method) is correctly added ---- +test_that("derive_param_bsa Test 45: BSA parameter (DuBois-DuBois method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -700,8 +667,8 @@ haycock <- function(hgt, wgt) { 0.024265 * hgt^0.3964 * wgt^0.5378 } -## Test 47: BSA parameter (Haycock method) is correctly added ---- -test_that("derive_param_bsa Test 47: BSA parameter (Haycock method) is correctly added", { +## Test 46: BSA parameter (Haycock method) is correctly added ---- +test_that("derive_param_bsa Test 46: BSA parameter (Haycock method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -735,8 +702,8 @@ gehan <- function(hgt, wgt) { 0.0235 * hgt^0.42246 * wgt^0.51456 } -## Test 48: BSA parameter (Gehan-George method) is correctly added ---- -test_that("derive_param_bsa Test 48: BSA parameter (Gehan-George method) is correctly added", { +## Test 47: BSA parameter (Gehan-George method) is correctly added ---- +test_that("derive_param_bsa Test 47: BSA parameter (Gehan-George method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -771,8 +738,8 @@ boyd <- function(hgt, wgt) { 0.0003207 * (hgt^0.3) * (1000 * wgt)^(0.7285 - (0.0188 * log10(1000 * wgt))) # nolint } -## Test 49: BSA parameter (Boyd method) is correctly added ---- -test_that("derive_param_bsa Test 49: BSA parameter (Boyd method) is correctly added", { +## Test 48: BSA parameter (Boyd method) is correctly added ---- +test_that("derive_param_bsa Test 48: BSA parameter (Boyd method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -806,8 +773,8 @@ fujimoto <- function(hgt, wgt) { 0.008883 * hgt^0.663 * wgt^0.444 } -## Test 50: BSA parameter (Fujimoto method) is correctly added ---- -test_that("derive_param_bsa Test 50: BSA parameter (Fujimoto method) is correctly added", { +## Test 49: BSA parameter (Fujimoto method) is correctly added ---- +test_that("derive_param_bsa Test 49: BSA parameter (Fujimoto method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -842,8 +809,8 @@ takahira <- function(hgt, wgt) { 0.007241 * hgt^0.725 * wgt^0.425 } -## Test 51: BSA parameter (Takahira method) is correctly added ---- -test_that("derive_param_bsa Test 51: BSA parameter (Takahira method) is correctly added", { +## Test 50: BSA parameter (Takahira method) is correctly added ---- +test_that("derive_param_bsa Test 50: BSA parameter (Takahira method) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~VSSTRESU, ~AVAL, "01-701-1015", "HEIGHT", "Height (cm)", "BASELINE", "cm", 170, @@ -874,8 +841,8 @@ test_that("derive_param_bsa Test 51: BSA parameter (Takahira method) is correctl ) }) -## Test 52: Derive BSA where height is measured only once ---- -test_that("derive_param_bsa Test 52: Derive BSA where height is measured only once", { +## Test 51: Derive BSA where height is measured only once ---- +test_that("derive_param_bsa Test 51: Derive BSA where height is measured only once", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", @@ -917,50 +884,19 @@ test_that("derive_param_bsa Test 52: Derive BSA where height is measured only on AVALU = "m^2" ), get_unit_expr = extract_unit(PARAM), - constant_height = TRUE, constant_by_vars = exprs(USUBJID) ), keys = c("USUBJID", "PARAMCD", "VISIT") ) }) -## Test 53: constant_by_vars is expected when constant_height is TRUE ---- -test_that("derive_param_bsa Test 53: constant_by_vars is expected when constant_height is TRUE", { - input <- tibble::tribble( - ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT, - "01-701-1015", "HEIGHT", "Height (cm)", 147.0, "cm", "SCREENING", - "01-701-1015", "WEIGHT", "Weight (kg)", 54.0, "kg", "SCREENING", - "01-701-1015", "WEIGHT", "Weight (kg)", 54.4, "kg", "BASELINE", - "01-701-1015", "WEIGHT", "Weight (kg)", 53.1, "kg", "WEEK 2", - "01-701-1028", "HEIGHT", "Height (cm)", 163.0, "cm", "SCREENING", - "01-701-1028", "WEIGHT", "Weight (kg)", 78.5, "kg", "SCREENING", - "01-701-1028", "WEIGHT", "Weight (kg)", 80.3, "kg", "BASELINE", - "01-701-1028", "WEIGHT", "Weight (kg)", 80.7, "kg", "WEEK 2" - ) - - expect_error( - derive_param_bsa( - input, - by_vars = exprs(USUBJID, VISIT), - method = "Mosteller", - set_values_to = exprs( - PARAMCD = "BSA", - PARAM = "Body Surface Area (m^2)", - AVALU = "m^2" - ), - get_unit_expr = extract_unit(PARAM), - constant_height = TRUE - ), - "constant_by_vars is expected when constant_height is TRUE" - ) -}) # derive_param_map ---- ## derive_param_map: Error checks ---- -## Test 54: MAP parameter NOT added - wrong DIABP unit ---- -test_that("derive_param_map Test 54: MAP parameter NOT added - wrong DIABP unit", { +## Test 52: MAP parameter NOT added - wrong DIABP unit ---- +test_that("derive_param_map Test 52: MAP parameter NOT added - wrong DIABP unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mHg)", 51, "BASELINE", @@ -980,8 +916,8 @@ test_that("derive_param_map Test 54: MAP parameter NOT added - wrong DIABP unit" ) }) -## Test 55: MAP parameter NOT added - wrong SYSBP unit ---- -test_that("derive_param_map Test 55: MAP parameter NOT added - wrong SYSBP unit", { +## Test 53: MAP parameter NOT added - wrong SYSBP unit ---- +test_that("derive_param_map Test 53: MAP parameter NOT added - wrong SYSBP unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", 51, "BASELINE", @@ -1001,8 +937,8 @@ test_that("derive_param_map Test 55: MAP parameter NOT added - wrong SYSBP unit" ) }) -## Test 56: MAP parameter NOT added - wrong PULSE unit ---- -test_that("derive_param_map Test 56: MAP parameter NOT added - wrong PULSE unit", { +## Test 54: MAP parameter NOT added - wrong PULSE unit ---- +test_that("derive_param_map Test 54: MAP parameter NOT added - wrong PULSE unit", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", 51, "BASELINE", @@ -1024,8 +960,8 @@ test_that("derive_param_map Test 56: MAP parameter NOT added - wrong PULSE unit" ) }) -## Test 57: MAP parameter NOT added - PARAMCD not set ---- -test_that("derive_param_map Test 57: MAP parameter NOT added - PARAMCD not set", { +## Test 55: MAP parameter NOT added - PARAMCD not set ---- +test_that("derive_param_map Test 55: MAP parameter NOT added - PARAMCD not set", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", 51, "BASELINE", @@ -1048,8 +984,8 @@ test_that("derive_param_map Test 57: MAP parameter NOT added - PARAMCD not set", ## derive_param_map: No obs added ---- -## Test 58: MAP parameter NOT added ---- -test_that("derive_param_map Test 58: MAP parameter NOT added", { +## Test 56: MAP parameter NOT added ---- +test_that("derive_param_map Test 56: MAP parameter NOT added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~VISIT, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", NA, "BASELINE", @@ -1083,8 +1019,8 @@ maphr <- function(sbp, dbp, hr) { dbp + 0.01 * exp(4.14 - 40.74 / hr) * (sbp - dbp) } -## Test 59: MAP parameter (DBP/SBP/PULSE) is correctly added ---- -test_that("derive_param_map Test 59: MAP parameter (DBP/SBP/PULSE) is correctly added", { +## Test 57: MAP parameter (DBP/SBP/PULSE) is correctly added ---- +test_that("derive_param_map Test 57: MAP parameter (DBP/SBP/PULSE) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, "01-701-1015", "PULSE", "Pulse (beats/min)", "BASELINE", 59, @@ -1119,8 +1055,8 @@ map <- function(sbp, dbp) { (2 * dbp + sbp) / 3 } -## Test 60: MAP parameter (DBP/SBP) is correctly added ---- -test_that("derive_param_map Test 60: MAP parameter (DBP/SBP) is correctly added", { +## Test 58: MAP parameter (DBP/SBP) is correctly added ---- +test_that("derive_param_map Test 58: MAP parameter (DBP/SBP) is correctly added", { expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", "BASELINE", 51, From cabc201714cf3dbcf66178e4afcb0cc10648bd6f Mon Sep 17 00:00:00 2001 From: Jeffrey Dickinson Date: Thu, 15 Jun 2023 14:06:41 +0000 Subject: [PATCH 3/5] docs: #1228 Produce BMI records for more visits: Fix typo in NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 48d076dffe..f737493b30 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ ## Updates of Existing Functions -- The functions `derive_param_bmi()` and `derive_param_bsa() are updated to have the option of producing more values at visits when only weight is collected (#1228). +- The functions `derive_param_bmi()` and `derive_param_bsa()` are updated to have the option of producing more values at visits when only weight is collected (#1228). # admiral 0.11.0 From e272bf5369186e8c2fc2721324fd0e1a70afc13c Mon Sep 17 00:00:00 2001 From: Jeffrey Dickinson Date: Thu, 15 Jun 2023 15:17:34 +0000 Subject: [PATCH 4/5] feat: #1228 Produce BMI records for more visits: Update ADVS template and vignette. --- inst/templates/ad_advs.R | 6 ++++-- vignettes/bds_finding.Rmd | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/inst/templates/ad_advs.R b/inst/templates/ad_advs.R index eb0977ce9d..7fce3a288d 100644 --- a/inst/templates/ad_advs.R +++ b/inst/templates/ad_advs.R @@ -121,14 +121,16 @@ advs <- advs %>% method = "Mosteller", set_values_to = exprs(PARAMCD = "BSA"), get_unit_expr = VSSTRESU, - filter = VSSTAT != "NOT DONE" | is.na(VSSTAT) + filter = VSSTAT != "NOT DONE" | is.na(VSSTAT), + constant_by_vars = exprs(USUBJID) ) %>% # Derive Body Mass Index derive_param_bmi( by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISIT, VISITNUM, ADT, ADY, VSTPT, VSTPTNUM), set_values_to = exprs(PARAMCD = "BMI"), get_unit_expr = VSSTRESU, - filter = VSSTAT != "NOT DONE" | is.na(VSSTAT) + filter = VSSTAT != "NOT DONE" | is.na(VSSTAT), + constant_by_vars = exprs(USUBJID) ) diff --git a/vignettes/bds_finding.Rmd b/vignettes/bds_finding.Rmd index e0aeaba5e2..3b111577bc 100644 --- a/vignettes/bds_finding.Rmd +++ b/vignettes/bds_finding.Rmd @@ -305,8 +305,8 @@ dataset_vignette( ) ``` -Likewise, function call below, to create parameter `Body Surface Area` and -`Body Mass Index` for `ADVS` domain. +Likewise, function call below, to create parameter `Body Surface Area` (BSA) and +`Body Mass Index` (BMI) for `ADVS` domain. Note that if height is collected only once use `constant_by_vars` to specify the subject-level variable to merge on. Otherwise BSA and BMI are only calculated for visits where both are collected. ```{r eval=TRUE} advs <- derive_param_bsa( @@ -315,7 +315,8 @@ advs <- derive_param_bsa( method = "Mosteller", set_values_to = exprs(PARAMCD = "BSA"), get_unit_expr = VSSTRESU, - filter = VSSTAT != "NOT DONE" | is.na(VSSTAT) + filter = VSSTAT != "NOT DONE" | is.na(VSSTAT), + constant_by_vars = exprs(USUBJID) ) advs <- derive_param_bmi( @@ -323,7 +324,8 @@ advs <- derive_param_bmi( by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISIT, VISITNUM, ADT, ADY, VSTPT, VSTPTNUM), set_values_to = exprs(PARAMCD = "BMI"), get_unit_expr = VSSTRESU, - filter = VSSTAT != "NOT DONE" | is.na(VSSTAT) + filter = VSSTAT != "NOT DONE" | is.na(VSSTAT), + constant_by_vars = exprs(USUBJID) ) ``` From 022c8fa8672a3524ec3f5f86c636134e3feb4ad0 Mon Sep 17 00:00:00 2001 From: Jeffrey Dickinson Date: Wed, 28 Jun 2023 14:04:37 +0000 Subject: [PATCH 5/5] doc: #1228 Produce BMI records for more visits: Add backticks to variable. --- R/derive_advs_params.R | 4 ++-- man/derive_param_bmi.Rd | 2 +- man/derive_param_bsa.Rd | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/derive_advs_params.R b/R/derive_advs_params.R index f28fcad448..a8b1e3a526 100644 --- a/R/derive_advs_params.R +++ b/R/derive_advs_params.R @@ -261,7 +261,7 @@ compute_map <- function(diabp, sysbp, hr = NULL) { #' to the other parameters using the specified variables. #' #' If height is constant (e.g. only measured once at screening or baseline) then -#' use `constant_by_vars` to select the subject-level variable to merge on (e.g. USUBJID). +#' use `constant_by_vars` to select the subject-level variable to merge on (e.g. `USUBJID`). #' This will produce BSA at all visits where weight is measured. Otherwise #' it will only be calculated at visits with both height and weight collected. #' @@ -558,7 +558,7 @@ compute_bsa <- function(height = height, #' to the other parameters using the specified variables. #' #' If height is constant (e.g. only measured once at screening or baseline) then -#' use `constant_by_vars` to select the subject-level variable to merge on (e.g. USUBJID). +#' use `constant_by_vars` to select the subject-level variable to merge on (e.g. `USUBJID`). #' This will produce BMI at all visits where weight is measured. Otherwise #' it will only be calculated at visits with both height and weight collected. #' diff --git a/man/derive_param_bmi.Rd b/man/derive_param_bmi.Rd index 5829d764b7..6b037854d2 100644 --- a/man/derive_param_bmi.Rd +++ b/man/derive_param_bmi.Rd @@ -77,7 +77,7 @@ When HEIGHT is constant, the HEIGHT parameters (measured only once) are merged to the other parameters using the specified variables. If height is constant (e.g. only measured once at screening or baseline) then -use \code{constant_by_vars} to select the subject-level variable to merge on (e.g. USUBJID). +use \code{constant_by_vars} to select the subject-level variable to merge on (e.g. \code{USUBJID}). This will produce BMI at all visits where weight is measured. Otherwise it will only be calculated at visits with both height and weight collected. diff --git a/man/derive_param_bsa.Rd b/man/derive_param_bsa.Rd index 5913bfb221..6446ca94ad 100644 --- a/man/derive_param_bsa.Rd +++ b/man/derive_param_bsa.Rd @@ -95,7 +95,7 @@ When HEIGHT is constant, the HEIGHT parameters (measured only once) are merged to the other parameters using the specified variables. If height is constant (e.g. only measured once at screening or baseline) then -use \code{constant_by_vars} to select the subject-level variable to merge on (e.g. USUBJID). +use \code{constant_by_vars} to select the subject-level variable to merge on (e.g. \code{USUBJID}). This will produce BSA at all visits where weight is measured. Otherwise it will only be calculated at visits with both height and weight collected.