-
Notifications
You must be signed in to change notification settings - Fork 4
/
meta_ae_example.R
203 lines (190 loc) · 5.57 KB
/
meta_ae_example.R
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the metalite.ae program.
#
# metalite.ae is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#' Create an example `meta_adam` object
#'
#' This function is only for illustration purpose.
#' r2rtf is required.
#'
#' @return A metadata object.
#'
#' @export
#'
#' @examples
#' meta <- meta_ae_example()
meta_ae_example <- function() {
# Create adsl ----
adsl <- r2rtf::r2rtf_adsl
adsl$TRTA <- adsl$TRT01A
adsl$TRTA <- factor(
adsl$TRTA,
levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
labels = c("Placebo", "Low Dose", "High Dose")
)
adsl$RACE <- tools::toTitleCase(adsl$RACE)
# Create adae ----
adae <- r2rtf::r2rtf_adae
adae$TRTA <- factor(
adae$TRTA,
levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
labels = c("Placebo", "Low Dose", "High Dose")
)
adae$RACE <- tools::toTitleCase(adae$RACE)
# Drug-related AE values
adae$related <- ifelse(
adae$AEREL == "RELATED",
"Y",
ifelse(
toupper(adae$AEREL) == "NOT RELATED",
"N",
tools::toTitleCase(tolower(adae$AEREL))
)
)
# AE outcome
for (i in seq_along(adae$AEOUT)) {
adae$outcome <- switch(adae$AEOUT[i],
"RECOVERED/RESOLVED" = "Resolved",
"RECOVERING/RESOLVING" = "Resolving",
"RECOVERED/RESOLVED WITH SEQUELAE" = "Sequelae",
"NOT RECOVERED/NOT RESOLVED" = "Not Resolved",
tools::toTitleCase(tolower(adae$AEOUT[i]))
)
}
# AE action
adae$AEACN <- gsub("", "DOSE NOT CHANGED", adae$AEACN)
for (i in seq_along(adae$AEACN)) {
adae$action_taken[i] <- switch(adae$AEACN[i],
"DOSE NOT CHANGED" = "None",
"DOSE REDUCED" = "Reduced",
"DRUG INTERRUPTED" = "Interrupted",
"DOSE INCREASED" = "Increased",
"NOT APPLICABLE" = "N/A",
"UNKNOWN" = "Unknown",
"''" = "None",
tools::toTitleCase(tolower(adae$AEACN[i]))
)
}
# AE duration with unit
adae$duration <- paste(
ifelse(
is.na(adae$ADURN),
"",
as.character(adae$ADURN)
),
tools::toTitleCase(tolower(adae$ADURU)),
sep = " "
)
for (i in seq_along(adae$duration)) {
if (is.na(adae$ADURN[i])) {
adae$duration[i] <- ifelse(
charmatch(toupper(adae$AEOUT[i]), "RECOVERING/RESOLVING") > 0 |
charmatch(toupper(adae$AEOUT[i]), "NOT RECOVERED/NOT RESOLVED") > 0,
"Continuing",
"Unknown"
)
}
}
# AE subject line
adae$subline <- paste0(
"Subject ID = ", adae$USUBJID,
", Gender = ", adae$SEX,
", Race = ", adae$RACE,
", AGE = ", adae$AGE, " Years",
", TRT = ", adae$TRTA
)
# Assign label
adae <- metalite::assign_label(
adae,
var = c("related", "outcome", "duration", "AESEV", "AESER", "AEDECOD", "action_taken"),
label = c("Related", "Outcome", "Duration", "Intensity", "Serious", "Adverse Event", "Action Taken")
)
# Define plan ----
plan <- plan(
analysis = "ae_summary", population = "apat",
observation = c("wk12", "wk24"), parameter = "any;rel;ser"
) |>
add_plan(
analysis = "ae_specific", population = "apat",
observation = c("wk12", "wk24"),
parameter = c("any", "aeosi", "rel", "ser")
) |>
add_plan(
analysis = "ae_listing", population = "apat",
observation = c("wk12", "wk24"), parameter = c("any", "rel", "ser")
) |>
add_plan(
analysis = "ae_exp_adj", population = "apat",
observation = c("wk12", "wk24"), parameter = "any;rel;ser"
)
# Create meta_adam ----
meta_adam <- meta_adam(
population = adsl,
observation = adae
) |>
define_plan(plan = plan) |>
define_population(
name = "apat",
group = "TRTA",
subset = quote(SAFFL == "Y")
) |>
define_observation(
name = "wk12",
group = "TRTA",
subset = quote(SAFFL == "Y"),
label = "Weeks 0 to 12"
) |>
define_observation(
name = "wk24",
group = "TRTA",
subset = quote(AOCC01FL == "Y"), # Just for demo, another flag should be used
label = "Weeks 0 to 24"
) |>
define_parameter(
name = "rel",
subset = quote(AEREL %in% c("POSSIBLE", "PROBABLE"))
) |>
define_parameter(
name = "aeosi",
subset = quote(AEOSI == "Y"),
var = "AEDECOD",
soc = "AEBODSYS",
term1 = "",
term2 = "of special interest",
label = "adverse events of special interest"
) |>
define_analysis(
name = "ae_summary",
title = "Summary of Adverse Events"
) |>
define_analysis(
name = "ae_listing",
var_name = c(
"USUBJID", "ASTDY", "AEDECOD", "duration",
"AESEV", "AESER", "related", "action_taken", "outcome"
),
subline_by = NULL,
group_by = c("USUBJID", "ASTDY"),
page_by = c("TRTA", "subline")
) |>
define_analysis(
name = "ae_exp_adj",
label = "Exposure Adjusted Incident Rate",
title = "Exposure-Adjusted Adverse Event Summary"
) |>
meta_build()
meta_adam
}