---
title: PKPG02
subtitle: Pharmacokinetic Parameter Summary of Serum PK Parameters by Treatment
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
library(ggplot2)
library(nestcolor)
# need adex for dose info and adpp for AUC max info
adex <- random.cdisc.data::cadex
adpp <- random.cdisc.data::cadpp
adpp_a <- adpp %>%
filter(
PPSPEC == "Plasma",
AVISITN == "1",
PARAMCD == "AUCIFO"
) %>%
mutate(AUCinf = AVAL)
adex_a <- adex %>%
filter(
AVISITN == "1",
PARAMCD == "DOSE"
) %>%
mutate(Dose = AVAL) %>%
select(USUBJID, Dose)
# join the dose information to the adpp table
adpp_adex <- left_join(adpp_a, adex_a, by = "USUBJID") %>%
group_by(`ARM`) %>%
mutate(count = paste0(`ARM`, " (", n(), ")"))
# set x and y variable names
x_var <- "Dose"
y_var <- "AUCinf"
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::: panel-tabset
## Summary of Pharmacokinetic <br/> Parameters -- Plasma
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r plot1, test = list(plot_v1 = "plot")}
# calculate Summary Statistics (mean and sd) for each group
SummaryStat <- adpp_adex %>% # nolint: object_name.
group_by(Dose = as.factor(Dose)) %>%
summarise(AUCsd = sd(AUCinf), meanAUC = mean(AUCinf))
SummaryStat$Dose <- as.numeric(as.character(SummaryStat$Dose)) # nolint: object_name.
# generate linear model
mod1 <- lm(log(AUCinf) ~ log(Dose), adpp_adex)
# obtain linear model coefficient values
cf <- round(coef(mod1), 2)
# generate linear model equation
eq <- paste0(
"y = ", cf[1],
ifelse(sign(cf[2]) == 1, " + ", " - "), abs(cf[2]), " x , ",
"R²",
" = ",
signif(summary(mod1)$adj.r.squared, 3)
)
plot <- ggplot(adpp_adex, aes(x = .data[[x_var]], y = .data[[y_var]])) +
annotate(geom = "text", x = min(adpp_adex[[x_var]]), y = max(adpp_adex[[y_var]]), label = eq, hjust = 0.1) +
geom_point(size = 1, aes(color = factor(`count`))) +
scale_x_continuous(
name = "Dose (mg/mL)",
breaks = unique(adpp_adex$Dose)
) +
scale_y_continuous(
name = paste(y_var, adpp_a$AVALU),
transform = "log",
breaks = exp(ceiling(seq(
from = min(log(adpp_adex$AUCinf)), to = max(log(adpp_adex$AUCinf)),
by = 1
))),
labels = as.character(ceiling(seq(
from = min(log(adpp_adex$AUCinf)),
to = max(log(adpp_adex$AUCinf)), by = 1
)))
) +
geom_smooth(method = "lm", formula = y ~ x, se = FALSE, color = "black", linewidth = 0.5) +
# Display error bars for each dosing group (this will only appear if the sd is less than the mean)
geom_errorbar(
data = SummaryStat,
aes(x = `Dose`, y = `meanAUC`, ymin = `meanAUC` - `AUCsd`, ymax = `meanAUC` + AUCsd),
width = .05,
position = position_dodge(.1)
) +
geom_point(data = SummaryStat, aes(x = Dose, y = meanAUC, size = 1), shape = 2, show.legend = FALSE) +
ggtitle(paste(
"Dose-Proportionality Plot of Serum", as.character(unique(adex$TRT01P)),
y_var, "in", adpp_a$AVALU
), subtitle = "Summary of serum PK parameters by treatment") +
labs(color = "Treatment Arm") +
theme_nest()
plot
```
```{r include = FALSE}
webr_code_labels <- c("plot1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Summary of Plasma Pharmacokinetic <br/> Parameters with Median Points
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r plot2, test = list(plot_v2 = "plot")}
# calculate median for each group if preferred
SummaryStat <- adpp_adex %>% # nolint: object_name.
group_by(Dose = as.factor(Dose)) %>%
summarise(medAUC = median(AUCinf))
SummaryStat$Dose <- as.numeric(as.character(SummaryStat$Dose)) # nolint: object_name.
plot <- ggplot(adpp_adex, aes(x = .data[[x_var]], y = .data[[y_var]])) +
annotate(geom = "text", x = min(adpp_adex[[x_var]]), y = max(adpp_adex[[y_var]]), label = eq, hjust = 0.1) +
geom_point(size = 1, aes(color = factor(`count`))) +
geom_smooth(method = "lm", formula = y ~ x, se = FALSE, color = "black", linewidth = 0.5) +
geom_point(data = SummaryStat, aes(x = Dose, y = medAUC, size = 1), shape = 2, show.legend = FALSE) +
ggtitle(
paste(
"Dose-Proportionality Plot of Serum",
as.character(unique(adex$TRT01P)),
y_var,
"in",
adpp_a$AVALU
),
subtitle = "Summary of serum PK parameters by treatment"
) +
labs(color = "Treatment Arm") +
scale_y_continuous(
name = paste(y_var, adpp_a$AVALU),
transform = "log",
breaks = exp(ceiling(seq(from = min(log(adpp_adex$AUCinf)), to = max(log(adpp_adex$AUCinf)), by = 1))),
labels = as.character(ceiling(seq(from = min(log(adpp_adex$AUCinf)), to = max(log(adpp_adex$AUCinf)), by = 1)))
) +
scale_x_continuous(
name = "Dose (mg/mL)",
breaks = unique(adpp_adex$Dose)
) +
theme_nest()
plot
```
```{r include = FALSE}
webr_code_labels <- c("plot2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
:::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}