Description Usage Arguments Details Value Author(s) Examples
View source: R/derive_vars_last_dose.R
Add EX source variables from last dose to the input dataset.
1 2 3 4 5 6 7 8 9 10 11 12 |
dataset |
Input dataset.
The variables specified by the |
dataset_ex |
Input EX dataset.
The variables specified by the |
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 |
dose_id |
Variables to identify unique dose (created by |
dose_date |
The EX dose date variable. |
analysis_date |
The analysis date variable. |
single_dose_condition |
The condition for checking if |
new_vars |
Variables to keep from |
traceability_vars |
A named list returned by |
All date (date-time) variables can be characters in standard ISO format or
of date / date-time class.
For ISO format, see impute_dtc
- parameter dtc
for further details.
When doing date comparison to identify last dose, date-time imputations are done as follows:
dose_date
: no date imputation, time imputation to 00:00:00
if time is missing.
analysis_date
: no date imputation, time imputation to 23:59:59
if time is missing.
The last dose records are identified as follows:
The dataset_ex
is filtered using filter_ex
, if provided.
This is useful for, for example, filtering for valid dose only.
The datasets dataset
and dataset_ex
are joined using by_vars
.
The last dose is identified:
the last dose is the EX record with maximum date where dose_date
is lower to or equal to
analysis_date
, subject to both date values are non-NA.
The last dose is identified per by_vars
.
If multiple EX records exist for the same dose_date
, then either dose_id
needs to be supplied (e.g. dose_id = vars(EXSEQ)
) to identify unique records,
or an error is issued. When dose_id
is supplied, the last EX record from the same dose_date
sorted by dose_id
will be used to identify last dose.
The EX source variables (as specified in new_vars
) from last dose are appended to the
dataset
and returned to the user.
This function only works correctly for EX dataset with a structure of single dose per row.
If your study EX dataset has multiple doses per row, use expansion_function_name??
to
transform the EX dataset into single dose per row structure before calling
derive_vars_last_dose
.
If variables (other than those specified in by_vars
) exist in both dataset
and dataset_ex
,
then join cannot be performed properly and an error is issued. To resolve the error, use
new_vars
to either keep variables unique to dataset_ex
, or use this option to rename
variables from dataset_ex
(e.g. new_vars = vars(LSTEXVIS = VISIT)
).
Input dataset with EX source variables from last dose added.
Ondrej Slama, Annie Yang
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 | library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data(ae)
data(ex_single)
ae %>%
head(100) %>%
derive_vars_last_dose(
head(ex_single, 100),
filter_ex = (EXDOSE > 0 | (EXDOSE == 0 & grepl("PLACEBO", EXTRT))) &
nchar(EXENDTC) >= 10,
new_vars = vars(EXDOSE, EXTRT, EXSEQ, EXENDTC, VISIT),
dose_date = EXENDTC,
analysis_date = AESTDTC,
single_dose_condition = (EXSTDTC == EXENDTC)
) %>%
select(STUDYID, USUBJID, AESEQ, AESTDTC, EXDOSE, EXTRT, EXENDTC, EXSEQ, VISIT)
# or with traceability variables
ae %>%
head(100) %>%
derive_vars_last_dose(
head(ex_single, 100),
filter_ex = (EXDOSE > 0 | (EXDOSE == 0 & grepl("PLACEBO", EXTRT))) &
nchar(EXENDTC) >= 10,
new_vars = vars(EXDOSE, EXTRT, EXSEQ, EXENDTC, VISIT),
dose_date = EXENDTC,
analysis_date = AESTDTC,
single_dose_condition = (EXSTDTC == EXENDTC),
traceability_vars = dplyr::vars(LDOSEDOM = "EX", LDOSESEQ = EXSEQ, LDOSEVAR = "EXENDTC")
) %>%
select(STUDYID, USUBJID, AESEQ, AESTDTC, EXDOSE, EXTRT, EXENDTC, LDOSEDOM, LDOSESEQ, LDOSEVAR)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.