---
title: EGT04
subtitle: Shift Table of Qualitative ECG Assessments
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
set.seed(123)
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, omit_columns = c("AVALC", "BASEC"))
adeg_labels <- var_labels(adeg)
adeg_f <- subset(
adeg,
PARAMCD == "ECGINTP" & # Analysis in terms of "NORMAL"/"ABNORMAL" (AVALC)
SAFFL == "Y" & # "Safety Population Flag"
ONTRTFL == "Y" & # "On Treatment Record Flag"
WORS02FL == "Y" # "Worst Post-Baseline Observation"
)
adeg_f$AVALC[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing"
adeg_f$BASEC[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing"
adeg_f$AVALC <- factor(
adeg_f$AVALC,
levels = c("NORMAL", "ABNORMAL", "Missing"),
labels = c("Normal", "Abnormal", "Missing")
)
adeg_f$BASEC <- factor(
adeg_f$BASEC,
levels = c("NORMAL", "ABNORMAL", "Missing"),
labels = c("Normal", "Abnormal", "Missing")
)
var_labels(adeg_f) <- adeg_labels
adeg_f <- adeg_f %>%
var_relabel(BASEC = "Baseline")
# Temprary solution for over arching column
adeg_f <- adeg_f %>% mutate(postbaseline_label = "Post-Baseline")
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::: panel-tabset
## Standard Table
The EGT04 template consists of a stacked list of contingency tables, one per group. For each group, the n's across all cells must add up to the group N in the analysis, and percentages are calculated using N as the denominator.
::: {.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("postbaseline_label") %>%
split_cols_by("AVALC") %>%
split_rows_by("ARM", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adeg_f$ARM)) %>%
add_rowcounts() %>%
analyze_vars(
"BASEC",
denom = "N_row",
.stats = "count_fraction",
na.rm = FALSE
) %>%
append_varlabels(adeg_f, c("BASEC"), indent = 1L)
result <- build_table(lyt, adeg_f)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
For the EGT04 template, data imputation should be avoided, and missing data explicit and accounted for, so the contingency table sum adds up to the group N. For illustration purposes, missing data are added to the example dataset.
```{r setup}
#| code-fold: show
```
::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}