-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathad_adtte.R
More file actions
92 lines (81 loc) · 2.72 KB
/
ad_adtte.R
File metadata and controls
92 lines (81 loc) · 2.72 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Name: ADTTE
#
# Label: Time to Event Analysis Dataset
#
# Input: adsl, adrs, tte_source objects
library(admiral)
library(admiralonco)
# pharmaverseadam contains example datasets generated from the CDISC pilot
# project SDTM ran through admiral templates
#library(pharmaverseadam)
library(dplyr)
library(lubridate)
# Load source datasets ----
# Use e.g. haven::read_sas to read in .sas7bdat, or other suitable functions
# as needed and assign to the variables below.
# For illustration purposes read in admiral test data
data("adsl")
data("adrs_onco")
adrs <- adrs_onco
# Derivations ----
# Add response date to ADSL for duration of response calculation
adsl <- adsl %>%
derive_vars_merged(
dataset_add = adrs,
filter_add = PARAMCD == "RSP" & AVALC == "Y" & ANL01FL == "Y",
by_vars = get_admiral_option("subject_keys"),
new_vars = exprs(TEMP_RESPDT = ADT)
)
# Use pre-defined tte_source objects to derive Overall Survival, Progression
# Free Survival and Duration of Response
adtte <- derive_param_tte(
dataset_adsl = adsl,
start_date = RANDDT,
event_conditions = list(death_event),
censor_conditions = list(lastalive_censor, rand_censor),
source_datasets = list(adsl = adsl, adrs = adrs),
set_values_to = exprs(PARAMCD = "OS", PARAM = "Overall Survival")
) %>%
derive_param_tte(
dataset_adsl = adsl,
start_date = RANDDT,
event_conditions = list(pd_event, death_event),
censor_conditions = list(lasta_censor, rand_censor),
source_datasets = list(adsl = adsl, adrs = adrs),
set_values_to = exprs(PARAMCD = "PFS", PARAM = "Progression Free Survival")
) %>%
derive_param_tte(
dataset_adsl = filter(adsl, !is.na(TEMP_RESPDT)),
start_date = TEMP_RESPDT,
event_conditions = list(pd_event, death_event),
censor_conditions = list(lasta_censor),
source_datasets = list(adsl = adsl, adrs = adrs),
set_values_to = exprs(PARAMCD = "RSD", PARAM = "Duration of Response")
)
# Derive analysis value and sequence
adtte <- adtte %>%
derive_vars_duration(
new_var = AVAL,
start_date = STARTDT,
end_date = ADT
) %>%
derive_var_obs_number(
by_vars = get_admiral_option("subject_keys"),
order = exprs(PARAMCD),
check_type = "error"
)
# Join any required ADSL variables
adtte <- adtte %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = exprs(ARMCD, ARM, ACTARMCD, ACTARM, AGE, SEX),
by_vars = get_admiral_option("subject_keys")
)
# Save output ----
# Change to whichever directory you want to save the dataset in
dir <- tools::R_user_dir("admiralonco_templates_data", which = "cache")
if (!file.exists(dir)) {
# Create the folder
dir.create(dir, recursive = TRUE, showWarnings = FALSE)
}
save(adtte, file = file.path(dir, "adtte.rda"), compress = "bzip2")