Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reorder columns #256

Merged
merged 20 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions book/tables/ADA/adat01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,32 @@ library(tibble)
adsl <- random.cdisc.data::cadsl
adab <- random.cdisc.data::cadab

combodf <- tribble(
~valname, ~label, ~levelcombo, ~exargs,
"all_X", "All Drug X", c("A: Drug X", "C: Combination"), list(),
"all_pt", "All Patients", c("A: Drug X", "B: Placebo", "C: Combination"), list()
# Order needed for the columns is c(1, 3, 4, 2, 5)
reorder_facets <- function(splret, spl, fulldf, ...) {
ord <- c(1, 3, 4, 2, 5)
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}

# Create a custom split function for adding the new columns (facets) and sorting them
custom_column_split_fun <- make_split_fun(
post = list(
add_combo_facet("all_X",
label = "All Drug X",
levels = c("A: Drug X", "C: Combination")
),
add_combo_facet("all_pt",
label = "All Patients",
levels = c("A: Drug X", "B: Placebo", "C: Combination")
),
reorder_facets
)
)


# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adab <- adab %>%
Expand Down Expand Up @@ -133,12 +153,13 @@ adab_pb <- df_explicit_na(adab) %>%
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of https://github.com/insightsengineering/rtables/issues/830 -->

```{r variant1, test = list(result_v1 = "result"), opts.label = ifelse(packageVersion("rtables") < "0.6.6.9011", "skip_test_strict", "")}
# Layout for Baseline Prevalence of NAbs
lyt_bl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -169,7 +190,7 @@ lyt_bl <- basic_table(show_colcounts = TRUE) %>%
lyt_pb <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -217,12 +238,6 @@ result_2 <- build_table(lyt_pb, df = adab_pb, alt_counts_df = adsl)
result_1@col_info <- result_2@col_info
result <- rbind(result_1, result_2)

# Change the column order.
result <- cbind_rtables(result[, 1], result[, 3]) %>%
cbind_rtables(result[, 4]) %>%
cbind_rtables(result[, 2]) %>%
cbind_rtables(result[, 5])

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Treatment Emergent ADA"
)
Expand Down
39 changes: 27 additions & 12 deletions book/tables/ADA/adat04a.qmd
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,30 @@ library(tibble)
adsl <- random.cdisc.data::cadsl
adab <- random.cdisc.data::cadab

combodf <- tribble(
~valname, ~label, ~levelcombo, ~exargs,
"all_X", "All Drug X", c("A: Drug X", "C: Combination"), list(),
"all_pt", "All Patients", c("A: Drug X", "B: Placebo", "C: Combination"), list()

# Order needed for the columns is c(1, 3, 4, 2, 5)
reorder_facets <- function(splret, spl, fulldf, ...) {
ord <- c(1, 3, 4, 2, 5)
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}

# Create a custom split function for adding the new columns (facets) and sorting them
custom_column_split_fun <- make_split_fun(
post = list(
add_combo_facet("all_X",
label = "All Drug X",
levels = c("A: Drug X", "C: Combination")
),
add_combo_facet("all_pt",
label = "All Patients",
levels = c("A: Drug X", "B: Placebo", "C: Combination")
),
reorder_facets
)
)

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
Expand Down Expand Up @@ -160,12 +180,13 @@ adab_pb <- df_explicit_na(adab) %>%
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of https://github.com/insightsengineering/rtables/issues/830 -->

```{r variant1, test = list(result_v1 = "result"), opts.label = ifelse(packageVersion("rtables") < "0.6.6.9011", "skip_test_strict", "")}
# Layout for Baseline Prevalence of NAbs
lyt_bl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -194,7 +215,7 @@ lyt_bl <- basic_table(show_colcounts = TRUE) %>%
lyt_pb <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -241,12 +262,6 @@ result_2 <- build_table(lyt_pb, df = adab_pb, alt_counts_df = adsl)
# Combine tables
result <- rbind(result_1, result_2)

# Change the column order
result <- cbind_rtables(result[, 1], result[, 3]) %>%
cbind_rtables(result[, 4]) %>%
cbind_rtables(result[, 2]) %>%
cbind_rtables(result[, 5])

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Treatment Emergent NAbs"
)
Expand Down
38 changes: 26 additions & 12 deletions book/tables/ADA/adat04b.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,29 @@ library(tibble)
adsl <- random.cdisc.data::cadsl
adab <- random.cdisc.data::cadab

