Skip to contents

Derive treatment emergent analysis flag (e.g., TRTEMFL).

Usage

derive_var_trtemfl(
  dataset,
  new_var = TRTEMFL,
  start_date = ASTDTM,
  end_date = AENDTM,
  trt_start_date = TRTSDTM,
  trt_end_date = NULL,
  end_window = NULL,
  ignore_time_for_trt_end = TRUE,
  initial_intensity = NULL,
  intensity = NULL,
  group_var = NULL,
  subject_keys = get_admiral_option("subject_keys")
)

Arguments

dataset

Input dataset

The variables specified by start_date, end_date, trt_start_date, trt_end_date, initial_intensity, and intensity are expected.

new_var

New variable

start_date

Event start date

Permitted Values: A symbol referring to a date or datetime variable of the input dataset

end_date

Event end date

Permitted Values: A symbol referring to a date or datetime variable of the input dataset

trt_start_date

Treatment start date

Permitted Values: A symbol referring to a date or datetime variable of the input dataset

trt_end_date

Treatment end date

Permitted Values: A symbol referring to a date or datetime variable of the input dataset or NULL

end_window

If the argument is specified (in 'days'), events starting more than the specified number of days after end of treatment, are not flagged.

Permitted Values: A non-negative integer or NULL

ignore_time_for_trt_end

If the argument is set to TRUE, the time part is ignored for checking if the event occurred more than end_window days after end of treatment.

Permitted Values: TRUE, FALSE

initial_intensity

Initial severity/intensity or toxicity

initial_intensity is ignored when group_var is specified.

If this argument is specified and group_var is NULL, events which start before treatment start and end after treatment start (or are ongoing) and worsened (i.e., the intensity is greater than the initial intensity), are flagged.

The values of the specified variable must be comparable with the usual comparison operators. I.e., if the intensity is greater than the initial intensity initial_intensity < intensity must evaluate to TRUE.

Permitted Values: A symbol referring to a variable of the input dataset or NULL

intensity

Severity/intensity or toxicity

If the argument is specified, events which start before treatment start and end after treatment start (or are ongoing) and worsened (i.e., the intensity is greater than the initial intensity), are flagged.

The values of the specified variable must be comparable with the usual comparison operators. I.e., if the intensity is greater than the initial intensity initial_intensity < intensity must evaluate to TRUE.

Permitted Values: A symbol referring to a variable of the input dataset or NULL

group_var

Grouping variable

If the argument is specified, it assumes that AEs are recorded as one episode of AE with multiple lines using a grouping variable.

Events starting during treatment or before treatment and worsening afterward are flagged. Once an AE record in a group is flagged, all subsequent records in the treatment window are flagged regardless of severity.

Permitted Values: A symbol referring to a variable of the input dataset or NULL

subject_keys

Variables to uniquely identify a subject.

A list of symbols created using exprs() is expected. This argument is only used when group_var is specified.

Value

The input dataset with the variable specified by new_var added

Details

For the derivation of the new variable the following cases are considered in this order. The first case which applies, defines the value of the variable.

  • not treated: If trt_start_date is NA, it is set to NA_character_.

  • event before treatment: If end_date is before trt_start_date (and end_date is not NA), it is set to NA_character_.

  • no event date: If start_date is NA, it is set to "Y" as in such cases it is usually considered more conservative to assume the event was treatment-emergent.

  • event started during treatment:

    • if end_window is not specified: if start_date is on or after trt_start_date, it is set to "Y",

    • if end_window is specified: if start_date is on or after trt_start_date and start_date is on or before trt_end_date + end_window days, it is set to "Y",

  • event started before treatment and (possibly) worsened on treatment:

    • if initial_intensity, intensity is specified and group_var is not specified: if initial_intensity < intensity and start_date is before trt_start_date and end_date is on or after trt_start_date or end_date is NA, it is set to "Y";

    • if group_var is specified: if previous intensity < intensity and start_date is after trt_start_date and end_date is on or after trt_start_date or end_date is NA, it is set to "Y";

  • Otherwise it is set to NA_character_.

See also

Examples


library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(lubridate)

