pharmaverse examples
  1. TLG
  2. Adverse Events
  • Introduction

  • SDTM
    • SDTM Examples
  • ADaM
    • ADSL
    • ADPC
    • ADPPK
    • ADRS
    • ADTTE
    • ADVS
    • ADAE
  • TLG
    • Demographic Table
    • Adverse Events
    • Pharmacokinetic
  • Interactive
    • teal applications
  • Logs
    • The Difference Between logr, logrx, and whirl
  • eSubmission
    • eSubmission

  • Session Info
  • Pharmaverse Home
  1. TLG
  2. Adverse Events

Adverse Events

Introduction

This guide will show you how pharmaverse packages, along with some from tidyverse, can be used to create an Adverse Events table, using the {pharmaverseadam} ADSL and ADAE data as an input.

The packages used with a brief description of their purpose are as follows:

  • {rtables}: designed to create and display complex tables with R.
  • {tern}: contains analysis functions to create tables and graphs used for clinical trial reporting.

Load Data and Required pharmaverse Package

After installation of packages, the first step is to load our pharmaverse packages and input data. Here, we are going to encode missing entries in a data frame adsl and adae.

Note that {tern} depends on {rtables} so the latter is automatically attached.

library(pharmaverseadam)
library(tern)
library(dplyr)

adsl <- adsl %>%
  df_explicit_na()

adae <- adae %>%
  df_explicit_na()

Start preprocessing

Now we will add some pre-processing to add labels ready for display in the table and how the output will be split.

adae <- adae %>%
  var_relabel(
    AEBODSYS = "MedDRA System Organ Class",
    AEDECOD = "MedDRA Preferred Term"
  ) %>%
  filter(SAFFL == "Y")

# Define the split function
split_fun <- drop_split_levels

Adverse Events table

Now we create the Adverse Events table.

lyt <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by(var = "ACTARM") %>%
  add_overall_col(label = "All Patients") %>%
  analyze_num_patients(
    vars = "USUBJID",
    .stats = c("unique", "nonunique"),
    .labels = c(
      unique = "Total number of patients with at least one adverse event",
      nonunique = "Overall total number of events"
    )
  ) %>%
  split_rows_by(
    "AEBODSYS",
    child_labels = "visible",
    nested = FALSE,
    split_fun = split_fun,
    label_pos = "topleft",
    split_label = obj_label(adae$AEBODSYS)
  ) %>%
  summarize_num_patients(
    var = "USUBJID",
    .stats = c("unique", "nonunique"),
    .labels = c(
      unique = "Total number of patients with at least one adverse event",
      nonunique = "Total number of events"
    )
  ) %>%
  count_occurrences(
    vars = "AEDECOD",
    .indent_mods = -1L
  ) %>%
  append_varlabels(adae, "AEDECOD", indent = 1L)

result <- build_table(lyt, df = adae, alt_counts_df = adsl)

result
MedDRA System Organ Class                                              Placebo     Xanomeline High Dose   Xanomeline Low Dose   All Patients
  MedDRA Preferred Term                                                 (N=86)            (N=72)                (N=96)            (N=306)   
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one adverse event              69 (80.2%)        70 (97.2%)            86 (89.6%)        225 (73.5%) 
Overall total number of events                                           301               436                    454               1191    
CARDIAC DISORDERS                                                                                                                           
  Total number of patients with at least one adverse event            13 (15.1%)        15 (20.8%)            16 (16.7%)         44 (14.4%) 
  Total number of events                                                  27                30                    34                 91     
  ATRIAL FIBRILLATION                                                  1 (1.2%)          2 (2.8%)              2 (2.1%)           5 (1.6%)  
  ATRIAL FLUTTER                                                          0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  ATRIAL HYPERTROPHY                                                   1 (1.2%)             0                      0              1 (0.3%)  
  ATRIOVENTRICULAR BLOCK FIRST DEGREE                                  1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  ATRIOVENTRICULAR BLOCK SECOND DEGREE                                 2 (2.3%)          1 (1.4%)              2 (2.1%)           5 (1.6%)  
  BRADYCARDIA                                                          1 (1.2%)             0                      0              1 (0.3%)  
  BUNDLE BRANCH BLOCK LEFT                                             1 (1.2%)             0                      0              1 (0.3%)  
  BUNDLE BRANCH BLOCK RIGHT                                            1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  CARDIAC DISORDER                                                        0              1 (1.4%)                  0              1 (0.3%)  
  CARDIAC FAILURE CONGESTIVE                                           1 (1.2%)             0                      0              1 (0.3%)  
  MYOCARDIAL INFARCTION                                                4 (4.7%)          4 (5.6%)              2 (2.1%)          10 (3.3%)  
  PALPITATIONS                                                            0                 0                  2 (2.1%)           2 (0.7%)  
  SINUS ARRHYTHMIA                                                     1 (1.2%)             0                      0              1 (0.3%)  
  SINUS BRADYCARDIA                                                    2 (2.3%)         8 (11.1%)              7 (7.3%)          17 (5.6%)  
  SUPRAVENTRICULAR EXTRASYSTOLES                                       1 (1.2%)          1 (1.4%)              1 (1.0%)           3 (1.0%)  
  SUPRAVENTRICULAR TACHYCARDIA                                            0                 0                  1 (1.0%)           1 (0.3%)  
  TACHYCARDIA                                                          1 (1.2%)             0                      0              1 (0.3%)  
  VENTRICULAR EXTRASYSTOLES                                               0              1 (1.4%)              2 (2.1%)           3 (1.0%)  
  VENTRICULAR HYPERTROPHY                                              1 (1.2%)             0                      0              1 (0.3%)  
  WOLFF-PARKINSON-WHITE SYNDROME                                          0                 0                  1 (1.0%)           1 (0.3%)  
