---
title: EUDRAT01
subtitle: Non-Serious Adverse Events Reported in $\geq$ 5% of Patients in Any Treatment Group -- Patients and Events
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
adsl <- random.cdisc.data::cadsl
adae <- random.cdisc.data::cadae
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adae <- df_explicit_na(adae)
adae_nonser <- adae %>% filter(AESER != "Y", SAFFL == "Y")
get_adae_trimmed <- function(adsl, adae, cutoff_rate) {
n_per_arm <- adsl %>%
dplyr::count(ARM)
anl_terms <- adae %>%
dplyr::group_by(ARM, AEBODSYS, AEDECOD) %>%
dplyr::count(
unique_terms = n_distinct(USUBJID)
) %>%
dplyr::select(-n) %>%
dplyr::ungroup()
anl_terms <- dplyr::left_join(
anl_terms,
n_per_arm,
by = "ARM"
) %>%
dplyr::mutate(
ae_rate = unique_terms / n
) %>%
dplyr::filter(ae_rate >= cutoff_rate) %>%
dplyr::select(AEDECOD) %>%
unique()
anl <- dplyr::left_join(
anl_terms,
adae,
by = "AEDECOD"
)
anl
}
adae_trim <- get_adae_trimmed(adsl, adae_nonser, cutoff_rate = 0.05)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::: panel-tabset
## Standard Table
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
# Define the split function
split_fun <- drop_split_levels
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
summarize_patients_events_in_cols(
custom_label = "Total number of patients with at least one non-serious adverse event occuring at a relative frequency of >=5% and number of events" # nolint: line_length.
) %>%
split_rows_by("AEBODSYS",
nested = FALSE,
split_fun = split_fun,
indent_mod = -1L,
label_pos = "topleft",
split_label = obj_label(adae_trim$AEBODSYS)
) %>%
split_rows_by("AEDECOD", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adae_trim$AEDECOD)) %>%
summarize_patients_events_in_cols(
col_split = FALSE
)
result <- build_table(lyt, adae_trim)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
Define a trimming function `get_adae_trimmed` to filter for AEs of greater than 5% incidence rate.
```{r setup}
#| code-fold: show
```
::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}