library(tibble)
library(admiral)
library(admiralmetabolic)
# Derive Waist to Height Ratio. In this example height is measured only once per subject.
<- tribble(
advs ~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)
)
# A tibble: 14 × 6
USUBJID PARAMCD PARAM AVAL AVALU VISIT
<chr> <chr> <chr> <dbl> <chr> <chr>
1 01-101-1001 HEIGHT Height (cm) 147 cm SCREENING
2 01-101-1001 WSTCIR Waist Circumference (cm) 110 cm SCREENING
3 01-101-1001 WSTCIR Waist Circumference (cm) 108 cm WEEK 2
4 01-101-1001 WSTCIR Waist Circumference (cm) 107 cm WEEK 3
5 01-101-1002 HEIGHT Height (cm) 163 cm SCREENING
6 01-101-1002 WSTCIR Waist Circumference (cm) 120 cm SCREENING
7 01-101-1002 WSTCIR Waist Circumference (cm) 118 cm WEEK 2
8 01-101-1002 WSTCIR Waist Circumference (cm) 117 cm WEEK 3
9 01-101-1001 WAISTHGT Waist to Height Ratio 0.748 <NA> SCREENING
10 01-101-1001 WAISTHGT Waist to Height Ratio 0.735 <NA> WEEK 2
11 01-101-1001 WAISTHGT Waist to Height Ratio 0.728 <NA> WEEK 3
12 01-101-1002 WAISTHGT Waist to Height Ratio 0.736 <NA> SCREENING
13 01-101-1002 WAISTHGT Waist to Height Ratio 0.724 <NA> WEEK 2
14 01-101-1002 WAISTHGT Waist to Height Ratio 0.718 <NA> WEEK 3