CONGENITAL, FAMILIAL AND GENETIC DISORDERS                                                                                                  
  Total number of patients with at least one adverse event                0              2 (2.8%)              1 (1.0%)           3 (1.0%)  
  Total number of events                                                  0                 2                      1                 3      
  VENTRICULAR SEPTAL DEFECT                                               0              2 (2.8%)              1 (1.0%)           3 (1.0%)  
EAR AND LABYRINTH DISORDERS                                                                                                                 
  Total number of patients with at least one adverse event             1 (1.2%)          1 (1.4%)              2 (2.1%)           4 (1.3%)  
  Total number of events                                                  2                 1                      3                 6      
  CERUMEN IMPACTION                                                       0                 0                  1 (1.0%)           1 (0.3%)  
  EAR PAIN                                                             1 (1.2%)             0                      0              1 (0.3%)  
  TINNITUS                                                                0                 0                  1 (1.0%)           1 (0.3%)  
  VERTIGO                                                                 0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
EYE DISORDERS                                                                                                                               
  Total number of patients with at least one adverse event             4 (4.7%)          1 (1.4%)              2 (2.1%)           7 (2.3%)  
  Total number of events                                                  8                 2                      2                 12     
  CONJUNCTIVAL HAEMORRHAGE                                                0                 0                  1 (1.0%)           1 (0.3%)  
  CONJUNCTIVITIS                                                       2 (2.3%)             0                      0              2 (0.7%)  
  EYE ALLERGY                                                          1 (1.2%)             0                      0              1 (0.3%)  
  EYE PRURITUS                                                         1 (1.2%)             0                      0              1 (0.3%)  
  EYE SWELLING                                                         1 (1.2%)             0                      0              1 (0.3%)  
  GLAUCOMA                                                             1 (1.2%)             0                      0              1 (0.3%)  
  VISION BLURRED                                                          0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
