library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(lubridate)
data("admiral_adsl")
adsl <- admiral_adsl
# derive overall survival parameter
death <- event_source(
dataset_name = "adsl",
filter = DTHFL == "Y",
date = DTHDT,
set_values_to = exprs(
EVNTDESC = "DEATH",
SRCDOM = "ADSL",
SRCVAR = "DTHDT"
)
)
last_alive_dt <- censor_source(
dataset_name = "adsl",
date = LSTALVDT,
set_values_to = exprs(
EVNTDESC = "LAST DATE KNOWN ALIVE",
SRCDOM = "ADSL",
SRCVAR = "LSTALVDT"
)
)
derive_param_tte(
dataset_adsl = adsl,
event_conditions = list(death),
censor_conditions = list(last_alive_dt),
source_datasets = list(adsl = adsl),
set_values_to = exprs(
PARAMCD = "OS",
PARAM = "Overall Survival"
)
) %>%
select(-STUDYID) %>%
filter(row_number() %in% 20:30)
# derive duration of response
# only observations for subjects in dataset_adsl are created
adsl <- tribble(
~USUBJID, ~DTHFL, ~DTHDT, ~RSPDT,
"01", "Y", ymd("2021-06-12"), ymd("2021-03-04"),
"02", "N", NA, NA,
"03", "Y", ymd("2021-08-21"), NA,
"04", "N", NA, ymd("2021-04-14")
) %>%
mutate(STUDYID = "AB42")
adrs <- tribble(
~USUBJID, ~AVALC, ~ADT, ~ASEQ,
"01", "SD", ymd("2021-01-03"), 1,
"01", "PR", ymd("2021-03-04"), 2,
"01", "PD", ymd("2021-05-05"), 3,
"02", "PD", ymd("2021-02-03"), 1,
"04", "SD", ymd("2021-02-13"), 1,
"04", "PR", ymd("2021-04-14"), 2,
"04", "CR", ymd("2021-05-15"), 3
) %>%
mutate(STUDYID = "AB42", PARAMCD = "OVR")
pd <- event_source(
dataset_name = "adrs",
filter = AVALC == "PD",
date = ADT,
set_values_to = exprs(
EVENTDESC = "PD",
SRCDOM = "ADRS",
SRCVAR = "ADTM",
SRCSEQ = ASEQ
)
)
death <- event_source(
dataset_name = "adsl",
filter = DTHFL == "Y",
date = DTHDT,
set_values_to = exprs(
EVENTDESC = "DEATH",
SRCDOM = "ADSL",
SRCVAR = "DTHDT"
)
)
lastvisit <- censor_source(
dataset_name = "adrs",
date = ADT,
censor = 1,
set_values_to = exprs(
EVENTDESC = "LAST TUMOR ASSESSMENT",
SRCDOM = "ADRS",
SRCVAR = "ADTM",
SRCSEQ = ASEQ
)
)
first_response <- censor_source(
dataset_name = "adsl",
date = RSPDT,
censor = 1,
set_values_to = exprs(
EVENTDESC = "FIRST RESPONSE",
SRCDOM = "ADSL",
SRCVAR = "RSPDT"
)
)
derive_param_tte(
dataset_adsl = filter(adsl, !is.na(RSPDT)),
start_date = RSPDT,
event_conditions = list(pd, death),
censor_conditions = list(lastvisit, first_response),
source_datasets = list(adsl = adsl, adrs = adrs),
set_values_to = exprs(
PARAMCD = "DURRSP",
PARAM = "Duration of Response"
)
)
# derive time to adverse event for each preferred term
adsl <- tribble(
~USUBJID, ~TRTSDT, ~EOSDT,
"01", ymd("2020-12-06"), ymd("2021-03-06"),
"02", ymd("2021-01-16"), ymd("2021-02-03")
) %>%
mutate(STUDYID = "AB42")
ae <- tribble(
~USUBJID, ~AESTDTC, ~AESEQ, ~AEDECOD,
"01", "2021-01-03T10:56", 1, "Flu",
"01", "2021-03-04", 2, "Cough",
"01", "2021", 3, "Flu"
) %>%
mutate(STUDYID = "AB42")
ae_ext <- derive_vars_dt(
ae,
dtc = AESTDTC,
new_vars_prefix = "AEST",
highest_imputation = "M",
flag_imputation = "none"
)
ttae <- event_source(
dataset_name = "ae",
date = AESTDT,
set_values_to = exprs(
EVNTDESC = "AE",
SRCDOM = "AE",
SRCVAR = "AESTDTC",
SRCSEQ = AESEQ
)
)
eos <- censor_source(
dataset_name = "adsl",
date = EOSDT,
set_values_to = exprs(
EVNTDESC = "END OF STUDY",
SRCDOM = "ADSL",
SRCVAR = "EOSDT"
)
)
derive_param_tte(
dataset_adsl = adsl,
by_vars = exprs(AEDECOD),
start_date = TRTSDT,
event_conditions = list(ttae),
censor_conditions = list(eos),
source_datasets = list(adsl = adsl, ae = ae_ext),
set_values_to = exprs(
PARAMCD = paste0("TTAE", as.numeric(as.factor(AEDECOD))),
PARAM = paste("Time to First", AEDECOD, "Adverse Event"),
PARCAT1 = "TTAE",
PARCAT2 = AEDECOD
)
) %>%
select(USUBJID, STARTDT, PARAMCD, PARAM, ADT, CNSR, SRCSEQ)
Run the code above in your browser using DataLab