-
Notifications
You must be signed in to change notification settings - Fork 33
/
tlf-ae-summary.qmd
188 lines (155 loc) · 4.58 KB
/
tlf-ae-summary.qmd
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
# AE summary {#sec-aesummary}
```{r, include=FALSE}
source("_common.R")
```
Following [ICH E3 guidance](https://database.ich.org/sites/default/files/E3_Guideline.pdf),
we summarize number of participants that were included in each safety analysis in Section 12.2, Adverse Events (AEs).
```{r}
library(haven) # Read SAS data
library(dplyr) # Manipulate data
library(tidyr) # Manipulate data
library(r2rtf) # Reporting in RTF format
```
In this chapter, we illustrate how to summarize AEs information for a study.
```{r, out.width = "100%", out.height = if (knitr::is_html_output()) "400px", echo = FALSE, fig.align = "center"}
knitr::include_graphics("tlf/tlf_ae_summary.pdf")
```
The data used to summarize AE information is in `adsl` and `adae` datasets.
```{r}
adsl <- read_sas("data-adam/adsl.sas7bdat")
adae <- read_sas("data-adam/adae.sas7bdat")
```
We first summarize participants in population by treatment arm.
```{r}
pop <- adsl %>%
filter(SAFFL == "Y") %>%
rename(TRTAN = TRT01AN) %>%
count(TRTAN, name = "tot")
pop
```
We transform the data to simplify the analysis of each required AE criteria of interest.
- With one or more adverse events
- With drug-related adverse events
- With serious adverse events
- With serious drug-related adverse events
- Who died
```{r}
tidy_ae <- adae %>%
mutate(
all = SAFFL == "Y",
drug = AEREL %in% c("POSSIBLE", "PROBABLE"),
ser = AESER == "Y",
drug_ser = drug & ser,
die = AEOUT == "FATAL"
) %>%
select(USUBJID, TRTAN, all, drug, ser, drug_ser, die) %>%
pivot_longer(cols = c(all, drug, ser, drug_ser, die))
tidy_ae
```
We summarize the number and percentage of participants who meet each AE criteria.
```{r}
fmt_num <- function(x, digits, width = digits + 4) {
formatC(
x,
digits = digits,
format = "f",
width = width
)
}
```
```{r}
ana <- tidy_ae %>%
filter(value == TRUE) %>%
group_by(TRTAN, name) %>%
summarise(n = n_distinct(USUBJID)) %>%
left_join(pop, by = "TRTAN") %>%
mutate(
pct = fmt_num(n / tot * 100, digits = 1),
n = fmt_num(n, digits = 0),
pct = paste0("(", pct, ")")
)
ana
```
We prepare reporting-ready dataset for each AE group.
```{r}
t_ae <- ana %>%
pivot_wider(
id_cols = "name",
names_from = TRTAN,
values_from = c(n, pct),
values_fill = list(
n = " 0",
pct = "( 0.0)"
)
)
t_ae <- t_ae %>%
mutate(name = factor(
name,
c("all", "drug", "ser", "drug_ser", "die"),
c(
"With one or more adverse events",
"With drug-related adverse events",
"With serious adverse events",
"With serious drug-related adverse events",
"Who died"
)
)) %>%
arrange(name)
```
We prepare reporting-ready dataset for the analysis population.
```{r}
t_pop <- pop %>%
mutate(
name = "Participants in population",
tot = fmt_num(tot, digits = 0)
) %>%
pivot_wider(
id_cols = name,
names_from = TRTAN,
names_prefix = "n_",
values_from = tot
)
t_pop
```
The final report data is saved in `tbl_ae_summary`.
```{r}
tbl_ae_summary <- bind_rows(t_pop, t_ae) %>%
select(name, ends_with("_0"), ends_with("_54"), ends_with("_81"))
tbl_ae_summary
```
We define the format of the output using code below:
```{r}
tbl_ae_summary %>%
rtf_title(
"Analysis of Adverse Event Summary",
"(Safety Analysis Population)"
) %>%
rtf_colheader(" | Placebo | Xanomeline Low Dose| Xanomeline High Dose",
col_rel_width = c(3.5, rep(2, 3))
) %>%
rtf_colheader(" | n | (%) | n | (%) | n | (%)",
col_rel_width = c(3.5, rep(c(0.7, 1.3), 3)),
border_top = c("", rep("single", 6)),
border_left = c("single", rep(c("single", ""), 3))
) %>%
rtf_body(
col_rel_width = c(3.5, rep(c(0.7, 1.3), 3)),
text_justification = c("l", rep("c", 6)),
border_left = c("single", rep(c("single", ""), 3))
) %>%
rtf_footnote("Every subject is counted a single time for each applicable row and column.") %>%
rtf_encode() %>%
write_rtf("tlf/tlf_ae_summary.rtf")
```
```{r, include=FALSE}
rtf2pdf("tlf/tlf_ae_summary.rtf")
```
```{r, out.width = "100%", out.height = if (knitr::is_html_output()) "400px", echo = FALSE, fig.align = "center"}
knitr::include_graphics("tlf/tlf_ae_summary.pdf")
```
The procedure to generate an AE summary table can be summarized as follows:
- Step 1: Read data (i.e., `adae` and `adsl`) into R.
- Step 2: Summarize participants in population by treatment arm, and name the dataset as `t_pop`.
- Step 3: Summarize participants in population by required AE criteria of interest,
and name the dataset as `t_ae`.
- Step 4: Row-wise combine `t_pop` and `t_ae` and format it by using r2rtf.