---
title: DTHT01
subtitle: Deaths
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
adsl <- random.cdisc.data::cadsl
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl) %>% filter(SAFFL == "Y")
# Reorder the levels in "DTHCAT" to put Other category at the end.
adsl$DTHCAT <- factor(adsl$DTHCAT, levels = c("ADVERSE EVENT", "PROGRESSIVE DISEASE", "OTHER", "<Missing>"))
```
```{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")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>%
count_values(
"DTHFL",
values = "Y",
.labels = c(count_fraction = "Total number of deaths"),
.formats = c(count_fraction = "xx (xx.x%)")
) %>%
analyze_vars(vars = c("DTHCAT"), var_labels = c("Primary Cause of Death"))
result <- build_table(lyt, df = adsl)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table Selecting <br/> Sections to Display
::: {.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("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>%
count_values(
"DTHFL",
values = "Y",
.labels = c(count_fraction = "Total number of deaths"),
.formats = c(count_fraction = "xx (xx.x%)")
) %>%
analyze_vars(vars = c("DTHCAT"), var_labels = c("Primary Cause of Death")) %>%
split_rows_by("DTHCAT", split_fun = keep_split_levels("OTHER"), child_labels = "hidden") %>%
analyze_vars(
"DTHCAUS",
.stats = "count_fraction",
.indent_mods = c("count_fraction" = 2L),
show_labels = "hidden"
) %>%
analyze_vars(
vars = "LDDTHGR1",
nested = FALSE,
var_labels = "Days from last drug administration",
show_labels = "visible"
) %>%
split_rows_by(
"LDDTHGR1",
split_fun = remove_split_levels("<Missing>"),
split_label = "Primary cause by days from last study drug administration",
label_pos = "visible"
) %>%
analyze_vars("DTHCAT")
result <- build_table(lyt, df = adsl) %>% prune_table()
result
```
```{r include = FALSE}
webr_code_labels <- c("variant2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table for Studies Collecting Death <br/> Information from Public Records
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant3, test = list(result_v3 = "result")}
dthcaus_levels <- levels(adsl[adsl$DTHCAT == "OTHER", ]$DTHCAUS)
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>%
count_values(
"DTHFL",
values = "Y",
.labels = c(count_fraction = "Total number of deaths"),
.formats = c(count_fraction = "xx (xx.x%)")
) %>%
analyze_vars(
vars = c("DTHCAT"),
var_labels = c("Primary Cause of Death"),
table_names = "primary_cause"
) %>%
split_rows_by(
"DTHCAT",
split_fun = keep_split_levels("OTHER"),
child_labels = "hidden"
) %>%
count_values(
"DTHCAUS",
values = dthcaus_levels[5],
.labels = c(count_fraction = "Post-study reportings of death"),
.formats = c(count_fraction = "xx (xx.x%)"),
.indent_mods = c(count_fraction = 2L),
table_names = "post_study_deaths"
) %>%
count_values(
"DTHCAUS",
values = dthcaus_levels[-5],
.labels = c(count_fraction = "All other causes"),
.formats = c(count_fraction = "xx (xx.x%)"),
.indent_mods = c(count_fraction = 2L),
table_names = "all_other_causes"
)
result <- build_table(lyt, df = adsl)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant3")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table Adding Details for "All other causes" <br/> Category for Studies Collecting Death <br/> Information from Public Records
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant4, test = list(result_v4 = "result")}
dthcaus_levels <- levels(adsl[adsl$DTHCAT == "OTHER", ]$DTHCAUS)
# create a helper variable DTHCAUS_other
adsl <- adsl %>%
mutate(
DTHCAUS_other = factor(ifelse(
DTHCAT == "OTHER" & DTHCAUS != "Post-study reporting of death", as.character(DTHCAUS), NA
), levels = c("LOST TO FOLLOW UP", "SUICIDE", "UNKNOWN", "MISSING")) %>% explicit_na()
)
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>%
count_values(
"DTHFL",
values = "Y",
.labels = c(count_fraction = "Total number of deaths"),
.formats = c(count_fraction = "xx (xx.x%)")
) %>%
analyze_vars(
vars = c("DTHCAT"),
var_labels = c("Primary Cause of Death"),
table_names = "primary_cause"
) %>%
split_rows_by("DTHCAT", split_fun = keep_split_levels("OTHER"), child_labels = "hidden") %>%
count_values(
"DTHCAUS",
values = dthcaus_levels[5],
.labels = c(count_fraction = "Post-study reportings of death"),
.formats = c(count_fraction = "xx (xx.x%)"),
.indent_mods = c(count_fraction = 2L),
table_names = "post_study_deaths"
) %>%
count_values(
"DTHCAUS",
values = dthcaus_levels[-5],
.labels = c(count_fraction = "All other causes"),
.formats = c(count_fraction = "xx (xx.x%)"),
.indent_mods = c(count_fraction = 2L),
table_names = "all_other_causes"
) %>%
analyze_vars(
"DTHCAUS_other",
.stats = "count_fraction",
.indent_mods = c("count_fraction" = 3L),
show_labels = "hidden"
)
result <- build_table(lyt, df = adsl)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant4")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
:::::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}