adae <- tribble(
  ~USUBJID, ~ASTDTM,            ~AENDTM,            ~AEITOXGR, ~AETOXGR,
  # before treatment
  "1",      "2021-12-13T20:15", "2021-12-15T12:45", "1",       "1",
  "1",      "2021-12-14T20:15", "2021-12-14T22:00", "1",       "3",
  # starting before treatment and ending during treatment
  "1",      "2021-12-30T20:00", "2022-01-14T11:00", "1",       "3",
  "1",      "2021-12-31T20:15", "2022-01-01T01:23", "1",       "1",
  # starting during treatment
  "1",      "2022-01-01T12:00", "2022-01-02T23:25", "3",       "4",
  # after treatment
  "1",      "2022-05-10T11:00", "2022-05-10T13:05", "2",       "2",
  "1",      "2022-05-11T11:00", "2022-05-11T13:05", "2",       "2",
  # missing dates
  "1",      "",                 "",                 "3",       "4",
  "1",      "2021-12-30T09:00", "",                 "3",       "4",
  "1",      "2021-12-30T11:00", "",                 "3",       "3",
  "1",      "",                 "2022-01-04T09:00", "3",       "4",
  "1",      "",                 "2021-12-24T19:00", "3",       "4",
  "1",      "",                 "2022-06-04T09:00", "3",       "4",
  # without treatment
  "2",      "",                 "2021-12-03T12:00", "1",       "2",
  "2",      "2021-12-01T12:00", "2021-12-03T12:00", "1",       "2",
  "2",      "2021-12-06T18:00", "",                 "1",       "2"
) %>%
  mutate(
    ASTDTM = ymd_hm(ASTDTM),
    AENDTM = ymd_hm(AENDTM),
    TRTSDTM = if_else(USUBJID == "1", ymd_hm("2022-01-01T01:01"), ymd_hms("")),
    TRTEDTM = if_else(USUBJID == "1", ymd_hm("2022-04-30T23:59"), ymd_hms(""))
  )

# derive TRTEMFL without considering treatment end and worsening
derive_var_trtemfl(adae) %>% select(ASTDTM, AENDTM, TRTSDTM, TRTEMFL)
#> # A tibble: 16 × 4
#>    ASTDTM              AENDTM              TRTSDTM             TRTEMFL
#>    <dttm>              <dttm>              <dttm>              <chr>  
#>  1 2021-12-13 20:15:00 2021-12-15 12:45:00 2022-01-01 01:01:00 NA     
#>  2 2021-12-14 20:15:00 2021-12-14 22:00:00 2022-01-01 01:01:00 NA     
#>  3 2021-12-30 20:00:00 2022-01-14 11:00:00 2022-01-01 01:01:00 NA     
#>  4 2021-12-31 20:15:00 2022-01-01 01:23:00 2022-01-01 01:01:00 NA     
#>  5 2022-01-01 12:00:00 2022-01-02 23:25:00 2022-01-01 01:01:00 Y      
#>  6 2022-05-10 11:00:00 2022-05-10 13:05:00 2022-01-01 01:01:00 Y      
#>  7 2022-05-11 11:00:00 2022-05-11 13:05:00 2022-01-01 01:01:00 Y      
#>  8 NA                  NA                  2022-01-01 01:01:00 Y      
#>  9 2021-12-30 09:00:00 NA                  2022-01-01 01:01:00 NA     
#> 10 2021-12-30 11:00:00 NA                  2022-01-01 01:01:00 NA     
#> 11 NA                  2022-01-04 09:00:00 2022-01-01 01:01:00 Y      
#> 12 NA                  2021-12-24 19:00:00 2022-01-01 01:01:00 NA     
#> 13 NA                  2022-06-04 09:00:00 2022-01-01 01:01:00 Y      
#> 14 NA                  2021-12-03 12:00:00 NA                  NA     
#> 15 2021-12-01 12:00:00 2021-12-03 12:00:00 NA                  NA     
#> 16 2021-12-06 18:00:00 NA                  NA                  NA     

# derive TRTEM2FL taking treatment end and worsening into account
derive_var_trtemfl(
  adae,
  new_var = TRTEM2FL,
  trt_end_date = TRTEDTM,
  end_window = 10,
  initial_intensity = AEITOXGR,
  intensity = AETOXGR
) %>% select(ASTDTM, AENDTM, AEITOXGR, AETOXGR, TRTEM2FL)
#> # A tibble: 16 × 5
#>    ASTDTM              AENDTM              AEITOXGR AETOXGR TRTEM2FL
#>    <dttm>              <dttm>              <chr>    <chr>   <chr>   
#>  1 2021-12-13 20:15:00 2021-12-15 12:45:00 1        1       NA      
#>  2 2021-12-14 20:15:00 2021-12-14 22:00:00 1        3       NA      
#>  3 2021-12-30 20:00:00 2022-01-14 11:00:00 1        3       Y       
#>  4 2021-12-31 20:15:00 2022-01-01 01:23:00 1        1       NA      
#>  5 2022-01-01 12:00:00 2022-01-02 23:25:00 3        4       Y       
#>  6 2022-05-10 11:00:00 2022-05-10 13:05:00 2        2       Y       
#>  7 2022-05-11 11:00:00 2022-05-11 13:05:00 2        2       NA      
#>  8 NA                  NA                  3        4       Y       
#>  9 2021-12-30 09:00:00 NA                  3        4       Y       
#> 10 2021-12-30 11:00:00 NA                  3        3       NA      
#> 11 NA                  2022-01-04 09:00:00 3        4       Y       
#> 12 NA                  2021-12-24 19:00:00 3        4       NA      
#> 13 NA                  2022-06-04 09:00:00 3        4       Y       
#> 14 NA                  2021-12-03 12:00:00 1        2       NA      
#> 15 2021-12-01 12:00:00 2021-12-03 12:00:00 1        2       NA      
#> 16 2021-12-06 18:00:00 NA                  1        2       NA      

