View source: R/derive_var_relative_flag.R
derive_var_relative_flag | R Documentation |
Flag all observations before or after the observation where a specified condition is fulfilled for each by group. For example, the function could be called to flag for each subject all observations before the first disease progression or to flag all AEs after a specific AE.
derive_var_relative_flag(
dataset,
by_vars,
order,
new_var,
condition,
mode,
selection,
inclusive,
flag_no_ref_groups = TRUE,
check_type = "warning"
)
dataset |
Input dataset The variables specified by the |
by_vars |
Grouping variables Permitted Values: list of variables created by |
order |
Sort order Within each by group the observations are ordered by the specified order. For handling of Permitted Values: list of expressions created by |
new_var |
New variable The variable is added to the input dataset and set to |
condition |
Condition for Reference Observation The specified condition determines the reference observation. In the output
dataset all observations before or after ( |
mode |
Selection mode (first or last) If Permitted Values: |
selection |
Flag observations before or after the reference observation? Permitted Values: |
inclusive |
Flag the reference observation? Permitted Values: |
flag_no_ref_groups |
Should by groups without reference observation be flagged? Permitted Values: |
check_type |
Check uniqueness? If Permitted Values: |
For each by group (by_vars
argument) the observations before or
after (selection
argument) the observations where the condition
(condition
argument) is fulfilled the first or last time (order
argument and mode
argument) is flagged in the output dataset.
The input dataset with the new variable (new_var
) added
General Derivation Functions for all ADaMs that returns variable appended to dataset:
derive_var_extreme_flag()
,
derive_var_joined_exist_flag()
,
derive_var_merged_ef_msrc()
,
derive_var_merged_exist_flag()
,
derive_var_merged_summary()
,
derive_var_obs_number()
,
derive_vars_computed()
,
derive_vars_joined()
,
derive_vars_merged()
,
derive_vars_merged_lookup()
,
derive_vars_transposed()
library(tibble)
library(dplyr, warn.conflicts = FALSE)
# Flag all AEs after the first COVID AE
adae <- tribble(
~USUBJID, ~ASTDY, ~ACOVFL, ~AESEQ,
"1", 2, NA, 1,
"1", 5, "Y", 2,
"1", 5, NA, 3,
"1", 17, NA, 4,
"1", 27, "Y", 5,
"1", 32, NA, 6,
"2", 8, NA, 1,
"2", 11, NA, 2,
)
derive_var_relative_flag(
adae,
by_vars = exprs(USUBJID),
order = exprs(ASTDY, AESEQ),
new_var = PSTCOVFL,
condition = ACOVFL == "Y",
mode = "first",
selection = "after",
inclusive = FALSE,
flag_no_ref_groups = FALSE
)
response <- tribble(
~USUBJID, ~AVISITN, ~AVALC,
"1", 0, "PR",
"1", 1, "CR",
"1", 2, "CR",
"1", 3, "SD",
"1", 4, "NE",
"2", 0, "SD",
"2", 1, "PD",
"2", 2, "PD",
"3", 0, "SD",
"4", 0, "SD",
"4", 1, "PR",
"4", 2, "PD",
"4", 3, "SD",
"4", 4, "PR"
)
# Flag observations up to first PD for each patient
response %>%
derive_var_relative_flag(
by_vars = exprs(USUBJID),
order = exprs(AVISITN),
new_var = ANL02FL,
condition = AVALC == "PD",
mode = "first",
selection = "before",
inclusive = TRUE
)
# Flag observations up to first PD excluding baseline (AVISITN = 0) for each patient
response %>%
restrict_derivation(
derivation = derive_var_relative_flag,
args = params(
by_vars = exprs(USUBJID),
order = exprs(AVISITN),
new_var = ANL02FL,
condition = AVALC == "PD",
mode = "first",
selection = "before",
inclusive = TRUE
),
filter = AVISITN > 0
) %>%
arrange(USUBJID, AVISITN)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.