GASTROINTESTINAL DISORDERS                                                                                                                  
  Total number of patients with at least one adverse event            17 (19.8%)        20 (27.8%)            16 (16.7%)         53 (17.3%) 
  Total number of events                                                  26                35                    26                 87     
  ABDOMINAL DISCOMFORT                                                    0              1 (1.4%)                  0              1 (0.3%)  
  ABDOMINAL PAIN                                                       1 (1.2%)          1 (1.4%)              3 (3.1%)           5 (1.6%)  
  CONSTIPATION                                                         1 (1.2%)             0                      0              1 (0.3%)  
  DIARRHOEA                                                           9 (10.5%)          3 (4.2%)              6 (6.2%)          18 (5.9%)  
  DYSPEPSIA                                                            1 (1.2%)          1 (1.4%)              1 (1.0%)           3 (1.0%)  
  DYSPHAGIA                                                               0                 0                  1 (1.0%)           1 (0.3%)  
  FLATULENCE                                                           1 (1.2%)             0                      0              1 (0.3%)  
  GASTROINTESTINAL HAEMORRHAGE                                            0              1 (1.4%)                  0              1 (0.3%)  
  GASTROOESOPHAGEAL REFLUX DISEASE                                     1 (1.2%)             0                      0              1 (0.3%)  
  GLOSSITIS                                                            1 (1.2%)             0                      0              1 (0.3%)  
  HIATUS HERNIA                                                        1 (1.2%)             0                      0              1 (0.3%)  
  NAUSEA                                                               3 (3.5%)          6 (8.3%)              3 (3.1%)          12 (3.9%)  
  RECTAL HAEMORRHAGE                                                      0                 0                  1 (1.0%)           1 (0.3%)  
  SALIVARY HYPERSECRETION                                                 0              4 (5.6%)                  0              4 (1.3%)  
  STOMACH DISCOMFORT                                                      0              1 (1.4%)                  0              1 (0.3%)  
  VOMITING                                                             3 (3.5%)          6 (8.3%)              4 (4.2%)          13 (4.2%)  
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS                                                                                        
  Total number of patients with at least one adverse event            21 (24.4%)        36 (50.0%)            51 (53.1%)        108 (35.3%) 
  Total number of events                                                  48               118                    126               292     
  APPLICATION SITE BLEEDING                                               0                 0                  1 (1.0%)           1 (0.3%)  
  APPLICATION SITE DERMATITIS                                          5 (5.8%)          7 (9.7%)              9 (9.4%)          21 (6.9%)  
  APPLICATION SITE DESQUAMATION                                           0                 0                  1 (1.0%)           1 (0.3%)  
  APPLICATION SITE DISCHARGE                                              0              1 (1.4%)                  0              1 (0.3%)  
  APPLICATION SITE DISCOLOURATION                                         0                 0                  1 (1.0%)           1 (0.3%)  
  APPLICATION SITE ERYTHEMA                                            3 (3.5%)         14 (19.4%)            13 (13.5%)         30 (9.8%)  
  APPLICATION SITE INDURATION                                          1 (1.2%)             0                      0              1 (0.3%)  
  APPLICATION SITE IRRITATION                                          3 (3.5%)         9 (12.5%)              9 (9.4%)          21 (6.9%)  
  APPLICATION SITE PAIN                                                   0              2 (2.8%)                  0              2 (0.7%)  
  APPLICATION SITE PERSPIRATION                                           0              2 (2.8%)                  0              2 (0.7%)  
  APPLICATION SITE PRURITUS                                            6 (7.0%)         21 (29.2%)            23 (24.0%)         50 (16.3%) 
  APPLICATION SITE REACTION                                            1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  APPLICATION SITE SWELLING                                               0              2 (2.8%)              1 (1.0%)           3 (1.0%)  
  APPLICATION SITE URTICARIA                                              0              1 (1.4%)              2 (2.1%)           3 (1.0%)  
  APPLICATION SITE VESICLES                                            1 (1.2%)          5 (6.9%)              5 (5.2%)          11 (3.6%)  
  APPLICATION SITE WARMTH                                                 0                 0                  1 (1.0%)           1 (0.3%)  
  ASTHENIA                                                             1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  CHEST DISCOMFORT                                                        0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  CHEST PAIN                                                              0              2 (2.8%)                  0              2 (0.7%)  
  CHILLS                                                               1 (1.2%)          1 (1.4%)              1 (1.0%)           3 (1.0%)  
  CYST                                                                    0                 0                  1 (1.0%)           1 (0.3%)  
  FATIGUE                                                              1 (1.2%)          5 (6.9%)              5 (5.2%)          11 (3.6%)  
  FEELING ABNORMAL                                                        0              1 (1.4%)                  0              1 (0.3%)  
  FEELING COLD                                                            0              1 (1.4%)                  0              1 (0.3%)  
  INFLAMMATION                                                            0                 0                  1 (1.0%)           1 (0.3%)  
  MALAISE                                                                 0              2 (2.8%)              1 (1.0%)           3 (1.0%)  
  OEDEMA                                                                  0                 0                  2 (2.1%)           2 (0.7%)  
  OEDEMA PERIPHERAL                                                    2 (2.3%)          2 (2.8%)              1 (1.0%)           5 (1.6%)  
  PAIN                                                                    0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  PYREXIA                                                              2 (2.3%)             0                  1 (1.0%)           3 (1.0%)  
  SECRETION DISCHARGE                                                     0                 0                  1 (1.0%)           1 (0.3%)  
  SUDDEN DEATH                                                            0                 0                  1 (1.0%)           1 (0.3%)  
  SWELLING                                                                0                 0                  1 (1.0%)           1 (0.3%)  
  ULCER                                                                   0                 0                  1 (1.0%)           1 (0.3%)  
HEPATOBILIARY DISORDERS                                                                                                                     
  Total number of patients with at least one adverse event             1 (1.2%)             0                      0              1 (0.3%)  
  Total number of events                                                  1                 0                      0                 1      
  HYPERBILIRUBINAEMIA                                                  1 (1.2%)             0                      0              1 (0.3%)  
