derive_var_worst_flag: Adds a Variable Flagging the Maximal / Minimal Value Within a...

Description Usage Arguments Details Value Author(s) Examples

View source: R/derive_var_extreme_flag.R

Description

Adds a Variable Flagging the Maximal / Minimal Value Within a Group of Observations

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
derive_var_worst_flag(
  dataset,
  by_vars,
  order,
  new_var,
  param_var,
  analysis_var,
  worst_high,
  worst_low,
  filter = NULL,
  check_type = "warning"
)

Arguments

dataset

Input dataset. Variables specified by by_vars, order, param_var, and analysis_var are expected.

by_vars

Grouping variables

Permitted Values: list of variables

order

Sort order. Used to determine maximal / minimal observation if they are not unique, see Details section for more information.

new_var

Variable to add to the dataset. It is set "Y" for the maximal / minimal observation of each group, see Details section for more information.

param_var

Variable with the parameter values for which the maximal / minimal value is calculated.

analysis_var

Variable with the measurement values for which the maximal / minimal value is calculated.

worst_high

Character with param_var values specifying the parameters referring to "high". Use character(0) if not required.

worst_low

Character with param_var values specifying the parameters referring to "low". Use character(0) if not required.

filter

Filter for flag data

Only observations fulfilling the specified condition are taken into account for flagging. If the parameter is not specified, all observations are considered.

Permitted Values: a condition

check_type

Check uniqueness?

If "warning" or "error" is specified, the specified message is issued if the observations of the input dataset are not unique with respect to the by variables and the order.

Default: "warning"

Permitted Values: "none", "warning", "error"

Details

For each group with respect to the variables specified by the by_vars parameter, the maximal / minimal observation of analysis_var is labelled in the new_var column as "Y" if its param_var is in worst_high / worst_low, otherwise it is assigned NA. If there is more than one such maximal / minimal observation, the first one with respect to the order specified by the order parameter is flagged.

Value

The input dataset with the new flag variable added.

Author(s)

Ondrej Slama

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
input <- tibble::tribble(
  ~STUDYID, ~USUBJID, ~PARAMCD,  ~AVISIT,    ~ADT,                 ~AVAL,
  "TEST01", "PAT01",  "PARAM01", "BASELINE", as.Date("2021-04-27"), 15.0,
  "TEST01", "PAT01",  "PARAM01", "BASELINE", as.Date("2021-04-25"), 14.0,
  "TEST01", "PAT01",  "PARAM01", "BASELINE", as.Date("2021-04-23"), 15.0,
  "TEST01", "PAT01",  "PARAM01", "WEEK 1",   as.Date("2021-04-27"), 10.0,
  "TEST01", "PAT01",  "PARAM01", "WEEK 2",   as.Date("2021-04-30"), 12.0,

  "TEST01", "PAT02",  "PARAM01", "SCREENING",as.Date("2021-04-27"), 15.0,
  "TEST01", "PAT02",  "PARAM01", "BASELINE", as.Date("2021-04-25"), 14.0,
  "TEST01", "PAT02",  "PARAM01", "BASELINE", as.Date("2021-04-23"), 15.0,
  "TEST01", "PAT02",  "PARAM01", "WEEK 1",   as.Date("2021-04-27"), 10.0,
  "TEST01", "PAT02",  "PARAM01", "WEEK 2",   as.Date("2021-04-30"), 12.0,

  "TEST01", "PAT01",  "PARAM02", "SCREENING",as.Date("2021-04-27"), 15.0,
  "TEST01", "PAT01",  "PARAM02", "SCREENING",as.Date("2021-04-25"), 14.0,
  "TEST01", "PAT01",  "PARAM02", "SCREENING",as.Date("2021-04-23"), 15.0,
  "TEST01", "PAT01",  "PARAM02", "BASELINE", as.Date("2021-04-27"), 10.0,
  "TEST01", "PAT01",  "PARAM02", "WEEK 2",   as.Date("2021-04-30"), 12.0,

  "TEST01", "PAT02",  "PARAM02", "SCREENING",as.Date("2021-04-27"), 15.0,
  "TEST01", "PAT02",  "PARAM02", "BASELINE", as.Date("2021-04-25"), 14.0,
  "TEST01", "PAT02",  "PARAM02", "WEEK 1",   as.Date("2021-04-23"), 15.0,
  "TEST01", "PAT02",  "PARAM02", "WEEK 1",   as.Date("2021-04-27"), 10.0,
  "TEST01", "PAT02",  "PARAM02", "BASELINE", as.Date("2021-04-30"), 12.0,

  "TEST01", "PAT02",  "PARAM03", "SCREENING",as.Date("2021-04-27"), 15.0,
  "TEST01", "PAT02",  "PARAM03", "BASELINE", as.Date("2021-04-25"), 14.0,
  "TEST01", "PAT02",  "PARAM03", "WEEK 1",   as.Date("2021-04-23"), 15.0,
  "TEST01", "PAT02",  "PARAM03", "WEEK 1",   as.Date("2021-04-27"), 10.0,
  "TEST01", "PAT02",  "PARAM03", "BASELINE", as.Date("2021-04-30"), 12.0
)

derive_var_worst_flag(
  input,
  by_vars = vars(USUBJID, PARAMCD, AVISIT),
  order = vars(desc(ADT)),
  new_var = WORSTFL,
  param_var = PARAMCD,
  analysis_var = AVAL,
  worst_high = c("PARAM01", "PARAM03"),
  worst_low = "PARAM02"
)

## Not run: 
# example with ADVS
derive_var_worst_flag(
  advs,
  by_vars = vars(USUBJID, PARAMCD, AVISIT),
  order = vars(ADT, ATPTN),
  new_var = WORSTFL,
  param_var = PARAMCD,
  analysis_var = AVAL,
  worst_high = c("SYSBP", "DIABP"),
  worst_low = "RESP",
  filter = !is.na(AVISIT) & !is.na(AVAL)
)

## End(Not run)

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.