@@ -20,7 +20,7 @@ library(formatters)
2020library(cards)
2121library(gtsummary)
2222
23- adsl <- random.cdisc.data::cadsl
23+ adsl <- pharmaverseadam::adsl
2424
2525set.seed(1)
2626adsl$RANDDT[sample(seq_len(nrow(adsl)), 100)] <- NA
@@ -35,76 +35,37 @@ data <- adsl |>
3535 levels = scrnfail_reas_lvls
3636 ),
3737 ENRLFL = with_label(!is.na(ENRLDT), "Subjects enrolled"),
38- RANDFL = with_label(!is.na(RANDDT), "Subjects randomized")
38+ RANDFL = with_label(!is.na(RANDDT), "Subjects randomized"),
39+ screen_fail = !ENRLFL # create a flag for screen failure
3940 )
4041data$SCRNFRS[data$SCRNFL == "N" | !is.na(data$ENRLDT)] <- NA
4142```
4243
43- ## Build ARD
44-
45- ``` {r ard, message=FALSE, warning=FALSE, results='hide'}
46- ard <- data |>
47- ard_stack(
48- ard_dichotomous(
49- variables = SCRNFL,
50- value = list(SCRNFL = TRUE),
51- statistic = everything() ~ c("n")
52- ),
53- ard_categorical(
54- variables = SCRNFRS,
55- statistic = everything() ~ c("n", "p"),
56- denominator = data
57- ),
58- ard_dichotomous(
59- variables = c(ENRLFL, RANDFL),
60- value = list(ENRLFL = TRUE, RANDFL = TRUE),
61- statistic = everything() ~ c("n", "p"),
62- denominator = data
63- )
64- )
65-
66- ard
67- ```
68-
69- ``` {r, echo=FALSE}
70- # Print ARD
71- withr::local_options(width = 9999)
72- print(ard, columns = "all", n = 40)
73- ```
74-
7544## Build Table
7645
7746``` {r tbl, message=FALSE, warning=FALSE, results='hide'}
78- tbl_scrn <- tbl_summary(
79- data = data,
80- by = TRT01A,
81- include = "SCRNFL",
82- missing = "no"
83- )
84-
85- tbl_scrnfrs <- tbl_hierarchical(
86- data = data,
87- denominator = adsl,
88- id = USUBJID,
89- by = TRT01A,
90- variables = "SCRNFRS",
91- label = list(..ard_hierarchical_overall.. = "Screening failures"),
92- overall_row = TRUE
93- ) |>
94- modify_indent(columns = label, rows = row_type == "level", indent = 4L) |>
47+ tbl <- data |>
48+ tbl_summary(
49+ include = c(SCRNFL, screen_fail, SCRNFRS, ENRLFL, RANDFL),
50+ # suppress number of missing observations
51+ missing = "no",
52+ # specify the denominator is always the no. obs. in `data`
53+ percent = data,
54+ # present SCRNFRS in descending order of frequency
55+ sort = SCRNFRS ~ "frequency",
56+ # update default screen failure label
57+ label = list(screen_fail = "Screening failures")
58+ ) |>
59+ # remove the blank header row for SCRNFRS
60+ remove_row_type(SCRNFRS, type = "header") |>
61+ modify_header(
62+ label = "**Disposition**",
63+ stat_0 = "**Trial A** \n N = {n}"
64+ ) |>
65+ # update indentation for screening failures subsection
66+ modify_indent(columns = label, rows = variable == "screen_fail", indent = 4L) |>
9567 modify_indent(columns = label, rows = variable == "SCRNFRS", indent = 8L)
9668
97- tbl_enrl_rand <- tbl_summary(
98- data = data,
99- by = TRT01A,
100- include = c("ENRLFL", "RANDFL"),
101- missing = "no"
102- )
103-
104- tbl <- list(tbl_scrn, tbl_scrnfrs, tbl_enrl_rand) |>
105- tbl_stack() |>
106- modify_header(label = "**Disposition**")
107-
10869tbl
10970```
11071
@@ -115,4 +76,18 @@ gt::gtsave(as_gt(tbl), filename = "result.png")
11576
11677``` {r img, echo=FALSE, fig.align='center', out.width='60%'}
11778```
79+
80+ ## Build ARD
81+
82+ ``` {r ard, message=FALSE, warning=FALSE, results='hide'}
83+ ard <- gather_ard(tbl)
84+
85+ ard
86+ ```
87+
88+ ``` {r, echo=FALSE}
89+ # Print ARD
90+ withr::local_options(width = 9999)
91+ print(ard)
92+ ```
11893:::
0 commit comments