Adverse Event
Visualization of adverse event


We will here use the tabTOX, tabTOX_arm and plotTOX functions in the Data & Functions page.
Download Tox_functions.R

# Libraries
library(tidyverse)
library(ggplot2)

# Creation of datasets
set.seed(1234)
n_AE <- 300
n_pat <- 100
df <- data.frame(OBS = sample(1:n_pat, n_AE, replace=T),
                 cat_tox = sample(paste("cat", 1:3), n_AE, replace=T),
                 tox = sample(paste("tox", 1:2), n_AE, replace=T),
                 tox_bis = sample(paste("tox", 1:20), n_AE, replace=T),
                 grade = sample(c(1, 2, 3, 4, 5, NA), n_AE, prob=c(0.3, 0.3, 0.2, 0.1, 0.05, 0.05), replace=T)) %>% arrange(OBS)
df$ARM <- ifelse(df$OBS%in%1:50, 'A', 'B')

df_bis <- data.frame(NAME = rep(paste("tox", 1:8), each=2),
                     N = sample(0:(n_pat/2), 16, replace=T),
                     ARM = rep(c('A', 'B'), 8))

tabTOX function


tabae1 <- tabTOX(df, "OBS", var="tox", var_grade="grade",
                 grade_max=FALSE, percent="%", latex=FALSE, langue='en')
tox N N grade 1 N grade 2 N grade 3 N grade 4 N grade 5 N missing grade
Total 97 64 62 44 20 7 12
tox 1 85 40 45 26 12 5 5
tox 2 76 40 30 23 11 2 7

Here is another example where other optional parameters are used:

tabae2 <- tabTOX(df, "OBS", var="tox", var_cat="cat_tox", var_grade="grade",
                 grade_max=TRUE, percent="%", latex=FALSE, langue='en',
                 all=FALSE, addNA=FALSE, var_name="AE", total="All", n=n_pat)
AE N grade 1 N grade 2 N grade 3 N grade 4 N grade 5
All 11 (11%) 28 (28%) 31 (31%) 20 (20%) 7 (7%)
cat 3 20 (20%) 22 (22%) 13 (13%) 11 (11%) 3 (3%)
- tox 1 16 (16%) 17 (17%) 10 (10%) 7 (7%) 1 (1%)
- tox 2 18 (18%) 10 (10%) 3 (3%) 4 (4%) 2 (2%)
cat 2 13 (13%) 20 (20%) 16 (16%) 7 (7%) 3 (3%)
- tox 1 10 (10%) 14 (14%) 8 (8%) 2 (2%) 3 (3%)
- tox 2 10 (10%) 9 (9%) 11 (11%) 5 (5%) 0
cat 1 13 (13%) 17 (17%) 15 (15%) 5 (5%) 1 (1%)
- tox 2 11 (11%) 10 (10%) 10 (10%) 3 (3%) 0
- tox 1 9 (9%) 9 (9%) 7 (7%) 3 (3%) 1 (1%)

In the example above, only the maximal grade per toxicity is taken into account, missing grades and any grades are not displayed. Category of each adverse event is added. The percentages of the numbers are also displayed (per patients).

tabTOX_arm function


tabae3 <- tabTOX_arm(df, "OBS", var="tox", var_cat="cat_tox", var_grade="grade",
                     arm="ARM", grade_filter = 3,
                     percent="%", latex=FALSE, langue='en',
                     var_name="AE", total="All", n=c(n_pat/2,n_pat/2))
AE A B
Any grade >= Grade 3 Any grade >= Grade 3
All 49 (98%) 27 (54%) 48 (96%) 31 (62%)
cat 3 35 (70%) 13 (26%) 37 (74%) 14 (28%)
- tox 1 23 (46%) 9 (18%) 28 (56%) 9 (18%)
- tox 2 21 (42%) 4 (8%) 19 (38%) 5 (10%)
cat 2 34 (68%) 10 (20%) 28 (56%) 16 (32%)
- tox 1 21 (42%) 5 (10%) 18 (36%) 8 (16%)
- tox 2 20 (40%) 5 (10%) 17 (34%) 11 (22%)
cat 1 29 (58%) 11 (22%) 24 (48%) 10 (20%)
- tox 2 20 (40%) 7 (14%) 16 (32%) 6 (12%)
- tox 1 14 (28%) 5 (10%) 15 (30%) 6 (12%)

plotTOX function


Here is an example of adverse events visualization for two groups comparison without the optional arguments:

tabae4 <- plotTOX(baz=df, id="OBS", var="tox_bis",
                  n=c(n_pat/2,n_pat/2), arm="ARM", langue="en")
tabae4$plot

We can:

tabae5 <- plotTOX(baz=df, id="OBS", var="tox_bis",
                  n=c(n_pat/2,n_pat/2), arm="ARM", langue="en",
                  percent_supp=15, favors=c("Favor B", "Favor A"),
                  y_favors_arrow=-0.1, y_favors_text=-0.3)
tabae5$plot

tabae6 <- plotTOX(baz=df_bis, id="OBS", var="tox_bis",
                  n=c(n_pat/2,n_pat/2), arm="ARM", langue="en",
                  y_favors_arrow=0, y_favors_text=-0.1)
tabae6$plot




Contact

This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Developed and updated by Noémie Bigot and Anouk Walter-Petrich
noemie.bigot@aphp.fr; anouk.walter-petrich@u-paris.fr

Based on The R Graph Gallery by Yan Holtz.

SBIM