---
title: PKCT01
subtitle: Summary Concentration Table
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern)
adsl <- random.cdisc.data::cadsl %>%
filter(ACTARM == "A: Drug X")
adpc <- random.cdisc.data::cadpc %>%
filter(ACTARM == "A: Drug X", PARAM == "Plasma Drug X")
# Setting up the data
adpc_1 <- adpc %>%
mutate(
NFRLT = as.factor(NFRLT),
AVALCAT1 = as.factor(AVALCAT1),
NOMTPT = as.factor(paste(NFRLT, "/", PCTPT))
) %>%
select(NOMTPT, ACTARM, VISIT, AVAL, PARAM, AVALCAT1)
adpc_1$NOMTPT <- factor(
adpc_1$NOMTPT,
levels = levels(adpc_1$NOMTPT)[order(as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", levels(adpc_1$NOMTPT))))]
)
# Row structure
lyt_rows <- basic_table() %>%
split_rows_by(
var = "ACTARM",
split_fun = drop_split_levels,
split_label = "Treatment Group",
label_pos = "topleft"
) %>%
add_rowcounts(alt_counts = TRUE) %>%
split_rows_by(
var = "VISIT",
split_fun = drop_split_levels,
split_label = "Visit",
label_pos = "topleft"
) %>%
split_rows_by(
var = "NOMTPT",
split_fun = drop_split_levels,
split_label = "Nominal Time (hr) / Timepoint",
label_pos = "topleft",
child_labels = "hidden"
)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::::: panel-tabset
## Standard Table (Stats in Columns)
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
lyt <- lyt_rows %>%
analyze_vars_in_cols(
vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)),
.stats = c("n", "n_blq", "mean", "sd", "cv", "geom_mean", "geom_cv", "median", "min", "max"),
.formats = c(
n = "xx.", n_blq = "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)
),
.labels = c(
n = "n", n_blq = "Number\nof\nLTRs/BLQs", mean = "Mean", sd = "SD", cv = "CV (%) Mean",
geom_mean = "Geometric Mean", geom_cv = "CV % Geometric Mean", median = "Median", min = "Minimum", max = "Maximum"
),
na_str = "NE",
.aligns = "decimal"
)
result <- build_table(lyt, df = adpc_1, alt_counts_df = adsl) %>% prune_table()
# Decorating
main_title(result) <- "Summary of PK Concentrations by Nominal Time and Treatment: PK Evaluable"
subtitles(result) <- c(
"Protocol: xxxxx",
paste("Analyte: ", unique(adpc_1$PARAM)),
paste("Treatment:", unique(adpc_1$ACTARM))
)
main_footer(result) <- "NE: Not Estimable"
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table Implementing 1/3 Imputation Rule
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
lyt <- lyt_rows %>%
analyze_vars_in_cols(
vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)),
.stats = c("n", "n_blq", "mean", "sd", "cv", "geom_mean", "geom_cv", "median", "min", "max"),
.formats = c(
n = "xx.", n_blq = "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)
),
.labels = c(
n = "n", n_blq = "Number\nof\nLTRs/BLQs", mean = "Mean", sd = "SD", cv = "CV (%) Mean",
geom_mean = "Geometric Mean", geom_cv = "CV % Geometric Mean", median = "Median", min = "Minimum", max = "Maximum"
),
imp_rule = "1/3",
.aligns = "decimal"
)
result <- build_table(lyt, df = adpc_1, alt_counts_df = adsl) %>% prune_table()
# Decorating
main_title(result) <- "Summary of PK Concentrations by Nominal Time and Treatment: PK Evaluable"
subtitles(result) <- c(
"Protocol: xxxxx",
paste("Analyte: ", unique(adpc_1$PARAM)),
paste("Treatment:", unique(adpc_1$ACTARM))
)
main_footer(result) <- c("NE: Not Estimable", "ND: Not Derived")
result
```
```{r include = FALSE}
webr_code_labels <- c("variant2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table Implementing 1/2 Imputation Rule
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant3, test = list(result_v3 = "result")}
lyt <- lyt_rows %>%
analyze_vars_in_cols(
vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)),
.stats = c("n", "n_blq", "mean", "sd", "cv", "geom_mean", "geom_cv", "median", "min", "max"),
.formats = c(
n = "xx.", n_blq = "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)
),
.labels = c(
n = "n", n_blq = "Number\nof\nLTRs/BLQs", mean = "Mean", sd = "SD", cv = "CV (%) Mean",
geom_mean = "Geometric Mean", geom_cv = "CV % Geometric Mean", median = "Median", min = "Minimum", max = "Maximum"
),
imp_rule = "1/2",
.aligns = "decimal"
)
result <- build_table(lyt, df = adpc_1, alt_counts_df = adsl) %>% prune_table()
# Decorate table
main_title(result) <- "Summary of PK Concentrations by Nominal Time and Treatment: PK Evaluable"
subtitles(result) <- c(
"Protocol: xxxxx",
paste("Analyte: ", unique(adpc_1$PARAM)),
paste("Treatment:", unique(adpc_1$ACTARM))
)
main_footer(result) <- "ND: Not Derived"
result
```
```{r include = FALSE}
webr_code_labels <- c("variant3")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
::::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}