-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-AET02.qmd
96 lines (79 loc) · 2.57 KB
/
03-AET02.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
---
title: "Adverse Events (AET02)"
editor: source
format:
html:
page-layout: full
code-fold: true
code-summary: "Show the code"
---
## Calculaing AET02 statistics using the {cards} package
In this example below we perform different data pre-processing for the different ARDs we want to create.
We then generate separate ARDs for the different sections of the AET02 table and then merge them all together.
```{r}
#| code-summary: "Show the code"
library(cards)
library(chevron)
adsl <- syn_data$adsl
adae <- syn_data$adae |>
dplyr::filter(AEBODSYS == 'cl A.1' | AEBODSYS == "cl D.1")
# Keep only 1 record per patient
adae_one_sub <- adae %>%
dplyr::filter(!duplicated(adae[c("USUBJID")]))
# Keep only 1 record per patient for each AEBODSYS
adae_one_sub_aebod <- adae %>%
dplyr::filter(!duplicated(adae[c("USUBJID", "AEBODSYS")]))
# ----- ARDS -----
# Total number of patients with at least one adverse event
tot_pat_ae <- ard_hierarchical(
data = adae_one_sub,
variables = c(SAFFL),
by = c(ARM),
denominator = adsl,
fmt_fn = ~ list(p = label_cards(digits = 1, scale = 100))) |>
apply_fmt_fn() |>
shuffle_ard(trim = FALSE) |>
dplyr::mutate(tbl_name = 'tot_pat_ae')
# Total number of AEs
tot_ae <- ard_hierarchical(
data = adae,
variables = c(SAFFL),
by = c(ARM),
denominator = adsl) |>
shuffle_ard(trim = FALSE) |>
dplyr::mutate(tbl_name = 'tot_ae')
# Total number of patients with at least one adverse event within each AEBODSYS
tot_pat_ae_aebod <- ard_hierarchical(
data = adae_one_sub_aebod,
variables = c(AEBODSYS),
by = c(ARM),
denominator = adsl,
fmt_fn = ~ list(p = label_cards(digits = 1, scale = 100))) |>
apply_fmt_fn()|>
shuffle_ard(trim = FALSE) |>
dplyr::mutate(tbl_name = 'tot_pat_ae_aebod')
# Total number of AEs for each AEBODSYS
tot_ae_aebod <- ard_hierarchical(
data = adae,
variables = c(AEBODSYS),
by = c(ARM),
denominator = adsl) |>
shuffle_ard(trim = FALSE) |>
dplyr::mutate(tbl_name = 'tot_ae_aebod')
# Count and Percent for each AEDECOD within each AEBODSYS
ae_n_p_aedecod <- ard_hierarchical(
data = adae,
variables = c(AEBODSYS, AEDECOD),
by = c(ARM),
denominator = adsl,
fmt_fn = ~ list(p = label_cards(digits = 2, scale = 100))) |>
apply_fmt_fn()|>
shuffle_ard(trim = FALSE) |>
dplyr::mutate(tbl_name = 'ae_n_p_aedecod ')
# bind the ARDs
final_aet02_ard <- dplyr::bind_rows(tot_pat_ae, tot_ae, tot_pat_ae_aebod, tot_ae_aebod, ae_n_p_aedecod) |>
as.data.frame() |>
dplyr::select(-c(variable, context, warning, error))
final_aet02_ard
rmarkdown::paged_table(final_aet02_ard)
```