IMMUNE SYSTEM DISORDERS                                                                                                                     
  Total number of patients with at least one adverse event                0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  Total number of events                                                  0                 1                      2                 3      
  HYPERSENSITIVITY                                                        0                 0                  1 (1.0%)           1 (0.3%)  
  SEASONAL ALLERGY                                                        0              1 (1.4%)                  0              1 (0.3%)  
INFECTIONS AND INFESTATIONS                                                                                                                 
  Total number of patients with at least one adverse event            16 (18.6%)        13 (18.1%)            10 (10.4%)         39 (12.7%) 
  Total number of events                                                  35                20                    18                 73     
  BRONCHITIS                                                           1 (1.2%)             0                      0              1 (0.3%)  
  CELLULITIS                                                              0                 0                  1 (1.0%)           1 (0.3%)  
  CERVICITIS                                                           1 (1.2%)             0                      0              1 (0.3%)  
  CYSTITIS                                                             1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  EAR INFECTION                                                        2 (2.3%)             0                      0              2 (0.7%)  
  GASTROENTERITIS VIRAL                                                1 (1.2%)             0                      0              1 (0.3%)  
  HORDEOLUM                                                               0              1 (1.4%)                  0              1 (0.3%)  
  INFLUENZA                                                            1 (1.2%)          1 (1.4%)              1 (1.0%)           3 (1.0%)  
  LOCALISED INFECTION                                                  1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  LOWER RESPIRATORY TRACT INFECTION                                       0              1 (1.4%)                  0              1 (0.3%)  
  NASOPHARYNGITIS                                                      2 (2.3%)          6 (8.3%)              4 (4.2%)          12 (3.9%)  
  ONYCHOMYCOSIS                                                           0                 0                  1 (1.0%)           1 (0.3%)  
  PNEUMONIA                                                               0                 0                  1 (1.0%)           1 (0.3%)  
  RHINITIS                                                                0              1 (1.4%)                  0              1 (0.3%)  
  UPPER RESPIRATORY TRACT INFECTION                                    6 (7.0%)          3 (4.2%)              1 (1.0%)          10 (3.3%)  
  URINARY TRACT INFECTION                                              2 (2.3%)          1 (1.4%)                  0              3 (1.0%)  
  VAGINAL MYCOSIS                                                      1 (1.2%)             0                      0              1 (0.3%)  
  VIRAL INFECTION                                                         0                 0                  1 (1.0%)           1 (0.3%)  
INJURY, POISONING AND PROCEDURAL COMPLICATIONS                                                                                              
  Total number of patients with at least one adverse event             4 (4.7%)          5 (6.9%)              5 (5.2%)          14 (4.6%)  
  Total number of events                                                  9                 8                     12                 29     
  CONTUSION                                                            1 (1.2%)          2 (2.8%)              1 (1.0%)           4 (1.3%)  
  EXCORIATION                                                          2 (2.3%)          1 (1.4%)              1 (1.0%)           4 (1.3%)  
  FACIAL BONES FRACTURE                                                   0              1 (1.4%)                  0              1 (0.3%)  
  FALL                                                                 1 (1.2%)          1 (1.4%)              2 (2.1%)           4 (1.3%)  
  HIP FRACTURE                                                         1 (1.2%)          2 (2.8%)                  0              3 (1.0%)  
  JOINT DISLOCATION                                                       0                 0                  1 (1.0%)           1 (0.3%)  
  SKIN LACERATION                                                      1 (1.2%)             0                  2 (2.1%)           3 (1.0%)  
  WOUND                                                                   0                 0                  1 (1.0%)           1 (0.3%)  
