---
title: PKPT03
subtitle: Pharmacokinetic Parameter Summary of Plasma by Treatment (Stats in Columns)
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern)
# Preprocess analysis data ----
adpp <- random.cdisc.data::cadpp
adpp <- adpp %>%
filter(PPSPEC == "Plasma") %>%
filter(AVISIT %in% c("CYCLE 1 DAY 1", "CYCLE 1 DAY 2")) %>%
h_pkparam_sort() %>%
mutate(PARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>%
mutate(PARAM = reorder(PARAM, TLG_ORDER))
# Preprocess subject-level data ----
adsl <- random.cdisc.data::cadsl
# Workaround needed to include (N=xx) population counts
# Repeat ADSL by the number of levels in AVISIT
# Include AVISIT and dummy PARAM as it's needed for trim_levels_in_group
adsl_tmp <- adsl %>%
select(STUDYID, USUBJID, ARMCD) %>%
unique() %>%
mutate(PARAM = factor(NA_character_, levels = levels(adpp$PARAM)))
# Data for Plasma Drug X example ----
adpp_x <- adpp %>%
filter(PPCAT == "Plasma Drug X") %>%
# Please do not replicate mutate statement below!
# It is used to make the random data in this example more realistic
# as not all parameters are always available across all visits.
mutate(
AVAL = if_else(
ARMCD == "ARM A" & AVISIT == "CYCLE 1 DAY 1" & PARAM == "Cmax (ug/mL)",
NA_real_, AVAL
)
)
adpp_x_tmp <- adpp_x %>%
select(STUDYID, USUBJID, ARMCD, AVISIT) %>%
unique()
adsl_x_splitvars <- adsl_tmp %>%
left_join(adpp_x_tmp, by = c("STUDYID", "USUBJID", "ARMCD")) %>%
filter(!is.na(AVISIT))
# Data for Plasma Drug Y example ----
adpp_y <- adpp %>%
filter(PPCAT == "Plasma Drug Y")
adpp_y_tmp <- adpp_y %>%
select(STUDYID, USUBJID, ARMCD, AVISIT) %>%
unique()
adsl_y_splitvars <- adsl_tmp %>%
left_join(adpp_y_tmp, by = c("STUDYID", "USUBJID", "ARMCD")) %>%
filter(!is.na(AVISIT))
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::::: panel-tabset
## Standard Table
```{r lyt}
# lyt creation
lyt <- basic_table() %>%
split_rows_by(
var = "AVISIT",
split_fun = drop_split_levels,
split_label = "Visit",
page_by = TRUE
) %>%
split_rows_by(
var = "ARMCD",
split_fun = trim_levels_in_group("PARAM"),
label_pos = "topleft",
split_label = "Treatment Arm"
) %>%
add_rowcounts(alt_counts = TRUE) %>%
split_rows_by(
var = "PARAM",
label_pos = "topleft",
split_label = "PK Parameter",
child_labels = "hidden"
) %>%
analyze_vars_in_cols(
vars = "AVAL",
.stats = c(
"n", "mean", "sd", "cv",
"geom_mean", "geom_cv", "median",
"min", "max"
),
.labels = c(
n = "n",
mean = "Mean",
sd = "SD",
cv = "CV (%)",
geom_mean = "Geometric Mean",
geom_cv = "CV % Geometric Mean",
median = "Median",
min = "Minimum",
max = "Maximum"
),
.formats = c(
n = "xx.",
mean = format_sigfig(3),
sd = format_sigfig(3),
cv = "xx.x",
median = format_sigfig(3),
geom_mean = format_sigfig(3),
geom_cv = "xx.x",
min = format_sigfig(3),
max = format_sigfig(3)
),
na_str = "NE"
)
```
#### Plasma Drug X
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
result <- build_table(lyt, df = adpp_x, alt_counts_df = adsl_x_splitvars)
main_title(result) <- paste("Summary of", unique(adpp_x$PPSPEC), "PK Parameter by Treatment Arm, PK Population")
subtitles(result) <- paste("Analyte:", unique(adpp_x$PPCAT))
result <- paginate_table(result, landscape = TRUE)
result
```
```{r include = FALSE}
webr_code_labels <- c("lyt", "variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
#### Plasma Drug X: Remove Rows with 0s
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
result <- build_table(lyt, df = adpp_x, alt_counts_df = adsl_x_splitvars) %>%
prune_table()
main_title(result) <- paste("Summary of", unique(adpp_x$PPSPEC), "PK Parameter by Treatment Arm, PK Population")
subtitles(result) <- paste("Analyte:", unique(adpp_x$PPCAT))
result <- paginate_table(result, landscape = TRUE)
result
```
```{r include = FALSE}
webr_code_labels <- c("lyt", "variant2")
```
{{< include ../../_utils/webr.qmd >}}
:::
#### Plasma Drug Y
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant3, test = list(result_v3 = "result")}
result <- build_table(lyt, df = adpp_y, alt_counts_df = adsl_y_splitvars)
main_title(result) <- paste("Summary of", unique(adpp_y$PPSPEC), "PK Parameter by Treatment Arm, PK Population")
subtitles(result) <- paste("Analyte:", unique(adpp_y$PPCAT))
result <- paginate_table(result, landscape = TRUE)
result
```
```{r include = FALSE}
webr_code_labels <- c("lyt", "variant3")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
::::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}