Skip to contents

Derive analysis criterion evaluation result variable, paired with character and numeric flags. This function allows also the derivation of a CRIT like variable with a different name (ex: ANL01FL), without generating additional numeric (ex: ANL01FN) and character label (ex: ANL01) variables.

Usage

derive_vars_crit(dataset, prefix, crit_label, condition, criterion)

Arguments

dataset

Input dataset

prefix

Variables to add

The analysis criterion evaluation variable's name (i.e., CRIT1) This name is also used in order to create both character and numeric flags variables (i.e., CRIT1FL and CRIT1FN). If the name does not contain CRIT wording, it generates a flag variable (ex: ANL01FL) whose logic is equals to CRIT1 variable, without generating additional numeric (ex: ANL01FN) and character (ANL01) variables.

crit_label

Criterion value

A text description defining the condition necessary to satisfy the presence of the criterion

condition

Condition for selecting a subset

The condition specified in order to select a subset from the input dataset in which the rule is applied.

criterion

Criterion rule

The criterion that each selected row satisfies or not. Returns Y or N for character variable and 1 or 0 for numeric variable if the criterion is met or not, respectively. Returns NA for not selected rows (not taken into account from condition)

Value

Dataset with criterion variables

Author

Federico Baratin

Examples

library(tibble)
library(admiral)
library(admiraldev)
library(dplyr)

input <- tribble(
  ~USUBJID, ~AVISITN, ~ISCAT, ~PARAMCD, ~AVAL, ~ISLLOQ,
  "999999-000001", 10, "IMMUNOLOGY", "J0033VN", 2, 4,
  "999999-000001", 10, "IMMUNOLOGY", "I0019NT", 3, 6,
  "999999-000001", 10, "IMMUNOLOGY", "M0019LN", 4, 4,
  "999999-000001", 10, "IMMUNOLOGY", "R0003MA", 3, 6,
  "999999-000001", 30, "IMMUNOLOGY", "J0033VN", 60, 4,
  "999999-000001", 30, "IMMUNOLOGY", "I0019NT", 567, 6,
  "999999-000001", 30, "IMMUNOLOGY", "M0019LN", 659, 4,
  "999999-000001", 30, "IMMUNOLOGY", "R0003MA", 250, 6,
  "999999-000002", 10, "IMMUNOLOGY", "J0033VN", 2, 4,
  "999999-000002", 10, "IMMUNOLOGY", "I0019NT", 7, 6,
  "999999-000002", 10, "IMMUNOLOGY", "M0019LN", 5, 4,
  "999999-000002", 10, "IMMUNOLOGY", "R0003MA", 3, 6,
  "999999-000002", 30, "IMMUNOLOGY", "J0033VN", 55, 4,
  "999999-000002", 30, "IMMUNOLOGY", "I0019NT", 89, 6,
  "999999-000002", 30, "IMMUNOLOGY", "M0019LN", 990, 4,
  "999999-000002", 30, "IMMUNOLOGY", "R0003MA", 340, 6,
  "999999-000003", 10, "IMMUNOLOGY", "J0033VN", 3, 4,
  "999999-000003", 10, "IMMUNOLOGY", "I0019NT", 6, 6,
  "999999-000003", 10, "IMMUNOLOGY", "M0019LN", 2, 4,
  "999999-000003", 10, "IMMUNOLOGY", "R0003MA", 2, 6,
  "999999-000003", 30, "IMMUNOLOGY", "J0033VN", 45, 4,
  "999999-000003", 30, "IMMUNOLOGY", "I0019NT", 381, 6,
  "999999-000003", 30, "IMMUNOLOGY", "M0019LN", 542, 4,
  "999999-000003", 30, "IMMUNOLOGY", "R0003MA", NA, 6
)


derive_vars_crit(
  dataset = input,
  prefix = "CRIT1",
  crit_label = "Titer >= ISLLOQ",
  condition = !is.na(AVAL) & !is.na(ISLLOQ),
  criterion = AVAL >= ISLLOQ
)
#> # A tibble: 24 × 9
#>    USUBJID       AVISITN ISCAT      PARAMCD  AVAL ISLLOQ CRIT1FL CRIT1FN CRIT1  
#>    <chr>           <dbl> <chr>      <chr>   <dbl>  <dbl> <chr>     <dbl> <chr>  
#>  1 999999-000001      10 IMMUNOLOGY J0033VN     2      4 N             0 Titer …
#>  2 999999-000001      10 IMMUNOLOGY I0019NT     3      6 N             0 Titer …
#>  3 999999-000001      10 IMMUNOLOGY M0019LN     4      4 Y             1 Titer …
#>  4 999999-000001      10 IMMUNOLOGY R0003MA     3      6 N             0 Titer …
#>  5 999999-000001      30 IMMUNOLOGY J0033VN    60      4 Y             1 Titer …
#>  6 999999-000001      30 IMMUNOLOGY I0019NT   567      6 Y             1 Titer …
#>  7 999999-000001      30 IMMUNOLOGY M0019LN   659      4 Y             1 Titer …
#>  8 999999-000001      30 IMMUNOLOGY R0003MA   250      6 Y             1 Titer …
#>  9 999999-000002      10 IMMUNOLOGY J0033VN     2      4 N             0 Titer …
#> 10 999999-000002      10 IMMUNOLOGY I0019NT     7      6 Y             1 Titer …
#> # ℹ 14 more rows