INVESTIGATIONS                                                                                                                              
  Total number of patients with at least one adverse event            10 (11.6%)         5 (6.9%)              8 (8.3%)          23 (7.5%)  
  Total number of events                                                  19                6                     15                 40     
  BIOPSY                                                                  0              1 (1.4%)                  0              1 (0.3%)  
  BIOPSY PROSTATE                                                         0              1 (1.4%)                  0              1 (0.3%)  
  BLOOD ALKALINE PHOSPHATASE INCREASED                                 1 (1.2%)             0                      0              1 (0.3%)  
  BLOOD CHOLESTEROL INCREASED                                             0              1 (1.4%)                  0              1 (0.3%)  
  BLOOD CREATINE PHOSPHOKINASE INCREASED                               1 (1.2%)             0                      0              1 (0.3%)  
  BLOOD GLUCOSE INCREASED                                                 0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  BLOOD URINE PRESENT                                                  1 (1.2%)             0                      0              1 (0.3%)  
  BODY TEMPERATURE INCREASED                                              0                 0                  1 (1.0%)           1 (0.3%)  
  CYSTOSCOPY                                                           1 (1.2%)             0                      0              1 (0.3%)  
  ELECTROCARDIOGRAM ST SEGMENT DEPRESSION                              4 (4.7%)             0                  1 (1.0%)           5 (1.6%)  
  ELECTROCARDIOGRAM T WAVE AMPLITUDE DECREASED                         1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  ELECTROCARDIOGRAM T WAVE INVERSION                                   2 (2.3%)          1 (1.4%)              1 (1.0%)           4 (1.3%)  
  HEART RATE INCREASED                                                 1 (1.2%)             0                      0              1 (0.3%)  
  HEART RATE IRREGULAR                                                 1 (1.2%)             0                      0              1 (0.3%)  
  NASAL MUCOSA BIOPSY                                                     0                 0                  1 (1.0%)           1 (0.3%)  
  NEUTROPHIL COUNT INCREASED                                              0                 0                  1 (1.0%)           1 (0.3%)  
  URINE ANALYSIS ABNORMAL                                                 0                 0                  1 (1.0%)           1 (0.3%)  
  WEIGHT DECREASED                                                        0                 0                  1 (1.0%)           1 (0.3%)  
  WHITE BLOOD CELL COUNT INCREASED                                        0                 0                  1 (1.0%)           1 (0.3%)  
METABOLISM AND NUTRITION DISORDERS                                                                                                          
  Total number of patients with at least one adverse event             6 (7.0%)          3 (4.2%)              1 (1.0%)          10 (3.3%)  
  Total number of events                                                  8                 5                      1                 14     
  DECREASED APPETITE                                                   1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  DEHYDRATION                                                          1 (1.2%)             0                      0              1 (0.3%)  
  DIABETES MELLITUS                                                    1 (1.2%)             0                      0              1 (0.3%)  
  FOOD CRAVING                                                         1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  HYPERCHOLESTEROLAEMIA                                                   0              1 (1.4%)                  0              1 (0.3%)  
  HYPONATRAEMIA                                                        1 (1.2%)             0                      0              1 (0.3%)  
  INCREASED APPETITE                                                   1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
MUSCULOSKELETAL AND CONNECTIVE TISSUE DISORDERS                                                                                             
  Total number of patients with at least one adverse event             5 (5.8%)         8 (11.1%)              7 (7.3%)          20 (6.5%)  
  Total number of events                                                  8                 11                    10                 29     
  ARTHRALGIA                                                           1 (1.2%)          1 (1.4%)              2 (2.1%)           4 (1.3%)  
  ARTHRITIS                                                            1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  BACK PAIN                                                            1 (1.2%)          3 (4.2%)              1 (1.0%)           5 (1.6%)  
  FLANK PAIN                                                              0              2 (2.8%)                  0              2 (0.7%)  
  MUSCLE SPASMS                                                           0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  MUSCULAR WEAKNESS                                                       0                 0                  1 (1.0%)           1 (0.3%)  
  MYALGIA                                                                 0              1 (1.4%)                  0              1 (0.3%)  
  PAIN IN EXTREMITY                                                    1 (1.2%)             0                      0              1 (0.3%)  
  SHOULDER PAIN                                                        1 (1.2%)             0                  2 (2.1%)           3 (1.0%)  
NEOPLASMS BENIGN, MALIGNANT AND UNSPECIFIED (INCL CYSTS AND POLYPS)                                                                         
  Total number of patients with at least one adverse event                0              1 (1.4%)              2 (2.1%)           3 (1.0%)  
  Total number of events                                                  0                 1                      3                 4      
  COLON CANCER                                                            0                 0                  1 (1.0%)           1 (0.3%)  
  MALIGNANT FIBROUS HISTIOCYTOMA                                          0                 0                  1 (1.0%)           1 (0.3%)  
  PROSTATE CANCER                                                         0              1 (1.4%)                  0              1 (0.3%)  
