Description Usage Arguments Details Value Author(s) Examples
View source: R/derive_var_ontrtfl.R
Derive on-treatment flag (ONTRTFL
) in an ADaM dataset with a single
assessment date (e.g ADT
) or event start and end dates (e.g. ASTDT
/AENDT
).
1 2 3 4 5 6 7 8 9 10 11 | derive_var_ontrtfl(
dataset,
new_var = ONTRTFL,
start_date,
end_date = NULL,
ref_start_date,
ref_end_date = NULL,
ref_end_window = 0,
filter_pre_timepoint = NULL,
span_period = NULL
)
|
dataset |
Input dataset. Required columns are |
new_var |
On-treatment flag variable name to be created. Default is |
start_date |
The start date (e.g. |
end_date |
The end date of assessment/event (e.g. |
ref_start_date |
The lower bound of the on-treatment period Required; A date or date-time object column is expected. |
ref_end_date |
The upper bound of the on-treatment period
A date or date-time object column is expected.
Optional; This can be null and everything after |
ref_end_window |
A window to add to the upper bound |
filter_pre_timepoint |
An expression to filter observations as not
on-treatment when |
span_period |
A |
On-Treatment is calculated by determining whether the assessment date or
start/stop dates fall between 2 dates. The following logic is used to
assign on-treatment = "Y"
:
start_date
is missing and ref_start_date
is non-missing
No timepoint filter is provided (filter_pre_timepoint
) and both
start_date
and ref_start_date
are non-missing and start_date
=
ref_start_date
A timepoint is provided (filter_pre_timepoint
) and both start_date
and ref_start_date
are non-missing and start_date = ref_start_date
and the filter provided in filter_pre_timepoint
is not true.
ref_end_date
is not provided and ref_start_date < start_date
ref_end_date
is provided and ref_start_date < start_date
<=
ref_end_date + ref_end_window
.
If the end_date
is provided and the end_date
< ref_start_date
then the ONTRTFL
is set to NULL
.This would be applicable to cases where
the start_date
is missing and ONTRTFL
has been assigned as "Y"
above.
If the span_period
is specified as "Y"
, this allows the user to assign ONTRTFL
as "Y"
to
cases where the record started prior to the 'ref_start_dateand was ongoing or ended after the
ref_end_date'.
Any date imputations needed should be done prior to calling this function.
The input dataset with an additional column named
ONTRTFL
with a value of "Y"
or NA
Alice Ehmann, Teckla Akinyi
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | library(lubridate, warn.conflict = FALSE)
advs <- tibble::tribble(
~USUBJID, ~ADT, ~TRTSDT, ~TRTEDT,
"P01", ymd("2020-02-24"), ymd("2020-01-01"), ymd("2020-03-01"),
"P02", ymd("2020-01-01"), ymd("2020-01-01"), ymd("2020-03-01"),
"P03", ymd("2019-12-31"), ymd("2020-01-01"), ymd("2020-03-01")
)
derive_var_ontrtfl(
advs,
start_date = ADT,
ref_start_date = TRTSDT,
ref_end_date = TRTEDT
)
advs <- tibble::tribble(
~USUBJID, ~ADT, ~TRTSDT, ~TRTEDT,
"P01", ymd("2020-07-01"), ymd("2020-01-01"), ymd("2020-03-01"),
"P02", ymd("2020-04-30"), ymd("2020-01-01"), ymd("2020-03-01"),
"P03", ymd("2020-03-15"), ymd("2020-01-01"), ymd("2020-03-01")
)
derive_var_ontrtfl(
advs,
start_date = ADT,
ref_start_date = TRTSDT,
ref_end_date = TRTEDT,
ref_end_window = 60
)
advs <- tibble::tribble(
~USUBJID, ~ADTM, ~TRTSDTM, ~TRTEDTM, ~TPT,
"P01", ymd("2020-01-02T12:00"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"), NA,
"P02", ymd("2020-01-01"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"), "PRE",
"P03", ymd("2019-12-31"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"), NA
)
derive_var_ontrtfl(
advs,
start_date = ADTM,
ref_start_date = TRTSDTM,
ref_end_date = TRTEDTM,
filter_pre_timepoint = TPT == "PRE"
)
advs <- tibble::tribble(
~USUBJID, ~ASTDT, ~TRTSDT, ~TRTEDT, ~AENDT,
"P01", ymd("2020-03-15"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-12-01"),
"P02", ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-03-15"),
"P03", ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), NA,
)
derive_var_ontrtfl(
advs,
start_date = ASTDT,
end_date = AENDT,
ref_start_date = TRTSDT,
ref_end_date = TRTEDT,
ref_end_window = 60,
span_period = "Y"
)
advs <- tibble::tribble(
~USUBJID, ~ASTDT, ~AP01SDT, ~AP01EDT, ~AENDT,
"P01", ymd("2020-03-15"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-12-01"),
"P02", ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-03-15"),
"P03", ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), NA,
)
derive_var_ontrtfl(
advs,
new_var = ONTR01FL,
start_date = ASTDT,
end_date = AENDT,
ref_start_date = AP01SDT,
ref_end_date = AP01EDT,
span_period = "Y"
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.