---
title: LBT10
subtitle: Liver Laboratory Tests -- Patients with Elevated Post-Baseline AST or ALT Levels at Two Consecutive Visits (with Respect to ULN)
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern)
adsl <- random.cdisc.data::cadsl
adhy <- random.cdisc.data::cadhy
adhy_liver <- adhy %>%
filter(PARAMCD %in% c(
"BL2AL2CU", "BL2AS2CU", "BG2AL2CU", "BG2AS2CU", "B2A2L2CU", "B2A2S2CU", "B2A5L2CU", "B2A5S2CU"
)) %>%
mutate(PARAMCAT = case_when(
PARAMCD %in% c("BL2AL2CU", "BL2AS2CU") ~ "Total Bilirubin <= 2xULN",
PARAMCD %in% c("BG2AL2CU", "BG2AS2CU") ~ "Total Bilirubin > 2xULN",
PARAMCD %in% c("B2A2L2CU", "B2A2S2CU") ~ "Total Bilirubin > 2xULN and Alkaline Phosphatase <= 2xULN",
PARAMCD %in% c("B2A5L2CU", "B2A5S2CU") ~ "Total Bilirubin > 2xULN and Alkaline Phosphatase <= 5xULN"
)) %>%
mutate(AVALC_FORMAT = case_when(
PARAMCD %in% c("BL2AL2CU", "BG2AL2CU", "B2A2L2CU", "B2A5L2CU") & AVALC == "Y" ~ "ALT >3xULN at 2 Visits",
PARAMCD %in% c("BL2AS2CU", "BG2AS2CU", "B2A2S2CU", "B2A5S2CU") & AVALC == "Y" ~ "AST >3xULN at 2 Visits",
TRUE ~ "Criteria not met"
))
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
anl <- df_explicit_na(adhy_liver)
```
```{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")}
tbl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARMCD") %>%
split_rows_by("PARAMCAT") %>%
split_rows_by("PARAM", split_fun = drop_split_levels, child_labels = "hidden") %>%
count_occurrences(
vars = "AVALC_FORMAT",
.stats = c("fraction"),
denom = "n",
drop = TRUE
) %>%
build_table(anl, alt_counts_df = adsl)
criteria_fun <- function(tr) {
row_label <- obj_label(tr)
ifelse(row_label == "Criteria not met", TRUE, FALSE)
}
result <- tbl %>% trim_rows(criteria = criteria_fun)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table Selecting Sections
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
tbl2 <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARMCD") %>%
split_rows_by("PARAMCAT", split_fun = remove_split_levels("Total Bilirubin > 2xULN")) %>%
split_rows_by("PARAM", split_fun = drop_split_levels, child_labels = "hidden") %>%
count_occurrences(
vars = "AVALC_FORMAT",
.stats = c("fraction"),
denom = "n",
drop = TRUE
) %>%
build_table(anl, alt_counts_df = adsl)
criteria_fun <- function(tr) {
row_label <- obj_label(tr)
ifelse(row_label == "Criteria not met", TRUE, FALSE)
}
result <- tbl2 %>% trim_rows(criteria = criteria_fun)
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 >}}
{{< include ../../repro.qmd >}}