NERVOUS SYSTEM DISORDERS                                                                                                                    
  Total number of patients with at least one adverse event            12 (14.0%)        25 (34.7%)            22 (22.9%)         59 (19.3%) 
  Total number of events                                                  16                43                    42                101     
  AMNESIA                                                                 0              1 (1.4%)                  0              1 (0.3%)  
  BALANCE DISORDER                                                        0                 0                  1 (1.0%)           1 (0.3%)  
  BURNING SENSATION                                                       0              2 (2.8%)                  0              2 (0.7%)  
  COGNITIVE DISORDER                                                      0              1 (1.4%)                  0              1 (0.3%)  
  COMPLEX PARTIAL SEIZURES                                                0                 0                  1 (1.0%)           1 (0.3%)  
  COORDINATION ABNORMAL                                                   0                 0                  1 (1.0%)           1 (0.3%)  
  DIZZINESS                                                            2 (2.3%)         11 (15.3%)             9 (9.4%)          22 (7.2%)  
  HEADACHE                                                             7 (8.1%)          6 (8.3%)              3 (3.1%)          16 (5.2%)  
  HEMIANOPIA HOMONYMOUS                                                   0                 0                  1 (1.0%)           1 (0.3%)  
  HYPERSOMNIA                                                             0              1 (1.4%)                  0              1 (0.3%)  
  LETHARGY                                                                0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  PARAESTHESIA                                                            0              1 (1.4%)                  0              1 (0.3%)  
  PARAESTHESIA ORAL                                                       0                 0                  1 (1.0%)           1 (0.3%)  
  PARKINSON'S DISEASE                                                  1 (1.2%)             0                      0              1 (0.3%)  
  PAROSMIA                                                                0              1 (1.4%)                  0              1 (0.3%)  
  PARTIAL SEIZURES WITH SECONDARY GENERALISATION                          0              1 (1.4%)                  0              1 (0.3%)  
  PSYCHOMOTOR HYPERACTIVITY                                            1 (1.2%)             0                      0              1 (0.3%)  
  SOMNOLENCE                                                           2 (2.3%)          1 (1.4%)              3 (3.1%)           6 (2.0%)  
  STUPOR                                                                  0                 0                  1 (1.0%)           1 (0.3%)  
  SYNCOPE                                                                 0              2 (2.8%)              5 (5.2%)           7 (2.3%)  
  SYNCOPE VASOVAGAL                                                       0              1 (1.4%)                  0              1 (0.3%)  
  TRANSIENT ISCHAEMIC ATTACK                                              0              1 (1.4%)              2 (2.1%)           3 (1.0%)  
PSYCHIATRIC DISORDERS                                                                                                                       
  Total number of patients with at least one adverse event            10 (11.6%)        8 (11.1%)             11 (11.5%)         29 (9.5%)  
  Total number of events                                                  14                11                    15                 40     
  AGITATION                                                            2 (2.3%)             0                  3 (3.1%)           5 (1.6%)  
  ANXIETY                                                              1 (1.2%)             0                  3 (3.1%)           4 (1.3%)  
  COMPLETED SUICIDE                                                    1 (1.2%)             0                      0              1 (0.3%)  
  CONFUSIONAL STATE                                                    2 (2.3%)          1 (1.4%)              3 (3.1%)           6 (2.0%)  
  DELIRIUM                                                                0              1 (1.4%)                  0              1 (0.3%)  
  DELUSION                                                             1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  DEPRESSED MOOD                                                          0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  DISORIENTATION                                                       1 (1.2%)             0                      0              1 (0.3%)  
  HALLUCINATION                                                           0              1 (1.4%)                  0              1 (0.3%)  
  HALLUCINATION, VISUAL                                                   0              1 (1.4%)                  0              1 (0.3%)  
  INSOMNIA                                                             2 (2.3%)          2 (2.8%)                  0              4 (1.3%)  
  IRRITABILITY                                                         1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  LIBIDO DECREASED                                                        0              1 (1.4%)                  0              1 (0.3%)  
  LISTLESS                                                                0              1 (1.4%)                  0              1 (0.3%)  
  NIGHTMARE                                                               0              1 (1.4%)                  0              1 (0.3%)  
  RESTLESSNESS                                                            0                 0                  1 (1.0%)           1 (0.3%)  
RENAL AND URINARY DISORDERS                                                                                                                 
  Total number of patients with at least one adverse event             4 (4.7%)          3 (4.2%)              4 (4.2%)          11 (3.6%)  
  Total number of events                                                  5                 4                      4                 13     
  CALCULUS URETHRAL                                                       0              1 (1.4%)                  0              1 (0.3%)  
  DYSURIA                                                              1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  ENURESIS                                                                0                 0                  1 (1.0%)           1 (0.3%)  
  INCONTINENCE                                                            0                 0                  1 (1.0%)           1 (0.3%)  
  MICTURITION URGENCY                                                  1 (1.2%)          1 (1.4%)              1 (1.0%)           3 (1.0%)  
  NEPHROLITHIASIS                                                      1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  POLLAKIURIA                                                          1 (1.2%)             0                      0              1 (0.3%)  
REPRODUCTIVE SYSTEM AND BREAST DISORDERS                                                                                                    
  Total number of patients with at least one adverse event             2 (2.3%)          1 (1.4%)                  0              3 (1.0%)  
  Total number of events                                                  4                 1                      0                 5      
  BENIGN PROSTATIC HYPERPLASIA                                         1 (1.2%)          1 (1.4%)                  0              2 (0.7%)  
  PELVIC PAIN                                                          1 (1.2%)             0                      0              1 (0.3%)  
