Data & Functions
Adverse Event


Data


We load the packages we will use :

# Libraries
library(tidyverse)
library(ggplot2)


We create databases :

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')



#Head of dataset
knitr::kable(head(df,8), align = "l")
OBS cat_tox tox tox_bis grade ARM
2 cat 2 tox 1 tox 7 1 A
2 cat 2 tox 1 tox 7 2 A
2 cat 2 tox 2 tox 10 1 A
3 cat 2 tox 2 tox 13 2 A
3 cat 3 tox 2 tox 11 1 A
3 cat 3 tox 1 tox 14 2 A
3 cat 2 tox 1 tox 5 5 A
4 cat 1 tox 1 tox 18 3 A



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))



#Head of dataset
knitr::kable(head(df_bis,8), align = "l")
NAME N ARM
tox 1 49 A
tox 1 38 B
tox 2 30 A
tox 2 21 B
tox 3 9 A
tox 3 8 B
tox 4 15 A
tox 4 7 B



Download functions


Last update date : 23/08/2024

Download Tox_functions.R

tabTOX function


This function is used to create a table from a database with adverse events (multiple lines per patient) to represent number of patients affected by toxicity.


tabTOX(
baz, database of toxicity (one line per toxicity).
id, patient identifier variable.
var, variable toxicity/treatment/….
var_cat, variable toxicity/treatment category/… (optional).
var_grade, variable with toxicity grade (optional).
grade_max=TRUE, only the maximal grade per toxicity/toxicity category is taken into account if TRUE, all grades of the same toxicity are counted if FALSE.
var_name, name of the column to be displayed in the table, by default var variable name (optional).
all=TRUE, to display the number of toxicity in all grades.
addNA=TRUE, to display toxicity with missing grade, if FALSE missing grades are taken into account in the Total column.
decreasing=TRUE, to sort by most represented toxicities/treatments.
percent="$\\%$", how to display percent.
langue="fr", language (fr or en).
latex=TRUE, latex table option, bold lines and indentations.
total="Total", to add an extra line at the top of the table, all toxicities combined.
)

plotTOX function


This function allows to draw a representation of adverse events for two groups comparison. A database with adverse events (multiple lines per patient) can be given (use of tabTOX() in the function), or directly a dataframe with three variables (NAME indicates the type of toxicity, N the number of patients affected by the toxicity and the last one the group for which the name can be given in the argument arm of the function).

The function returns two objects data and plot which contain respectively a table with the number of patients concerned by toxicity per arm (with the RR and its 95%CI) and an associated graph.


plotTOX(
baz, database of toxicity (one line per toxicity) or dataframe with three variables giving directly the number of toxicities per patient and per arm.
id, patient identifier variable (necessary only if all database of adverse events is given).
var, variable toxicity/treatment/… (necessary only if all database of adverse events is given).
n, vector giving the number of patients in each arm (vector of size 2 with same order of arm levels).
arm, variable indicating arm.
arm_levels, arm labels (optional, vector of size 2 with same order of arm levels).
percent_supp=0, percentage below which the toxicity is not displayed.
favors, vector with the names to display below axis for directional difference (optional).
y_arrow=0.2, coordinate for favors arrows.
y_lab=-0.1, coordinate for favors labels.
langue="fr", language (fr or en).
name_file, path and name of the file (pdf, png or tiff) in which we want to save the forest plot (optional).
dim_file, size 2 vector to specify the width and height of the graphic when we want to save it (optional).
)




Contact

This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Based on The R Graph Gallery by Yan Holtz.