I am generating an AE table with Overall row at top ("Any Adverse Event..."). I have successfully created table from ARD without the Overall row using code below.
# Read in data
adsl <- cards::ADSL %>%
mutate(TRTP = TRT01P)
adae <- cards::ADAE %>%
filter(SAFFL == "Y") %>%
left_join(adsl %>% select(c(USUBJID, TRTP)),
by = "USUBJID") %>%
select(c(USUBJID, TRTP, AESOC, AEDECOD))
# Stack creation
ard.stck <- cards::ard_stack_hierarchical(
data = adae,
variables = c(AESOC, AEDECOD),
by = TRTP,
denominator = adsl,
id = USUBJID,
include = everything(),
statistic = everything() ~ c("n", "N", "p")
)
# ARD table
ard.stck %>% tbl_ard_hierarchical(
variables = c(AESOC, AEDECOD),
by = TRTP,
statistic = all_categorical() ~ c("{n} ({p}%)")) %>%
modify_header(all_stat_cols() ~ "**{level}** \nN = {n}")
When I try to add Overall on the stack using syntax below, the table format is messed up (added screenshot bottom). Code syntax below:
# Add Overall row
ard.stck.ov <- cards::ard_stack_hierarchical(
data = adae,
variables = c(AESOC, AEDECOD),
by = TRTP,
denominator = adsl,
id = USUBJID,
include = everything(),
statistic = everything() ~ c("n", "N", "p"),
overall = TRUE
)
ard.stck.ov %>% tbl_ard_hierarchical(
variables = c(AESOC, AEDECOD),
by = TRTP,
statistic = all_categorical() ~ c("{n} ({p}%)")) %>%
modify_header(all_stat_cols() ~ "**{level}** \nN = {n}")
Please let me know if I am not doing this correctly. Thank you!!
The simplest way to get a table and an ARD for the AE summaries is to build the table with tbl_hierarchical()
and get the ARD from the table with gather_ard()
.
library(gtsummary)
library(dplyr)
adsl <- cards::ADSL %>%
mutate(TRTP = TRT01P)
adae <- cards::ADAE %>%
filter(SAFFL == "Y") %>%
left_join(adsl %>% select(c(USUBJID, TRTP)), by = "USUBJID") %>%
select(c(USUBJID, TRTP, AESOC, AEDECOD))
# Method 1: Build table, then get ARD from table
tbl<-
tbl_hierarchical(
adae,
variables = c(AESOC, AEDECOD),
by = TRTP,
denominator = adsl,
id = USUBJID
) |>
add_overall()
ard <- gather_ard(tbl)
The tbl_ard_hierarchical()
function is still waiting on features like the overall argument. You should be able to create one table stratified by TRTP and the other not, then merge them with tbl_merge()