combodf <- tribble(
~valname, ~label, ~levelcombo, ~exargs,
"all_X", "All Drug X", c("A: Drug X", "C: Combination"), list(),
"all_pt", "All Patients", c("A: Drug X", "B: Placebo", "C: Combination"), list()
# Order needed for the columns is c(1, 3, 4, 2, 5)
reorder_facets <- function(splret, spl, fulldf, ...) {
ord <- c(1, 3, 4, 2, 5)
make_split_result(
splret$values[ord],
splret$datasplit[ord],
splret$labels[ord]
)
}

# Create a custom split function for adding the new columns (facets) and sorting them
custom_column_split_fun <- make_split_fun(
post = list(
add_combo_facet("all_X",
label = "All Drug X",
levels = c("A: Drug X", "C: Combination")
),
add_combo_facet("all_pt",
label = "All Patients",
levels = c("A: Drug X", "B: Placebo", "C: Combination")
),
reorder_facets
)
)

# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
Expand Down Expand Up @@ -140,12 +159,13 @@ adab_pb <- left_join(adab_pb_ada, adab_pb_adap, by = mergecol) %>%
## {{< fa regular file-lines sm fw >}} Preview

<!-- skip strict because of https://github.com/insightsengineering/rtables/issues/830 -->

```{r variant1, test = list(result_v1 = "result"), opts.label = ifelse(packageVersion("rtables") < "0.6.6.9011", "skip_test_strict", "")}
# Layout for Baseline Prevalence of NAbs
lyt_bl <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -175,7 +195,7 @@ lyt_bl <- basic_table(show_colcounts = TRUE) %>%
lyt_pb <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
"ACTARM",
split_fun = add_combo_levels(combodf)
split_fun = custom_column_split_fun
) %>%
count_patients_with_flags(
"USUBJID",
Expand Down Expand Up @@ -207,12 +227,6 @@ result_2 <- build_table(lyt_pb, df = adab_pb, alt_counts_df = adsl)
# Combine tables.
result <- rbind(result_1, result_2)

# Change the column order.
result <- cbind_rtables(result[, 1], result[, 3]) %>%
cbind_rtables(result[, 4]) %>%
cbind_rtables(result[, 2]) %>%
cbind_rtables(result[, 5])

main_title(result) <- paste(
"Baseline Prevalence and Incidence of Neutralizing Antibodies (NAbs)"
)
Expand Down
9 changes: 6 additions & 3 deletions book/tables/efficacy/rbmit01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ subtitle: Tables for RBMI

{{< include ../../_utils/envir_hook.qmd >}}

:::: {.panel-tabset}
::: panel-tabset
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
## Data Setup

We use a publicly available example dataset from an antidepressant clinical trial of an active drug versus placebo from the `rbmi` package.
Expand Down Expand Up @@ -117,10 +117,11 @@ draws_vars$subjid <- "TMP_ID"
Define which imputation method to use, then create samples for the imputation parameters by running the `draws()` function.

<!-- skip strict because of https://github.com/insightsengineering/rbmi/issues/409 -->

```{r, warning = FALSE, opts.label = "skip_test_strict"}
#| code-fold: show

draws_method <- method_bayes()
draws_method <- method_bayes(seed = 123)

draws_obj <- rbmi::draws(
data = data_full,
Expand Down Expand Up @@ -154,6 +155,7 @@ The next step is to run the analysis model on each imputed dataset.
This is done by defining an analysis function and then calling `rbmi::analyse()` to apply this function to each imputed dataset.

<!-- skip strict because of https://github.com/insightsengineering/rbmi/issues/409 -->

```{r, opts.label = "skip_test_strict"}
#| code-fold: show
#| opts_label: "skip_test_strict" #
Expand Down Expand Up @@ -183,6 +185,7 @@ The `rbmi::pool()` function can be used to summarize the analysis results across
Using the `broom::tidy()` function the `rbmi` final results are reshaped.

<!-- skip strict because of https://github.com/insightsengineering/rbmi/issues/409 -->

```{r, opts.label = "skip_test_strict"}
#| code-fold: show

Expand Down Expand Up @@ -215,5 +218,5 @@ result
{{< include ../../_utils/save_results.qmd >}}

{{< include ../../repro.qmd >}}
:::

::::
32 changes: 16 additions & 16 deletions package/tests/testthat/_snaps/development/tables-ADA-adat01.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
Output
Baseline Prevalence and Incidence of Treatment Emergent ADA

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X C: Combination <Missing> B: Placebo All Drug X
(N=134) (N=132) (N=0) (N=134) (N=266)
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Baseline Prevalence of ADAs
Baseline evaluable patients 134 132 0 0 266
Patient with a positive sample at baseline 63 (47.0%) 64 (48.5%) 0 0 127 (47.7%)
Patient with no positive samples at baseline 71 68 0 0 139
Incidence of Treatment Emergent ADAs
Post-baseline evaluable patients 134 132 0 0 266
Patient positive for Treatment Emergent ADA 0 0 0 0 0
Treatment-induced ADA 0 0 0 0 0
Treatment-enhanced ADA 0 0 0 0 0
Patient negative for Treatment Emergent ADA 0 0 0 0 0
Treatment unaffected 0 0 0 0 0
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X C: Combination <Missing> B: Placebo All Drug X
(N=134) (N=132) (N=0) (N=134) (N=266)
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Baseline Prevalence of ADAs
Baseline evaluable patients 134 132 0 0 266
Patient with a positive sample at baseline 63 (47.0%) 64 (48.5%) 0 0 127 (47.7%)
Patient with no positive samples at baseline 71 68 0 0 139
Incidence of Treatment Emergent ADAs
Post-baseline evaluable patients 134 132 0 0 266
Patient positive for Treatment Emergent ADA 0 0 0 0 0
Treatment-induced ADA 0 0 0 0 0
Treatment-enhanced ADA 0 0 0 0 0
Patient negative for Treatment Emergent ADA 0 0 0 0 0
Treatment unaffected 0 0 0 0 0
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————

ADA = Anti-Drug Antibodies (is also referred to as ATA, or Anti-Therapeutic Antibodies) Baseline evaluable patient = a patient with an ADA assay result from a baseline sample(s)
Post-baseline evaluable patient = a patient with an ADA assay result from at least one post-baseline sample Number of patients positive for Treatment Emergent
Expand Down
Melkiades marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
Relative Reduction (%) 5.7%
p-value (RBMI) 0.8932
5
Adjusted Mean (SE) -4.251 (0.647) -2.805 (0.644)
95% CI (-5.528, -2.974) (-4.077, -1.533)
Difference in Adjusted Means (SE) 1.446 (0.914)
95% CI (-0.358, 3.250)
Relative Reduction (%) -34.0%
p-value (RBMI) 0.1155
Adjusted Mean (SE) -4.255 (0.653) -2.857 (0.634)
95% CI (-5.546, -2.965) (-4.109, -1.605)
Difference in Adjusted Means (SE) 1.398 (0.915)
95% CI (-0.409, 3.205)
Relative Reduction (%) -32.9%
p-value (RBMI) 0.1285
6
Adjusted Mean (SE) -6.366 (0.721) -4.095 (0.696)
95% CI (-7.793, -4.939) (-5.471, -2.720)
Difference in Adjusted Means (SE) 2.270 (0.996)
95% CI (0.301, 4.239)
Relative Reduction (%) -35.7%
p-value (RBMI) 0.0241
Adjusted Mean (SE) -6.413 (0.712) -4.166 (0.692)
95% CI (-7.821, -5.005) (-5.533, -2.800)
Difference in Adjusted Means (SE) 2.246 (1.005)
95% CI (0.260, 4.232)
Relative Reduction (%) -35.0%
p-value (RBMI) 0.0269
7
Adjusted Mean (SE) -7.689 (0.797) -4.776 (0.752)
95% CI (-9.266, -6.112) (-6.261, -3.290)
Difference in Adjusted Means (SE) 2.913 (1.073)
95% CI (0.792, 5.035)
Relative Reduction (%) -37.9%
p-value (RBMI) 0.0074
Adjusted Mean (SE) -7.652 (0.775) -4.939 (0.771)
95% CI (-9.185, -6.120) (-6.465, -3.414)
Difference in Adjusted Means (SE) 2.713 (1.099)
95% CI (0.538, 4.888)
Relative Reduction (%) -35.5%
p-value (RBMI) 0.0149

Loading
Loading