Derives a ratio variable for a BDS dataset based on user specified variables.
Arguments
- dataset
Input dataset
- numer_var
Variable containing numeric values to be used in the numerator of the ratio calculation.
- denom_var
Variable containing numeric values to be used in the denominator of the ratio calculation.
- new_var
A user-defined variable that will be appended to the dataset. The default behavior will take the denominator variable and prefix it with
R2
and append to the dataset. Using this argument will override this default behavior.Default is
NULL
.
Details
A user wishing to calculate a Ratio to Baseline, AVAL / BASE
will
have returned a new variable R2BASE
that will be appended to the input dataset.
Ratio to Analysis Range Lower Limit AVAL / ANRLO
will return a new variable
R2ANRLO
, and Ratio to Analysis Range Upper Limit AVAL / ANRHI
will return
a new variable R2ANRLO
. Please note how the denominator variable has the prefix
R2----
. A user can override the default returned variables by using the
new_var
argument. Also, values of 0 in the denominator will return NA
in
the derivation.
Reference CDISC ADaM Implementation Guide Version 1.1 Section 3.3.4 Analysis Parameter Variables for BDS Datasets
See also
BDS-Findings Functions that returns variable appended to dataset:
derive_var_anrind()
,
derive_var_atoxgr_dir()
,
derive_var_atoxgr()
,
derive_var_basetype()
,
derive_var_base()
,
derive_var_chg()
,
derive_var_ontrtfl()
,
derive_var_pchg()
,
derive_var_shift()
Examples
library(tibble)
data <- tribble(
~USUBJID, ~PARAMCD, ~SEQ, ~AVAL, ~BASE, ~ANRLO, ~ANRHI,
"P01", "ALT", 1, 27, 27, 6, 34,
"P01", "ALT", 2, 41, 27, 6, 34,
"P01", "ALT", 3, 17, 27, 6, 34,
"P02", "ALB", 1, 38, 38, 33, 49,
"P02", "ALB", 2, 39, 38, 33, 49,
"P02", "ALB", 3, 37, 38, 33, 49
)
# Returns "R2" prefixed variables
data %>%
derive_var_analysis_ratio(numer_var = AVAL, denom_var = BASE) %>%
derive_var_analysis_ratio(numer_var = AVAL, denom_var = ANRLO) %>%
derive_var_analysis_ratio(numer_var = AVAL, denom_var = ANRHI)
#> # A tibble: 6 x 10
#> USUBJID PARAMCD SEQ AVAL BASE ANRLO ANRHI R2BASE R2ANRLO R2ANRHI
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 P01 ALT 1 27 27 6 34 1 4.5 0.794
#> 2 P01 ALT 2 41 27 6 34 1.52 6.83 1.21
#> 3 P01 ALT 3 17 27 6 34 0.630 2.83 0.5
#> 4 P02 ALB 1 38 38 33 49 1 1.15 0.776
#> 5 P02 ALB 2 39 38 33 49 1.03 1.18 0.796
#> 6 P02 ALB 3 37 38 33 49 0.974 1.12 0.755
# Returns user-defined variables
data %>%
derive_var_analysis_ratio(numer_var = AVAL, denom_var = BASE, new_var = R01BASE) %>%
derive_var_analysis_ratio(numer_var = AVAL, denom_var = ANRLO, new_var = R01ANRLO) %>%
derive_var_analysis_ratio(numer_var = AVAL, denom_var = ANRHI, new_var = R01ANRHI)
#> # A tibble: 6 x 10
#> USUBJID PARAMCD SEQ AVAL BASE ANRLO ANRHI R01BASE R01ANRLO R01ANRHI
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 P01 ALT 1 27 27 6 34 1 4.5 0.794
#> 2 P01 ALT 2 41 27 6 34 1.52 6.83 1.21
#> 3 P01 ALT 3 17 27 6 34 0.630 2.83 0.5
#> 4 P02 ALB 1 38 38 33 49 1 1.15 0.776
#> 5 P02 ALB 2 39 38 33 49 1.03 1.18 0.796
#> 6 P02 ALB 3 37 38 33 49 0.974 1.12 0.755