View source: R/derive_var_extreme_date.R
derive_var_extreme_dt | R Documentation |
The derive_var_extreme_dt()
function has been superseded in favor of derive_vars_extreme_event()
.
Add the first or last date from multiple sources to the
dataset, e.g., the last known alive date (LSTALVDT
).
Note: This is a wrapper function for the function derive_var_extreme_dtm()
.
derive_var_extreme_dt(
dataset,
new_var,
...,
source_datasets,
mode,
subject_keys = get_admiral_option("subject_keys")
)
dataset |
Input dataset The variables specified by the |
new_var |
Name of variable to create |
... |
Source(s) of dates. One or more |
source_datasets |
A named |
mode |
Selection mode (first or last) If Permitted Values: |
subject_keys |
Variables to uniquely identify a subject A list of expressions where the expressions are symbols as returned by
|
The following steps are performed to create the output dataset:
For each source dataset the observations as specified by the filter
element are selected and observations where date
is NA
are removed.
Then for each patient the first or last observation (with respect to date
and mode
) is selected.
The new variable is set to the variable or expression specified by the
date
element.
The variables specified by the set_values_to
element are added.
The selected observations of all source datasets are combined into a single dataset.
For each patient the first or last observation (with respect to the new
variable and mode
) from the single dataset is selected and the new
variable is merged to the input dataset.
The time part is removed from the new variable.
The input dataset with the new variable added.
date_source()
, derive_var_extreme_dtm()
, derive_vars_merged()
Other superseded:
date_source()
,
derive_param_extreme_record()
,
derive_var_dthcaus()
,
derive_var_extreme_dtm()
,
dthcaus_source()
,
get_summary_records()
library(dplyr, warn.conflicts = FALSE)
ae <- tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~AESEQ, ~AESTDTC, ~AEENDTC,
"PILOT01", "AE", "01-1130", 5, "2014-05-09", "2014-05-09",
"PILOT01", "AE", "01-1130", 6, "2014-05-22", NA,
"PILOT01", "AE", "01-1130", 4, "2014-05-09", "2014-05-09",
"PILOT01", "AE", "01-1130", 8, "2014-05-22", NA,
"PILOT01", "AE", "01-1130", 7, "2014-05-22", NA,
"PILOT01", "AE", "01-1130", 2, "2014-03-09", "2014-03-09",
"PILOT01", "AE", "01-1130", 1, "2014-03-09", "2014-03-16",
"PILOT01", "AE", "01-1130", 3, "2014-03-09", "2014-03-16",
"PILOT01", "AE", "01-1133", 1, "2012-12-27", NA,
"PILOT01", "AE", "01-1133", 3, "2012-12-27", NA,
"PILOT01", "AE", "01-1133", 2, "2012-12-27", NA,
"PILOT01", "AE", "01-1133", 4, "2012-12-27", NA,
"PILOT01", "AE", "01-1211", 5, "2012-11-29", NA,
"PILOT01", "AE", "01-1211", 1, "2012-11-16", NA,
"PILOT01", "AE", "01-1211", 7, "2013-01-11", NA,
"PILOT01", "AE", "01-1211", 8, "2013-01-11", NA,
"PILOT01", "AE", "01-1211", 4, "2012-11-22", NA,
"PILOT01", "AE", "01-1211", 2, "2012-11-21", "2012-11-21",
"PILOT01", "AE", "01-1211", 3, "2012-11-21", NA,
"PILOT01", "AE", "01-1211", 6, "2012-12-09", NA,
"PILOT01", "AE", "01-1211", 9, "2013-01-14", "2013-01-14",
"PILOT01", "AE", "09-1081", 2, "2014-05-01", NA,
"PILOT01", "AE", "09-1081", 1, "2014-04-07", NA,
"PILOT01", "AE", "09-1088", 1, "2014-05-08", NA,
"PILOT01", "AE", "09-1088", 2, "2014-08-02", NA
)
adsl <- tribble(
~STUDYID, ~USUBJID, ~TRTEDTM, ~TRTEDT,
"PILOT01", "01-1130", "2014-08-16 23:59:59", "2014-08-16",
"PILOT01", "01-1133", "2013-04-28 23:59:59", "2013-04-28",
"PILOT01", "01-1211", "2013-01-12 23:59:59", "2013-01-12",
"PILOT01", "09-1081", "2014-04-27 23:59:59", "2014-04-27",
"PILOT01", "09-1088", "2014-10-09 23:59:59", "2014-10-09"
) %>%
mutate(
across(TRTEDTM:TRTEDT, as.Date)
)
lb <- tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~LBSEQ, ~LBDTC,
"PILOT01", "LB", "01-1130", 219, "2014-06-07T13:20",
"PILOT01", "LB", "01-1130", 322, "2014-08-16T13:10",
"PILOT01", "LB", "01-1133", 268, "2013-04-18T15:30",
"PILOT01", "LB", "01-1133", 304, "2013-04-29T10:13",
"PILOT01", "LB", "01-1211", 8, "2012-10-30T14:26",
"PILOT01", "LB", "01-1211", 162, "2013-01-08T12:13",
"PILOT01", "LB", "09-1081", 47, "2014-02-01T10:55",
"PILOT01", "LB", "09-1081", 219, "2014-05-10T11:15",
"PILOT01", "LB", "09-1088", 283, "2014-09-27T12:13",
"PILOT01", "LB", "09-1088", 322, "2014-10-09T13:25"
)
dm <- tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~AGE, ~AGEU,
"PILOT01", "DM", "01-1130", 84, "YEARS",
"PILOT01", "DM", "01-1133", 81, "YEARS",
"PILOT01", "DM", "01-1211", 76, "YEARS",
"PILOT01", "DM", "09-1081", 86, "YEARS",
"PILOT01", "DM", "09-1088", 69, "YEARS"
)
ae_start <- date_source(
dataset_name = "ae",
date = convert_dtc_to_dt(AESTDTC, highest_imputation = "M")
)
ae_end <- date_source(
dataset_name = "ae",
date = convert_dtc_to_dt(AEENDTC, highest_imputation = "M")
)
ae_ext <- ae %>%
derive_vars_dt(
dtc = AESTDTC,
new_vars_prefix = "AEST",
highest_imputation = "M"
) %>%
derive_vars_dt(
dtc = AEENDTC,
new_vars_prefix = "AEEN",
highest_imputation = "M"
)
lb_date <- date_source(
dataset_name = "lb",
date = convert_dtc_to_dt(LBDTC)
)
lb_ext <- derive_vars_dt(
lb,
dtc = LBDTC,
new_vars_prefix = "LB"
)
adsl_date <- date_source(dataset_name = "adsl", date = TRTEDT)
dm %>%
derive_var_extreme_dt(
new_var = LSTALVDT,
ae_start, ae_end, lb_date, adsl_date,
source_datasets = list(
adsl = adsl,
ae = ae_ext,
lb = lb_ext
),
mode = "last"
) %>%
select(USUBJID, LSTALVDT)
# derive last alive date and traceability variables
ae_start <- date_source(
dataset_name = "ae",
date = convert_dtc_to_dt(AESTDTC, highest_imputation = "M"),
set_values_to = exprs(
LALVDOM = "AE",
LALVSEQ = AESEQ,
LALVVAR = "AESTDTC"
)
)
ae_end <- date_source(
dataset_name = "ae",
date = convert_dtc_to_dt(AEENDTC, highest_imputation = "M"),
set_values_to = exprs(
LALVDOM = "AE",
LALVSEQ = AESEQ,
LALVVAR = "AEENDTC"
)
)
lb_date <- date_source(
dataset_name = "lb",
date = convert_dtc_to_dt(LBDTC),
set_values_to = exprs(
LALVDOM = "LB",
LALVSEQ = LBSEQ,
LALVVAR = "LBDTC"
)
)
adsl_date <- date_source(
dataset_name = "adsl",
date = TRTEDT,
set_values_to = exprs(
LALVDOM = "ADSL",
LALVSEQ = NA_integer_,
LALVVAR = "TRTEDT"
)
)
dm %>%
derive_var_extreme_dt(
new_var = LSTALVDT,
ae_start, ae_end, lb_date, adsl_date,
source_datasets = list(
adsl = adsl,
ae = ae_ext,
lb = lb_ext
),
mode = "last"
) %>%
select(USUBJID, LSTALVDT, LALVDOM, LALVSEQ, LALVVAR)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.