adae2 <- tribble(
  ~USUBJID, ~ASTDTM, ~AENDTM, ~AEITOXGR, ~AETOXGR, ~AEGRPID,
  # before treatment
  "1", "2021-12-13T20:15", "2021-12-15T12:45", "1", "1", "1",
  "1", "2021-12-14T20:15", "2021-12-14T22:00", "1", "3", "1",
  # starting before treatment and ending during treatment
  "1", "2021-12-30T20:15", "2022-01-14T01:23", "3", "3", "2",
  "1", "2022-01-05T20:00", "2022-06-01T11:00", "3", "1", "2",
  "1", "2022-01-10T20:15", "2022-01-11T01:23", "3", "2", "2",
  "1", "2022-01-13T20:15", "2022-03-01T01:23", "3", "1", "2",
  # starting during treatment
  "1", "2022-01-01T12:00", "2022-01-02T23:25", "4", "4", "3",

  # after treatment
  "1", "2022-05-10T11:00", "2022-05-10T13:05", "2", "2", "4",
  "1", "2022-05-10T12:00", "2022-05-10T13:05", "2", "2", "4",
  "1", "2022-05-11T11:00", "2022-05-11T13:05", "2", "2", "4",
  # missing dates
  "1", "", "", "3", "4", "5",
  "1", "2021-12-30T09:00", "", "3", "4", "5",
  "1", "2021-12-30T11:00", "", "3", "3", "5",
  "1", "", "2022-01-04T09:00", "3", "4", "5",
  "1", "", "2021-12-24T19:00", "3", "4", "5",
  "1", "", "2022-06-04T09:00", "3", "4", "5",
  # without treatment
  "2", "", "2021-12-03T12:00", "1", "2", "1",
  "2", "2021-12-01T12:00", "2021-12-03T12:00", "1", "2", "2",
  "2", "2021-12-06T18:00", "", "1", "2", "3"
) %>%
  mutate(
    STUDYID = "ABC12345",
    ASTDTM = ymd_hm(ASTDTM),
    AENDTM = ymd_hm(AENDTM),
    TRTSDTM = if_else(USUBJID == "1", ymd_hm("2022-01-01T01:01"), ymd_hms("")),
    TRTEDTM = if_else(USUBJID == "1", ymd_hm("2022-04-30T23:59"), ymd_hms(""))
  )
# derive TRTEMFL taking treatment end and worsening into account within a grouping variable
derive_var_trtemfl(
  adae2,
  new_var = TRTEMFL,
  trt_end_date = TRTEDTM,
  end_window = 10,
  intensity = AETOXGR,
  group_var = AEGRPID
) %>% select(ASTDTM, AENDTM, AEITOXGR, AETOXGR, AEGRPID, TRTEMFL)
#> # A tibble: 19 × 6
#>    ASTDTM              AENDTM              AEITOXGR AETOXGR AEGRPID TRTEMFL
#>    <dttm>              <dttm>              <chr>    <chr>   <chr>   <chr>  
#>  1 2021-12-13 20:15:00 2021-12-15 12:45:00 1        1       1       NA     
#>  2 2021-12-14 20:15:00 2021-12-14 22:00:00 1        3       1       NA     
#>  3 2021-12-30 20:15:00 2022-01-14 01:23:00 3        3       2       NA     
#>  4 2022-01-05 20:00:00 2022-06-01 11:00:00 3        1       2       NA     
#>  5 2022-01-10 20:15:00 2022-01-11 01:23:00 3        2       2       Y      
#>  6 2022-01-13 20:15:00 2022-03-01 01:23:00 3        1       2       Y      
#>  7 2022-01-01 12:00:00 2022-01-02 23:25:00 4        4       3       Y      
#>  8 2022-05-10 11:00:00 2022-05-10 13:05:00 2        2       4       Y      
#>  9 2022-05-10 12:00:00 2022-05-10 13:05:00 2        2       4       Y      
#> 10 2022-05-11 11:00:00 2022-05-11 13:05:00 2        2       4       NA     
#> 11 2021-12-30 09:00:00 NA                  3        4       5       NA     
#> 12 2021-12-30 11:00:00 NA                  3        3       5       NA     
#> 13 NA                  NA                  3        4       5       Y      
#> 14 NA                  2022-01-04 09:00:00 3        4       5       Y      
#> 15 NA                  2021-12-24 19:00:00 3        4       5       NA     
#> 16 NA                  2022-06-04 09:00:00 3        4       5       Y      
#> 17 NA                  2021-12-03 12:00:00 1        2       1       NA     
#> 18 2021-12-01 12:00:00 2021-12-03 12:00:00 1        2       2       NA     
#> 19 2021-12-06 18:00:00 NA                  1        2       3       NA