diff --git a/book/tables/ADA/adat03.qmd b/book/tables/ADA/adat03.qmd index 772c35d7ff..0f17fdbb53 100644 --- a/book/tables/ADA/adat03.qmd +++ b/book/tables/ADA/adat03.qmd @@ -39,6 +39,85 @@ anl <- merge(anl, adpc, by = c("USUBJID", "NFRLT")) %>% mutate(AVAL_LT = ifelse(AVAL <= max_conc, TRUE, FALSE)) ``` +## Standard Table (μg/mL) + +```{r variant1, test = list(result_v1 = "result")} +# parameters in columns +adat03_stats <- c("n", "mean", "sd", "median", "min", "max", "cv", "geom_mean", "count_fraction") +adat03_lbls <- c( + n = "Total Number\nof Measurable\n Samples", + mean = "Mean", + sd = "SD", + median = "Median", + min = "Minimum", + max = "Maximum", + cv = "CV (%)", + geom_mean = "Geometric Mean", + count_fraction = paste0("Samples with\nConcentration\n≤ ", max_conc, "μg/mL") +) +adat03_fmts <- c( + n = "xx.", + mean = format_sigfig(3), + sd = format_sigfig(3), + median = format_sigfig(3), + min = format_sigfig(3), + max = format_sigfig(3), + cv = "xx.x", + geom_mean = format_sigfig(3), + count_fraction = format_count_fraction +) + +afun_list <- lapply( + 1:9, + function(i) make_afun(s_summary, .stats = adat03_stats[i], .formats = adat03_fmts[i], .labels = "Overall") +) + +# lyt creation +lyt <- basic_table() %>% + split_rows_by( + var = "ARM", + label_pos = "topleft", + split_label = "Treatment Group", + split_fun = drop_split_levels, + section_div = "" + ) %>% + add_rowcounts() %>% + split_rows_by( + var = "VISIT", + label_pos = "topleft", + split_label = "Visit", + split_fun = drop_split_levels, + child_labels = "hidden" + ) %>% + analyze_vars_in_cols( + vars = c(rep("AVAL", 8), "AVAL_LT"), + .stats = adat03_stats, + .labels = adat03_lbls, + .formats = adat03_fmts + ) %>% + analyze_colvars( + afun_list, + nested = FALSE, + extra_args = list(".labels" = "Overall") + ) + +result <- build_table(lyt, anl, alt_counts_df = adsl) + +main_title(result) <- paste( + "Summary of Serum Concentrations (μg/mL) at Timepoints Where ADA Samples Were Collected and Analyzed\n + Protocol:", unique(adab$PARCAT1)[1] +) +subtitles(result) <- paste("Analyte:", unique(adab$PARAMCD)[1]) +fnotes_at_path(result, rowpath = NULL, colpath = c("multivars", "AVAL")) <- "Refers to the total no. of measurable ADA samples that have a corresponding measurable drug concentration sample (i.e. results with +valid numeric values and LTRs). LTR results on post-dose samples are replaced by aaa µg/mL i.e. half of MQC value." +fnotes_at_path(result, rowpath = NULL, colpath = c("multivars", "AVAL_LT")) <- "In validation, the assay was able to detect yyy ng/mL of surrogate ADA in the presence of zzz µg/mL of [drug]. BLQ = Below Limit of +Quantitation, LTR = Lower than Reportable, MQC = Minimum Quantifiable Concentration, ADA = Anti-Drug Antibodies (is also referred to as ATA, +or Anti-Therapeutic Antibodies). RXXXXXXX is also known as [drug]" + +result +``` + +{{< include ../../test-utils/save_results.qmd >}} ## `teal` App diff --git a/book/tables/pharmacokinetic/pkct01.qmd b/book/tables/pharmacokinetic/pkct01.qmd index 74eaffeb1e..9e9cc4aff6 100644 --- a/book/tables/pharmacokinetic/pkct01.qmd +++ b/book/tables/pharmacokinetic/pkct01.qmd @@ -10,6 +10,140 @@ subtitle: Summary Concentration Table ::: panel-tabset ## Data Setup +```{r setup, message=FALSE} +#| code-fold: show + +library(scda) +library(dplyr) +library(tern) + +adsl <- synthetic_cdisc_dataset("latest", "adsl") %>% + filter(ACTARM == "A: Drug X") +adpc <- synthetic_cdisc_dataset("latest", "adpc") %>% + 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) + ) %>% + select(NFRLT, ACTARM, VISIT, AVAL, PARAM, AVALCAT1) %>% + var_relabel(NFRLT = "Nominal Time from First Dose (hr)") + +# 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 = "NFRLT", + split_fun = drop_split_levels, + split_label = obj_label(adpc_1$NFRLT), + label_pos = "topleft", + child_labels = "hidden" + ) +``` + +## Standard Table (Stats in Columns) + +```{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_level = "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 +``` + +## Table Implementing 1/3 Imputation Rule + +```{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 +``` + +## Table Implementing 1/2 Imputation Rule + +```{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 +``` + +{{< include ../../test-utils/save_results.qmd >}} + ## `teal` App ```{r teal, message=FALSE, opts.label='skip_if_testing'} diff --git a/book/tables/pharmacokinetic/pkpt02.qmd b/book/tables/pharmacokinetic/pkpt02.qmd index 9972fb18d3..7808121289 100644 --- a/book/tables/pharmacokinetic/pkpt02.qmd +++ b/book/tables/pharmacokinetic/pkpt02.qmd @@ -23,6 +23,66 @@ adpp <- adpp %>% filter(PPSPEC == "Plasma", AVISIT == "CYCLE 1 DAY 1") ## Standard Table -- Plasma +```{r} +# lyt creation +lyt <- basic_table() %>% + split_cols_by( + var = "ARMCD", + split_fun = trim_levels_in_group("ARMCD"), + # label_pos = "topleft", + split_label = "Treatment Arm" + ) %>% + split_rows_by( + var = "PKPARAM", + label_pos = "topleft", + split_label = "PK Parameter" + ) %>% + tern::analyze_vars( + vars = "AVAL", + .stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"), + .formats = c( + n = "xx.", + mean_sd = format_sigfig(3, "xx (xx)"), + cv = "xx.x", + geom_mean = format_sigfig(3), + geom_cv = "xx.x", + median = format_sigfig(3), + range = format_sigfig(3, "xx - xx") + ) + ) +``` + +#### Plasma Drug X + +```{r variant1, test = list(result_v1 = "result")} +adpp0 <- adpp %>% + filter(PPCAT == "Plasma Drug X") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp0) +main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) +result +``` + +#### Plasma Drug Y + +```{r variant2, test = list(result_v2 = "result")} +adpp1 <- adpp %>% + filter(PPCAT == "Plasma Drug Y") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp1) +main_title(result) <- paste("Summary of", unique(adpp1$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp1$PPCAT), "\nVisit:", unique(adpp1$AVISIT)) +result +``` + +{{< include ../../test-utils/save_results.qmd >}} ## `teal` App diff --git a/book/tables/pharmacokinetic/pkpt03.qmd b/book/tables/pharmacokinetic/pkpt03.qmd index 30b4eac10f..0cd72f7010 100644 --- a/book/tables/pharmacokinetic/pkpt03.qmd +++ b/book/tables/pharmacokinetic/pkpt03.qmd @@ -10,6 +10,155 @@ subtitle: Pharmacokinetic Parameter Summary of Plasma by Treatment (Stats in Col ::: panel-tabset ## Data Setup +```{r setup, message=FALSE} +#| code-fold: show + +library(scda) +library(dplyr) +library(tern) + +# Preprocess analysis data ---- +adpp <- synthetic_cdisc_dataset("latest", "adpp") +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 <- synthetic_cdisc_dataset("latest", "adsl") + +# 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)) +``` + +## Standard Table + +```{r} +# 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_level = "NE" + ) +``` + +#### Plasma Drug X + +```{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 +``` + +#### Plasma Drug X: Remove Rows with 0s + +```{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 +``` + +#### Plasma Drug Y + +```{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 +``` {{< include ../../test-utils/save_results.qmd >}} diff --git a/book/tables/pharmacokinetic/pkpt04.qmd b/book/tables/pharmacokinetic/pkpt04.qmd index 9b59e20582..027ef61f8b 100644 --- a/book/tables/pharmacokinetic/pkpt04.qmd +++ b/book/tables/pharmacokinetic/pkpt04.qmd @@ -23,6 +23,67 @@ adpp <- adpp %>% filter(PPSPEC == "Urine", AVISIT == "CYCLE 1 DAY 1") ## Standard Table +```{r} +# lyt creation +lyt <- basic_table() %>% + split_cols_by( + var = "ARMCD", + split_fun = trim_levels_in_group("ARMCD"), + # label_pos = "topleft", + split_label = "Treatment Arm" + ) %>% + split_rows_by( + var = "PKPARAM", + label_pos = "topleft", + split_label = "PK Parameter" + ) %>% + tern::analyze_vars( + vars = "AVAL", + .stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"), + .formats = c( + n = "xx.", + mean_sd = format_sigfig(3, "xx (xx)"), + cv = "xx.x", + geom_mean = format_sigfig(3), + geom_cv = "xx.x", + median = format_sigfig(3), + range = format_sigfig(3, "xx - xx") + ) + ) +``` + +#### Plasma Drug X + +```{r variant1, test = list(result_v1 = "result")} +adpp0 <- adpp %>% + filter(PPCAT == "Plasma Drug X") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp0) +main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) +result +``` + +#### Plasma Drug Y + +```{r variant2, test = list(result_v2 = "result")} +adpp1 <- adpp %>% + filter(PPCAT == "Plasma Drug Y") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp1) +main_title(result) <- paste("Summary of", unique(adpp1$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp1$PPCAT), "\nVisit:", unique(adpp1$AVISIT)) +result +``` + +{{< include ../../test-utils/save_results.qmd >}} + ## `teal` App ```{r teal, message=FALSE, opts.label='skip_if_testing'} diff --git a/book/tables/pharmacokinetic/pkpt05.qmd b/book/tables/pharmacokinetic/pkpt05.qmd index 5380e242e8..e82735216c 100644 --- a/book/tables/pharmacokinetic/pkpt05.qmd +++ b/book/tables/pharmacokinetic/pkpt05.qmd @@ -23,6 +23,84 @@ adpp <- adpp %>% filter(PPSPEC == "Urine", AVISIT == "CYCLE 1 DAY 1") ## Standard Table +```{r} +# lyt creation +lyt <- basic_table() %>% + split_rows_by( + var = "ARMCD", + split_fun = trim_levels_in_group("ARMCD"), + label_pos = "topleft", + split_label = "Treatment Arm" + ) %>% + split_rows_by( + var = "PKPARAM", + 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) + ) + ) +``` + +#### Plasma Drug X + +```{r variant1, test = list(result_v1 = "result")} +adpp0 <- adpp %>% + filter(PPCAT == "Plasma Drug X") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp0) +main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) +result +``` + +#### Plasma Drug Y + +```{r variant2, test = list(result_v2 = "result")} +adpp1 <- adpp %>% + filter(PPCAT == "Plasma Drug Y") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp1) +main_title(result) <- paste("Summary of", unique(adpp1$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp1$PPCAT), "\nVisit:", unique(adpp1$AVISIT)) +result +``` + +{{< include ../../test-utils/save_results.qmd >}} ## `teal` App diff --git a/book/tables/pharmacokinetic/pkpt06.qmd b/book/tables/pharmacokinetic/pkpt06.qmd index 8a567ab0ff..4d474b7c85 100644 --- a/book/tables/pharmacokinetic/pkpt06.qmd +++ b/book/tables/pharmacokinetic/pkpt06.qmd @@ -24,6 +24,66 @@ adpp <- adpp %>% filter(AVISIT == "CYCLE 1 DAY 1", str_detect(tolower(PARAM), re ## Standard Table +```{r} +# lyt creation +lyt <- basic_table() %>% + split_cols_by( + var = "ARMCD", + split_fun = trim_levels_in_group("ARMCD"), + # label_pos = "topleft", + split_label = "Treatment Arm" + ) %>% + split_rows_by( + var = "PKPARAM", + label_pos = "topleft", + split_label = "PK Parameter" + ) %>% + tern::analyze_vars( + vars = "AVAL", + .stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"), + .formats = c( + n = "xx.", + mean_sd = format_sigfig(3, "xx (xx)"), + cv = "xx.x", + geom_mean = format_sigfig(3), + geom_cv = "xx.x", + median = format_sigfig(3), + range = format_sigfig(3, "xx - xx") + ) + ) +``` + +#### Plasma Drug X + +```{r variant1, test = list(result_v1 = "result")} +adpp0 <- adpp %>% + filter(PPCAT == "Plasma Drug X") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp0) +main_title(result) <- paste("Summary of Dose-Normalized PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) +result +``` + +#### Plasma Drug Y + +```{r variant2, test = list(result_v2 = "result")} +adpp1 <- adpp %>% + filter(PPCAT == "Plasma Drug Y") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp1) +main_title(result) <- paste("Summary of Dose-Normalized PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp1$PPCAT), "\nVisit:", unique(adpp1$AVISIT)) +result +``` + +{{< include ../../test-utils/save_results.qmd >}} ## `teal` App diff --git a/book/tables/pharmacokinetic/pkpt07.qmd b/book/tables/pharmacokinetic/pkpt07.qmd index 18ace14814..7c6dbb0e1d 100644 --- a/book/tables/pharmacokinetic/pkpt07.qmd +++ b/book/tables/pharmacokinetic/pkpt07.qmd @@ -22,6 +22,87 @@ adpp <- synthetic_cdisc_dataset("latest", "adpp") adpp <- adpp %>% filter(AVISIT == "CYCLE 1 DAY 1", str_detect(tolower(PARAM), regex("norm by dose", ignore_case = TRUE))) ``` +## Standard Table -- Urine + +```{r} +# lyt creation +lyt <- basic_table() %>% + split_rows_by( + var = "ARMCD", + split_fun = trim_levels_in_group("ARMCD"), + label_pos = "topleft", + split_label = "Treatment Arm" + ) %>% + split_rows_by( + var = "PKPARAM", + 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) + ) + ) +``` + +#### Plasma Drug X + +```{r variant1, test = list(result_v1 = "result")} +adpp0 <- adpp %>% + filter(PPCAT == "Plasma Drug X") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp0) +main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) +result +``` + +#### Plasma Drug Y + +```{r variant2, test = list(result_v2 = "result")} +adpp1 <- adpp %>% + filter(PPCAT == "Plasma Drug Y") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + mutate(PKPARAM = reorder(PKPARAM, TLG_ORDER)) + +result <- build_table(lyt, df = adpp1) +main_title(result) <- paste("Summary of", unique(adpp1$PPSPEC), "PK Parameter by Treatment Arm, PK Population") +subtitles(result) <- paste("Analyte:", unique(adpp1$PPCAT), "\nVisit:", unique(adpp1$AVISIT)) +result +``` + +{{< include ../../test-utils/save_results.qmd >}} + ## `teal` App ```{r teal, message=FALSE, opts.label='skip_if_testing'} diff --git a/book/tables/pharmacokinetic/pkpt08.qmd b/book/tables/pharmacokinetic/pkpt08.qmd index d22af7264d..f10afc1e44 100644 --- a/book/tables/pharmacokinetic/pkpt08.qmd +++ b/book/tables/pharmacokinetic/pkpt08.qmd @@ -26,7 +26,66 @@ adpp <- adpp %>% ## Standard Table -- Plasma +```{r variant1, test = list(result_v1 = "result")} +# create layout +lyt <- basic_table() %>% + add_overall_col("Accumulation Interval (hours)") %>% + split_cols_by(var = "PPINT") %>% + split_cols_by(var = "PKPARAM") %>% + split_rows_by( + var = "ARMCD", + split_fun = trim_levels_in_group("ACTARM"), + label_pos = "topleft", + split_label = "Treatment Arm" + ) %>% + analyze_vars( + vars = "AVAL", + .stats = c( + "n", "mean", "sd", "cv", + "median", "min", "max" + ), + .labels = c( + n = "n", + mean = "Mean", + sd = "SD", + cv = "CV (%)", + 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), + min = format_sigfig(3), + max = format_sigfig(3) + ) + ) +adpp0 <- adpp %>% + filter( + AVISIT == "CYCLE 1 DAY 1", + PPCAT == "Plasma Drug X" + ) %>% + h_pkparam_sort() %>% + mutate( + PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")")) + ) + +result <- build_table(lyt, df = adpp0) +main_title(result) <- paste( + "Summary of Cumulative Amount and Percentage of", unique(adpp0$PPSPEC), "Recovered from\n", + unique(adpp0$PPCAT), "following", unique(adpp0$REGIMEN), "Administration for", + unique(adpp0$PPINT)[length(unique(adpp0$PPINT))], "hours, PK Population" +) +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) + +cat(rtables::toString(result, indent_size = 10)) +``` + +{{< include ../../test-utils/save_results.qmd >}} ## `teal` App diff --git a/book/tables/pharmacokinetic/pkpt11.qmd b/book/tables/pharmacokinetic/pkpt11.qmd index 0998fa5183..17c98e56d2 100644 --- a/book/tables/pharmacokinetic/pkpt11.qmd +++ b/book/tables/pharmacokinetic/pkpt11.qmd @@ -10,9 +10,154 @@ subtitle: Pharmacokinetic Parameter Estimated Ratios of Geometric Means and 90% ::: panel-tabset ## Data Setup +```{r setup, message=FALSE} +#| code-fold: show + +library(scda) +library(dplyr) +library(tern) + +adpp <- synthetic_cdisc_dataset("latest", "adpp") + +# Comparator Dose - A: Drug X +arm_var <- "TRT01A" +comp_dose <- "A: Drug X" +other_doses <- as.character(unique(adpp[[arm_var]])[unique(adpp[[arm_var]]) != comp_dose]) + +adpp <- adpp %>% + filter(AVISIT == "CYCLE 1 DAY 1") %>% + mutate( + COMP = paste0(TRT01A, "/", comp_dose), + COMP_AVAL = ifelse(TRT01A == comp_dose, paste0(AVAL, comp_dose), AVAL) + ) + +for (dose in other_doses) { + temp_df <- adpp[adpp[[arm_var]] == comp_dose, ] + temp_df$COMP <- paste0(dose, "/", comp_dose) + adpp <- rbind(adpp, temp_df) +} + +# Plasma Drug X +adpp0 <- adpp %>% + filter(PPCAT == "Plasma Drug X") %>% + h_pkparam_sort() %>% + mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) %>% + var_relabel(COMP = "Comparison") + +# statistics function +s_gmr <- function(df, + compare_dose = comp_dose, # comparator, defaults to comp_dose defined above (string) + denom = TRUE, # whether to use comparator as denominator, defaults to TRUE (logical) + arm_var = arm_var) { # arm variable, defaults to arm_var defined above (string) + which_num <- !grepl(compare_dose, df[[arm_var]]) + + x_num <- as.numeric(df[which_num, ][["AVAL"]]) + x_num <- x_num[!is.na(x_num)] + x_num_no_negative_vals <- x_num + x_num_no_negative_vals[x_num_no_negative_vals <= 0] <- NA + + x_denom <- as.numeric(gsub(compare_dose, "", df[!which_num, ][["AVAL"]])) + x_denom <- x_denom[!is.na(x_denom)] + x_denom_no_negative_vals <- x_denom + x_denom_no_negative_vals[x_denom_no_negative_vals <= 0] <- NA + + x_num_log <- log(x_num_no_negative_vals) + x_denom_log <- log(x_denom_no_negative_vals) + + if (denom) { + geom_mean_ratio <- exp(mean(x_num_log, na.rm = FALSE)) / exp(mean(x_denom_log, na.rm = FALSE)) + geom_mean_ci <- t.test(x_num_log, x_denom_log, conf.level = 0.90)$conf.int + } else { + geom_mean_ratio <- exp(mean(x_denom_log, na.rm = FALSE)) / exp(mean(x_num_log, na.rm = FALSE)) + geom_mean_ci <- t.test(x_denom_log, x_num_log, conf.level = 0.90)$conf.int + } + + list( + n = nrow(df), + geom_mean_ratio = geom_mean_ratio, + gmr_ci_lwr = exp(geom_mean_ci[1]), + gmr_ci_upr = exp(geom_mean_ci[2]) + ) +} + +afun_pk_gmr <- function(.formats = list( + n = "xx.", + geom_mean_ratio = format_sigfig(3), + gmr_ci_lwr = format_sigfig(3), + gmr_ci_upr = format_sigfig(3) + ), + compare_dose = comp_dose, + denom = TRUE) { + checkmate::assert_list(.formats) + checkmate::assert_subset(names(.formats), c("n", "geom_mean_ratio", "gmr_ci_lwr", "gmr_ci_upr")) + + afun_lst <- Map( + function(stat, fmt, compare_dose, denom, arm_var) { + function(df, .spl_context) { + x_stat <- s_gmr(df, compare_dose = compare_dose, denom = denom, arm_var = arm_var)[[stat]] + rcell(x_stat, format = fmt, label = tail(.spl_context$value, 1)) + } + }, + stat = names(.formats), + fmt = .formats, + compare_dose = compare_dose, + denom = denom, + arm_var = arm_var + ) + + afun_lst +} +``` ## Standard Table -- Plasma +```{r variant1, test = list(result_v1 = "result")} +# create layout +lyt <- basic_table() %>% + split_rows_by( + var = "PKPARAM", + label_pos = "topleft", + split_fun = keep_split_levels(c("AUCinf obs (day*ug/mL)", "Cmax (ug/mL)")), + split_label = "PK Parameter" + ) %>% + split_rows_by( + var = "COMP", + split_fun = remove_split_levels(paste0(comp_dose, "/", comp_dose)), + indent_mod = 11L, + child_labels = "hidden" + ) %>% + split_cols_by_multivar( + vars = rep("AVAL", 4), + varlabels = c( + "n", + "Geometric Mean Ratio", + "90% CI Lower Bound", + "90% CI Upper Bound" + ) + ) %>% + analyze_colvars( + afun = afun_pk_gmr(), + extra_args = list( + compare_dose = comp_dose, + denom = TRUE, + arm_var = arm_var + ) + ) %>% + append_varlabels(adpp0, "COMP", 12L) + +result <- build_table(lyt, df = adpp0) + +main_title(result) <- paste0( + "Estimated Ratios of Geometric Means and 90% Confidence Intervals for AUC and CMAX Following ", + unique(adpp0$REGIMEN), "\nof ", comp_dose, " in Comparison with ", + paste(other_doses, collapse = " & "), ", PK Population" +) +subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT)) + +result +``` + +{{< include ../../test-utils/save_results.qmd >}} ## `teal` App