library(tibble)
library(rlang)
# Example 1: Derive Waist to Height Ratio where Height is measured only once
advs <- tribble(
~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT,
"01-101-1001", "HEIGHT", "Height (cm)", 147, "cm", "SCREENING",
"01-101-1001", "WSTCIR", "Waist Circumference (cm)", 110, "cm", "SCREENING",
"01-101-1001", "WSTCIR", "Waist Circumference (cm)", 108, "cm", "WEEK 2",
"01-101-1001", "WSTCIR", "Waist Circumference (cm)", 107, "cm", "WEEK 3",
"01-101-1002", "HEIGHT", "Height (cm)", 163, "cm", "SCREENING",
"01-101-1002", "WSTCIR", "Waist Circumference (cm)", 120, "cm", "SCREENING",
"01-101-1002", "WSTCIR", "Waist Circumference (cm)", 118, "cm", "WEEK 2",
"01-101-1002", "WSTCIR", "Waist Circumference (cm)", 117, "cm", "WEEK 3",
)
derive_param_waisthgt(
advs,
by_vars = exprs(USUBJID, VISIT),
wstcir_code = "WSTCIR",
height_code = "HEIGHT",
set_values_to = exprs(
PARAMCD = "WAISTHGT",
PARAM = "Waist to Height Ratio"
),
constant_by_vars = exprs(USUBJID),
get_unit_expr = admiral::extract_unit(PARAM)
)
# Example 2: Same as above but only adding Waist to Height Ratio
# at certain visits
derive_param_waisthgt(
advs,
by_vars = exprs(USUBJID, VISIT),
wstcir_code = "WSTCIR",
height_code = "HEIGHT",
set_values_to = exprs(
PARAMCD = "WAISTHGT",
PARAM = "Waist to Height Ratio"
),
constant_by_vars = exprs(USUBJID),
get_unit_expr = admiral::extract_unit(PARAM),
filter = VISIT %in% c("SCREENING", "WEEK 3")
)
# Example 3: Pediatric study where Height and Waist Circumference
# are measured multiple times
advs <- tribble(
~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT,
"01-101-1001", "HEIGHT", "Height (cm)", 147, "cm", "SCREENING",
"01-101-1001", "HEIGHT", "Height (cm)", 148, "cm", "WEEK 2",
"01-101-1001", "HEIGHT", "Height (cm)", 149, "cm", "WEEK 3",
"01-101-1001", "WSTCIR", "Waist Circumference (cm)", 100, "cm", "SCREENING",
"01-101-1001", "WSTCIR", "Waist Circumference (cm)", 99, "cm", "WEEK 2",
"01-101-1001", "WSTCIR", "Waist Circumference (cm)", 98, "cm", "WEEK 3",
"01-101-1002", "HEIGHT", "Height (cm)", 163, "cm", "SCREENING",
"01-101-1002", "HEIGHT", "Height (cm)", 164, "cm", "WEEK 2",
"01-101-1002", "HEIGHT", "Height (cm)", 165, "cm", "WEEK 3",
"01-101-1002", "WSTCIR", "Waist Circumference (cm)", 110, "cm", "SCREENING",
"01-101-1002", "WSTCIR", "Waist Circumference (cm)", 109, "cm", "WEEK 2",
"01-101-1002", "WSTCIR", "Waist Circumference (cm)", 108, "cm", "WEEK 3"
)
derive_param_waisthgt(
advs,
by_vars = exprs(USUBJID, VISIT),
wstcir_code = "WSTCIR",
height_code = "HEIGHT",
set_values_to = exprs(
PARAMCD = "WAISTHGT",
PARAM = "Waist to Height Ratio"
),
get_unit_expr = admiral::extract_unit(PARAM)
)
# Example 4: Automatic conversion is performed when deriving the ratio
# if parameters are provided in different units (e.g. centimeters and inches)
advs <- tribble(
~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT,
"01-101-1001", "HEIGHT", "Height (cm)", 147, "cm", "SCREENING",
"01-101-1001", "WSTCIR", "Waist Circumference (in)", 39.37, "in", "SCREENING",
"01-101-1001", "WSTCIR", "Waist Circumference (in)", 38.98, "in", "WEEK 2",
"01-101-1001", "WSTCIR", "Waist Circumference (in)", 38.58, "in", "WEEK 3",
"01-101-1002", "HEIGHT", "Height (cm)", 163, "cm", "SCREENING",
"01-101-1002", "WSTCIR", "Waist Circumference (in)", 43.31, "in", "SCREENING",
"01-101-1002", "WSTCIR", "Waist Circumference (in)", 42.91, "in", "WEEK 2",
"01-101-1002", "WSTCIR", "Waist Circumference (in)", 42.52, "in", "WEEK 3"
)
derive_param_waisthgt(
advs,
by_vars = exprs(USUBJID, VISIT),
wstcir_code = "WSTCIR",
height_code = "HEIGHT",
set_values_to = exprs(
PARAMCD = "WAISTHGT",
PARAM = "Waist to Height Ratio"
),
constant_by_vars = exprs(USUBJID),
get_unit_expr = admiral::extract_unit(PARAM)
)
Run the code above in your browser using DataLab