---
title: AET10
subtitle: Most Common ($\geq$ 5%) Adverse 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)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::: panel-tabset
## Standard Table
The "All Patients" column is not required in this table but for illustrative purposes we include it to show correct sorting.
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
var = "ARM",
split_fun = add_overall_level("All Patients", first = FALSE)
) %>%
count_occurrences(vars = "AEDECOD")
tbl1 <- build_table(
lyt = lyt,
df = adae,
alt_counts_df = adsl
)
tbl2 <- prune_table(
tt = tbl1,
prune_func = keep_rows(
has_fraction_in_any_col(
atleast = 0.05, # specify threshold
col_names = levels(adsl$ARM)
)
)
)
result <- sort_at_path(
tbl2,
path = c("AEDECOD"),
scorefun = score_occurrences
)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Most Common ($\geq$ 35%) Adverse Events (setting threshold)
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
var = "ARM",
split_fun = add_overall_level("All Patients", first = FALSE)
) %>%
count_occurrences(vars = "AEDECOD")
tbl1 <- build_table(
lyt = lyt,
df = adae,
alt_counts_df = adsl
)
tbl2 <- prune_table(
tt = tbl1,
prune_func = keep_rows(
has_fraction_in_any_col(
atleast = 0.35, # specify threshold
col_names = levels(adsl$ARM)
)
)
)
result <- sort_at_path(
tbl2,
path = c("AEDECOD"),
scorefun = score_occurrences
)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
:::::
{{< include ../../_utils/save_results.qmd >}}
## `teal` App
::: {.panel-tabset .nav-justified}
## {{< fa regular file-lines fa-sm fa-fw >}} Preview
The desired frequency is specified in `prune_freq`. For illustration, frequency is set to $\geq$ 35%.
```{r teal, opts.label = c("skip_if_testing", "app")}
library(teal.modules.clinical)
## Data reproducible code
data <- teal_data()
data <- within(data, {
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)
})
datanames <- c("ADSL", "ADAE")
names(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
## Reusable Configuration For Modules
ADAE <- data[["ADAE"]]
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_events(
label = "Adverse Event Table",
dataname = "ADAE",
arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
llt = choices_selected(
choices = variable_choices(ADAE, c("AETERM", "AEDECOD")),
selected = c("AEDECOD")
),
hlt = choices_selected(
choices = variable_choices(ADAE, c("AEBODSYS", "AESOC")),
selected = NULL
),
add_total = TRUE,
event_type = "adverse event",
prune_freq = 35,
)
)
)
shinyApp(app$ui, app$server)
```
{{< include ../../_utils/shinylive.qmd >}}
:::
{{< include ../../repro.qmd >}}