RESPIRATORY, THORACIC AND MEDIASTINAL DISORDERS                                                                                             
  Total number of patients with at least one adverse event            10 (11.6%)        10 (13.9%)            10 (10.4%)         30 (9.8%)  
  Total number of events                                                  15                22                    16                 53     
  ALLERGIC GRANULOMATOUS ANGIITIS                                         0              1 (1.4%)                  0              1 (0.3%)  
  COUGH                                                                3 (3.5%)          5 (6.9%)              6 (6.2%)          14 (4.6%)  
  DYSPHONIA                                                               0                 0                  1 (1.0%)           1 (0.3%)  
  DYSPNOEA                                                             1 (1.2%)          1 (1.4%)              1 (1.0%)           3 (1.0%)  
  EMPHYSEMA                                                            1 (1.2%)             0                      0              1 (0.3%)  
  EPISTAXIS                                                               0              2 (2.8%)              1 (1.0%)           3 (1.0%)  
  HAEMOPTYSIS                                                          1 (1.2%)             0                      0              1 (0.3%)  
  NASAL CONGESTION                                                     3 (3.5%)          3 (4.2%)              1 (1.0%)           7 (2.3%)  
  PHARYNGEAL ERYTHEMA                                                     0              1 (1.4%)                  0              1 (0.3%)  
  PHARYNGOLARYNGEAL PAIN                                                  0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  POSTNASAL DRIP                                                       1 (1.2%)             0                      0              1 (0.3%)  
  PRODUCTIVE COUGH                                                        0              1 (1.4%)                  0              1 (0.3%)  
  RALES                                                                1 (1.2%)             0                      0              1 (0.3%)  
  RESPIRATORY TRACT CONGESTION                                            0              1 (1.4%)                  0              1 (0.3%)  
  RHINORRHOEA                                                             0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
SKIN AND SUBCUTANEOUS TISSUE DISORDERS                                                                                                      
  Total number of patients with at least one adverse event            21 (24.4%)        42 (58.3%)            42 (43.8%)        105 (34.3%) 
  Total number of events                                                  47               111                    118               276     
  ACTINIC KERATOSIS                                                       0              1 (1.4%)                  0              1 (0.3%)  
  ALOPECIA                                                             1 (1.2%)             0                      0              1 (0.3%)  
  BLISTER                                                                 0              1 (1.4%)              5 (5.2%)           6 (2.0%)  
  COLD SWEAT                                                           1 (1.2%)             0                      0              1 (0.3%)  
  DERMATITIS ATOPIC                                                    1 (1.2%)             0                      0              1 (0.3%)  
  DERMATITIS CONTACT                                                      0                 0                  1 (1.0%)           1 (0.3%)  
  DRUG ERUPTION                                                        1 (1.2%)             0                      0              1 (0.3%)  
  ERYTHEMA                                                            9 (10.5%)         14 (19.4%)            15 (15.6%)         38 (12.4%) 
  HYPERHIDROSIS                                                        2 (2.3%)         8 (11.1%)              4 (4.2%)          14 (4.6%)  
  PRURITUS                                                             8 (9.3%)         26 (36.1%)            23 (24.0%)         57 (18.6%) 
  PRURITUS GENERALISED                                                    0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
  RASH                                                                 5 (5.8%)         11 (15.3%)            13 (13.5%)         29 (9.5%)  
  RASH ERYTHEMATOUS                                                       0                 0                  2 (2.1%)           2 (0.7%)  
  RASH MACULO-PAPULAR                                                     0              1 (1.4%)                  0              1 (0.3%)  
  RASH PAPULAR                                                            0              1 (1.4%)                  0              1 (0.3%)  
  RASH PRURITIC                                                           0              2 (2.8%)              1 (1.0%)           3 (1.0%)  
  SKIN EXFOLIATION                                                        0                 0                  1 (1.0%)           1 (0.3%)  
  SKIN IRRITATION                                                      3 (3.5%)          5 (6.9%)              6 (6.2%)          14 (4.6%)  
  SKIN ODOUR ABNORMAL                                                     0              1 (1.4%)                  0              1 (0.3%)  
  SKIN ULCER                                                           1 (1.2%)             0                      0              1 (0.3%)  
  URTICARIA                                                               0              1 (1.4%)              1 (1.0%)           2 (0.7%)  
