---
title: EGT02
subtitle: ECG Abnormalities (EGT02_1 & EGT02_2)
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern)
adsl <- random.cdisc.data::cadsl
adeg <- random.cdisc.data::cadeg
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adeg <- df_explicit_na(adeg)
# Note: We keep only post-baseline for analysis.
adeg_f <- adeg %>%
filter(ONTRTFL == "Y") %>%
filter(PARAM %in% c("Heart Rate", "QT Duration", "RR Duration")) %>%
filter(ANRIND != "<Missing>") %>%
var_relabel(
PARAM = "Assessment",
ANRIND = "Abnormality"
)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::: panel-tabset
## ECG Abnormalities Regardless <br/> of Abnormality at Baseline
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(var = "ACTARM") %>%
split_rows_by(
"PARAM",
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adeg_f$PARAM)
) %>%
count_abnormal("ANRIND", abnormal = list(Low = "LOW", High = "HIGH"), exclude_base_abn = FALSE) %>%
append_varlabels(adeg_f, "ANRIND", indent = 1L)
result <- build_table(lyt = lyt, df = adeg_f, alt_counts_df = adsl)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## ECG Abnormalities Among Subjects <br/> Without Abnormality at Baseline
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(var = "ACTARM") %>%
split_rows_by(
"PARAM",
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adeg_f$PARAM)
) %>%
count_abnormal("ANRIND", abnormal = list(Low = "LOW", High = "HIGH"), exclude_base_abn = TRUE) %>%
append_varlabels(adeg_f, "ANRIND", indent = 1L)
result <- build_table(lyt = lyt, df = adeg_f, alt_counts_df = adsl)
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
```{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
ADEG <- random.cdisc.data::cadeg
})
datanames <- c("ADSL", "ADEG")
names(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
## Reusable Configuration For Modules
ADSL <- data[["ADSL"]]
ADEG <- data[["ADEG"]]
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_abnormality(
label = "Abnormality Table",
dataname = "ADEG",
arm_var = choices_selected(
choices = variable_choices(ADSL, subset = c("ARM", "ARMCD")),
selected = "ARM"
),
by_vars = choices_selected(
choices = variable_choices(ADEG, subset = c("EGCAT", "PARAM", "AVISIT")),
selected = c("PARAM"),
keep_order = TRUE
),
grade = choices_selected(
choices = variable_choices(ADEG, subset = "ANRIND"),
selected = "ANRIND",
fixed = TRUE
),
abnormal = list(Low = "LOW", High = "HIGH"),
exclude_base_abn = FALSE
)
)
)
shinyApp(app$ui, app$server)
```
{{< include ../../_utils/shinylive.qmd >}}
:::
{{< include ../../repro.qmd >}}