AET10
Most Common (\(\geq\) 5%) Adverse Events
The “All Patients” column is not required in this table but for illustrative purposes we include it to show correct sorting.
Code
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
var = "ARM",
split_fun = add_overall_level("All Patients", first = FALSE)
) %>%
count_occurrences(vars = "AEDECOD")
tbl1 <- build_table(
lyt = lyt,
df = adae,
alt_counts_df = adsl
)
tbl2 <- prune_table(
tt = tbl1,
prune_func = keep_rows(
has_fraction_in_any_col(
atleast = 0.05, # specify threshold
col_names = levels(adsl$ARM)
)
)
)
result <- sort_at_path(
tbl2,
path = c("AEDECOD"),
scorefun = score_occurrences
)
result
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
-----------------------------------------------------------------------
dcd D.2.1.5.3 47 (35.1%) 58 (43.3%) 57 (43.2%) 162 (40.5%)
dcd A.1.1.1.1 50 (37.3%) 45 (33.6%) 63 (47.7%) 158 (39.5%)
dcd B.2.2.3.1 48 (35.8%) 54 (40.3%) 51 (38.6%) 153 (38.2%)
dcd A.1.1.1.2 48 (35.8%) 48 (35.8%) 50 (37.9%) 146 (36.5%)
dcd B.2.1.2.1 49 (36.6%) 44 (32.8%) 52 (39.4%) 145 (36.2%)
dcd D.1.1.1.1 50 (37.3%) 42 (31.3%) 51 (38.6%) 143 (35.8%)
dcd D.1.1.4.2 48 (35.8%) 42 (31.3%) 50 (37.9%) 140 (35.0%)
dcd B.1.1.1.1 47 (35.1%) 49 (36.6%) 43 (32.6%) 139 (34.8%)
dcd C.2.1.2.1 35 (26.1%) 48 (35.8%) 55 (41.7%) 138 (34.5%)
dcd C.1.1.1.3 43 (32.1%) 46 (34.3%) 43 (32.6%) 132 (33.0%)
Code
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
var = "ARM",
split_fun = add_overall_level("All Patients", first = FALSE)
) %>%
count_occurrences(vars = "AEDECOD")
tbl1 <- build_table(
lyt = lyt,
df = adae,
alt_counts_df = adsl
)
tbl2 <- prune_table(
tt = tbl1,
prune_func = keep_rows(
has_fraction_in_any_col(
atleast = 0.35, # specify threshold
col_names = levels(adsl$ARM)
)
)
)
result <- sort_at_path(
tbl2,
path = c("AEDECOD"),
scorefun = score_occurrences
)
result
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
-----------------------------------------------------------------------
dcd D.2.1.5.3 47 (35.1%) 58 (43.3%) 57 (43.2%) 162 (40.5%)
dcd A.1.1.1.1 50 (37.3%) 45 (33.6%) 63 (47.7%) 158 (39.5%)
dcd B.2.2.3.1 48 (35.8%) 54 (40.3%) 51 (38.6%) 153 (38.2%)
dcd A.1.1.1.2 48 (35.8%) 48 (35.8%) 50 (37.9%) 146 (36.5%)
dcd B.2.1.2.1 49 (36.6%) 44 (32.8%) 52 (39.4%) 145 (36.2%)
dcd D.1.1.1.1 50 (37.3%) 42 (31.3%) 51 (38.6%) 143 (35.8%)
dcd D.1.1.4.2 48 (35.8%) 42 (31.3%) 50 (37.9%) 140 (35.0%)
dcd B.1.1.1.1 47 (35.1%) 49 (36.6%) 43 (32.6%) 139 (34.8%)
dcd C.2.1.2.1 35 (26.1%) 48 (35.8%) 55 (41.7%) 138 (34.5%)
The desired frequency is specified in prune_freq
. For illustration, frequency is set to \(\geq\) 35%.
Code
library(teal.modules.clinical)
## Data reproducible code
data <- teal_data()
data <- within(data, {
ADSL <- random.cdisc.data::cadsl
ADAE <- random.cdisc.data::cadae
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
ADSL <- df_explicit_na(ADSL)
ADAE <- df_explicit_na(ADAE)
})
datanames <- c("ADSL", "ADAE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
## Reusable Configuration For Modules
ADAE <- data[["ADAE"]]
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_events(
label = "Adverse Event Table",
dataname = "ADAE",
arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
llt = choices_selected(
choices = variable_choices(ADAE, c("AETERM", "AEDECOD")),
selected = c("AEDECOD")
),
hlt = choices_selected(
choices = variable_choices(ADAE, c("AEBODSYS", "AESOC")),
selected = NULL
),
add_total = TRUE,
event_type = "adverse event",
prune_freq = 35,
)
)
)
shinyApp(app$ui, app$server)
Experimental use!
shinylive
allow you to modify to run shiny
application entirely in the web browser. Modify the code below and click re-run the app to see the results. The performance is slighly worse and some of the features (e.g. downloading) might not work at all.
#| standalone: true
#| viewerHeight: 800
#| components: [viewer, editor]
#| layout: vertical
# -- WEBR HELPERS --
options(webr_pkg_repos = c("r-universe" = "https://pharmaverse.r-universe.dev", getOption("webr_pkg_repos")))
if (packageVersion("webr") < "0.3.0") {
.e <- as.environment("webr_shims")
.e[["library"]] <- function(pkg, ...) {
package <- as.character(substitute(pkg))
if (length(find.package(package, quiet = TRUE)) == 0) {
webr::install(package)
}
base::library(package, character.only = TRUE, ...)
}
}
# -- APP CODE --
library(teal.modules.clinical)
## Data reproducible code
data <- teal_data()
data <- within(data, {
ADSL <- random.cdisc.data::cadsl
ADAE <- random.cdisc.data::cadae
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
ADSL <- df_explicit_na(ADSL)
ADAE <- df_explicit_na(ADAE)
})
datanames <- c("ADSL", "ADAE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
## Reusable Configuration For Modules
ADAE <- data[["ADAE"]]
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_events(
label = "Adverse Event Table",
dataname = "ADAE",
arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
llt = choices_selected(
choices = variable_choices(ADAE, c("AETERM", "AEDECOD")),
selected = c("AEDECOD")
),
hlt = choices_selected(
choices = variable_choices(ADAE, c("AEBODSYS", "AESOC")),
selected = NULL
),
add_total = TRUE,
event_type = "adverse event",
prune_freq = 35,
)
)
)
shinyApp(app$ui, app$server)
Timestamp
Session Info
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
locale:
[1] C
time zone: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] teal.modules.clinical_0.9.1.9005 teal.transform_0.5.0.9005
[3] teal_0.15.2.9036 teal.slice_0.5.1.9002
[5] teal.data_0.6.0.9002 teal.code_0.5.0.9005
[7] shiny_1.8.1.1 dplyr_1.1.4
[9] tern_0.9.4.9007 rtables_0.6.7.9002
[11] magrittr_2.0.3 formatters_0.5.6.9004
loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 fastmap_1.1.1
[3] random.cdisc.data_0.3.15.9003 TH.data_1.1-2
[5] webshot2_0.1.1 shinyjs_2.1.0
[7] promises_1.3.0 digest_0.6.35
[9] estimability_1.5 mime_0.12
[11] tern.gee_0.1.3.9006 lifecycle_1.0.4
[13] survival_3.6-4 processx_3.8.4
[15] compiler_4.4.0 sass_0.4.9
[17] rlang_1.1.3 tools_4.4.0
[19] utf8_1.2.4 yaml_2.3.8
[21] knitr_1.46 htmlwidgets_1.6.4
[23] multcomp_1.4-25 websocket_1.4.1
[25] withr_3.0.0 purrr_1.0.2
[27] shinyWidgets_0.8.6 geepack_1.3.10
[29] grid_4.4.0 fansi_1.0.6
[31] teal.logger_0.2.0.9002 xtable_1.8-4
[33] colorspace_2.1-0 ggplot2_3.5.1
[35] emmeans_1.10.1 scales_1.3.0
[37] MASS_7.3-60.2 cli_3.6.2
[39] mvtnorm_1.2-4 rmarkdown_2.26
[41] generics_0.1.3 cachem_1.0.8
[43] chromote_0.2.0 stringr_1.5.1
[45] splines_4.4.0 formatR_1.14
[47] vctrs_0.6.5 webshot_0.5.5
[49] Matrix_1.7-0 sandwich_3.1-0
[51] jsonlite_1.8.8 callr_3.7.6
[53] teal.widgets_0.4.2.9011 testthat_3.2.1.1
[55] fontawesome_0.5.2 jquerylib_0.1.4
[57] tidyr_1.3.1 glue_1.7.0
[59] codetools_0.2-20 ps_1.7.6
[61] stringi_1.8.3 gtable_0.3.5
[63] later_1.3.2 shinycssloaders_1.0.0
[65] munsell_0.5.1 tibble_3.2.1
[67] logger_0.3.0 pillar_1.9.0
[69] htmltools_0.5.8.1 brio_1.1.5
[71] R6_2.5.1 Rdpack_2.6
[73] evaluate_0.23 lattice_0.22-6
[75] rbibutils_2.2.16 backports_1.4.1
[77] memoise_2.0.1 broom_1.0.5
[79] teal.reporter_0.3.1.9005 bslib_0.7.0
[81] httpuv_1.6.15 Rcpp_1.0.12
[83] shinyvalidate_0.1.3 coda_0.19-4.1
[85] nlme_3.1-164 checkmate_2.3.1
[87] xfun_0.43 zoo_1.8-12
[89] forcats_1.0.0 pkgconfig_2.0.3
.lock
file
Download the .lock
file and use renv::restore()
on it to recreate environment used to generate this website.
Code
parent_file_path <- knitr::current_input(dir = TRUE)
book_root_dir <- parent_file_path
while (!file.exists(file.path(book_root_dir, "_quarto.yml"))) book_root_dir <- dirname(book_root_dir)
lock_path <- file.path(
"../../assets/www/lock",
paste0(
gsub(
file.path(book_root_dir, ""),
"",
gsub(
"\\.rmarkdown$",
"",
knitr::current_input(dir = TRUE)
)
),
".lock"
)
)
withr::with_options(
list(renv.verbose = FALSE),
renv::snapshot(parent_file_path, lockfile = lock_path, prompt = FALSE, force = TRUE)
)