SOCIAL CIRCUMSTANCES                                                                                                                        
  Total number of patients with at least one adverse event                0              1 (1.4%)                  0              1 (0.3%)  
  Total number of events                                                  0                 1                      0                 1      
  ALCOHOL USE                                                             0              1 (1.4%)                  0              1 (0.3%)  
SURGICAL AND MEDICAL PROCEDURES                                                                                                             
  Total number of patients with at least one adverse event             2 (2.3%)          2 (2.8%)              1 (1.0%)           5 (1.6%)  
  Total number of events                                                  2                 2                      1                 5      
  ACROCHORDON EXCISION                                                    0              1 (1.4%)                  0              1 (0.3%)  
  CATARACT OPERATION                                                   1 (1.2%)             0                  1 (1.0%)           2 (0.7%)  
  EYE LASER SURGERY                                                    1 (1.2%)             0                      0              1 (0.3%)  
  SKIN LESION EXCISION                                                    0              1 (1.4%)                  0              1 (0.3%)  
VASCULAR DISORDERS                                                                                                                          
  Total number of patients with at least one adverse event             3 (3.5%)          1 (1.4%)              4 (4.2%)           8 (2.6%)  
  Total number of events                                                  7                 1                      5                 13     
  HOT FLUSH                                                               0                 0                  1 (1.0%)           1 (0.3%)  
  HYPERTENSION                                                         1 (1.2%)             0                  2 (2.1%)           3 (1.0%)  
  HYPOTENSION                                                          2 (2.3%)             0                  1 (1.0%)           3 (1.0%)  
  ORTHOSTATIC HYPOTENSION                                              1 (1.2%)             0                      0              1 (0.3%)  
  WOUND HAEMORRHAGE                                                       0              1 (1.4%)                  0              1 (0.3%)  
Demographic Table
Pharmacokinetic
Source Code
---
title: "Adverse Events"
order: 2
---


```{r setup script, include=FALSE, purl=FALSE}
invisible_hook_purl <- function(before, options, ...) {knitr::hook_purl(before, options, ...); NULL}
knitr::knit_hooks$set(purl = invisible_hook_purl)
```

## Introduction

This guide will show you how pharmaverse packages, along with some from tidyverse, can be used to create an Adverse Events table, using the `{pharmaverseadam}` `ADSL` and `ADAE` data as an input.

The packages used with a brief description of their purpose are as follows:

* [`{rtables}`](https://insightsengineering.github.io/rtables/): designed to create and display complex tables with R.
* [`{tern}`](https://insightsengineering.github.io/tern/): contains analysis functions to create tables and graphs used for clinical trial reporting.

## Load Data and Required pharmaverse Package

After installation of packages, the first step is to load our pharmaverse packages and input data. Here, we are going to encode missing entries in a data frame `adsl` and `adae`.

Note that `{tern}` depends on `{rtables}` so the latter is automatically attached.

```{r setup, message=FALSE, warning=FALSE, results='hold'}
library(pharmaverseadam)
library(tern)
library(dplyr)

adsl <- adsl %>%
  df_explicit_na()

adae <- adae %>%
  df_explicit_na()
```

## Start preprocessing

Now we will add some pre-processing to add labels ready for display in the table and how the output will be split.

```{r preproc}
adae <- adae %>%
  var_relabel(
    AEBODSYS = "MedDRA System Organ Class",
    AEDECOD = "MedDRA Preferred Term"
  ) %>%
  filter(SAFFL == "Y")

# Define the split function
split_fun <- drop_split_levels
```

## Adverse Events table

Now we create the Adverse Events table.

```{r table}
lyt <- basic_table(show_colcounts = TRUE) %>%
  split_cols_by(var = "ACTARM") %>%
  add_overall_col(label = "All Patients") %>%
  analyze_num_patients(
    vars = "USUBJID",
    .stats = c("unique", "nonunique"),
    .labels = c(
      unique = "Total number of patients with at least one adverse event",
      nonunique = "Overall total number of events"
    )
  ) %>%
  split_rows_by(
    "AEBODSYS",
    child_labels = "visible",
    nested = FALSE,
    split_fun = split_fun,
    label_pos = "topleft",
    split_label = obj_label(adae$AEBODSYS)
  ) %>%
  summarize_num_patients(
    var = "USUBJID",
    .stats = c("unique", "nonunique"),
    .labels = c(
      unique = "Total number of patients with at least one adverse event",
      nonunique = "Total number of events"
    )
  ) %>%
  count_occurrences(
    vars = "AEDECOD",
    .indent_mods = -1L
  ) %>%
  append_varlabels(adae, "AEDECOD", indent = 1L)

result <- build_table(lyt, df = adae, alt_counts_df = adsl)

result
```
 
Cookie Preferences