Add a variable for dose amount from the last dose to the input dataset.
Arguments
- dataset
Input dataset. The variables specified by the
by_vars
andanalysis_date
parameters are expected.- dataset_ex
Input EX dataset. The variables specified by the
by_vars
,dose_date
,new_vars
parameters, and source variables fromtraceability_vars
parameter are expected.- filter_ex
Filtering condition applied to EX dataset. For example, it can be used to filter for valid dose. Defaults to NULL.
- by_vars
Variables to join by (created by
rlang::exprs
).- dose_id
Variables to identify unique dose (created by
rlang::exprs
). Defaults to emptyexprs()
.- dose_date
The EX dose date variable. A date or date-time object is expected.
- analysis_date
The analysis date variable. A date or date-time object is expected.
- single_dose_condition
The condition for checking if
dataset_ex
is single dose. An error is issued if the condition is not true. Defaults to(EXDOSFRQ == "ONCE")
.- new_var
The new variable added to
dataset
.- dose_var
The EX source dose amount variable. Defaults to
EXDOSE
.- traceability_vars
A named list returned by
exprs()
listing the traceability variables, e.g.exprs(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)
. The left-hand side (names of the list elements) gives the names of the traceability variables in the returned dataset. The right-hand side (values of the list elements) gives the values of the traceability variables in the returned dataset. These can be either strings or symbols referring to existing variables.
Details
The last dose amount is derived as the dose amount where the maximum dose_date
is
lower to or equal to the analysis_date
per by_vars
for each observation in dataset
.
If dose information is aggregated (i.e. is a dosing frequency other than "ONCE"
over a period defined by a start and end date) the function
create_single_dose_dataset()
can be used to generate single doses from
aggregate dose information and satisfy single_dose_condition
.
See also
derive_vars_last_dose()
, create_single_dose_dataset()
General Derivation Functions for all ADaMs that returns variable appended to dataset:
derive_var_extreme_flag()
,
derive_var_joined_exist_flag()
,
derive_var_last_dose_date()
,
derive_var_last_dose_grp()
,
derive_var_merged_cat()
,
derive_var_merged_character()
,
derive_var_merged_exist_flag()
,
derive_var_merged_summary()
,
derive_var_obs_number()
,
derive_var_relative_flag()
,
derive_vars_joined()
,
derive_vars_last_dose()
,
derive_vars_merged_lookup()
,
derive_vars_merged()
,
derive_vars_transposed()
,
get_summary_records()
Examples
library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data(admiral_ae)
data(ex_single)
ex_single <- derive_vars_dtm(
head(ex_single, 100),
dtc = EXENDTC,
new_vars_prefix = "EXEN",
flag_imputation = "none"
)
adae <- admiral_ae %>%
head(100) %>%
derive_vars_dtm(
dtc = AESTDTC,
new_vars_prefix = "AST",
highest_imputation = "M"
)
adae %>%
derive_var_last_dose_amt(
dataset_ex = ex_single,
filter_ex = (EXDOSE > 0 | (EXDOSE == 0 & grepl("PLACEBO", EXTRT))) &
!is.na(EXENDTM),
dose_date = EXENDTM,
analysis_date = ASTDTM,
new_var = LDOSE,
dose_var = EXDOSE
) %>%
select(STUDYID, USUBJID, AESEQ, AESTDTC, LDOSE)
#> # A tibble: 100 x 5
#> STUDYID USUBJID AESEQ AESTDTC LDOSE
#> <chr> <chr> <dbl> <chr> <dbl>
#> 1 CDISCPILOT01 01-701-1015 1 2014-01-03 NA
#> 2 CDISCPILOT01 01-701-1015 2 2014-01-03 NA
#> 3 CDISCPILOT01 01-701-1015 3 2014-01-09 NA
#> 4 CDISCPILOT01 01-701-1023 3 2012-08-26 0
#> 5 CDISCPILOT01 01-701-1023 1 2012-08-07 0
#> 6 CDISCPILOT01 01-701-1023 2 2012-08-07 0
#> 7 CDISCPILOT01 01-701-1023 4 2012-08-07 0
#> 8 CDISCPILOT01 01-701-1028 1 2013-07-21 NA
#> 9 CDISCPILOT01 01-701-1028 2 2013-08-08 NA
#> 10 CDISCPILOT01 01-701-1034 1 2014-08-27 NA
#> # … with 90 more rows
# or with traceability variables
adae %>%
derive_var_last_dose_amt(
dataset_ex = ex_single,
filter_ex = (EXDOSE > 0 | (EXDOSE == 0 & grepl("PLACEBO", EXTRT))) &
!is.na(EXENDTM),
dose_date = EXENDTM,
analysis_date = ASTDTM,
new_var = LDOSE,
dose_var = EXDOSE,
traceability_vars = exprs(
LDOSEDOM = "EX",
LDOSESEQ = EXSEQ,
LDOSEVAR = "EXDOSE"
)
) %>%
select(STUDYID, USUBJID, AESEQ, AESTDTC, LDOSEDOM, LDOSESEQ, LDOSEVAR, LDOSE)
#> # A tibble: 100 x 8
#> STUDYID USUBJID AESEQ AESTDTC LDOSEDOM LDOSESEQ LDOSEVAR LDOSE
#> <chr> <chr> <dbl> <chr> <chr> <int> <chr> <dbl>
#> 1 CDISCPILOT01 01-701-1015 1 2014-01-03 NA NA NA NA
#> 2 CDISCPILOT01 01-701-1015 2 2014-01-03 NA NA NA NA
#> 3 CDISCPILOT01 01-701-1015 3 2014-01-09 NA NA NA NA
#> 4 CDISCPILOT01 01-701-1023 3 2012-08-26 EX 7 EXDOSE 0
#> 5 CDISCPILOT01 01-701-1023 1 2012-08-07 EX 3 EXDOSE 0
#> 6 CDISCPILOT01 01-701-1023 2 2012-08-07 EX 3 EXDOSE 0
#> 7 CDISCPILOT01 01-701-1023 4 2012-08-07 EX 3 EXDOSE 0
#> 8 CDISCPILOT01 01-701-1028 1 2013-07-21 NA NA NA NA
#> 9 CDISCPILOT01 01-701-1028 2 2013-08-08 NA NA NA NA
#> 10 CDISCPILOT01 01-701-1034 1 2014-08-27 NA NA NA NA
#> # … with 90 more rows