Skip to contents

Introduction

The vignette documents how to use the functions in aeplots to create tables and plots for analysing adverse event data in clinical trials.

Input data

2 treatment arms

To generate tables and plots to summarise adverse events in clinical trials, the R package requires the input dataset in data frame format. A sample dataset with two treatment arms is shown below:

data(df2)
head(df2, 10)
id arm ae_pt aebodsys severity date_rand date_ae last_visit variable1 variable2
2001 Placebo Cold Respiratory Moderate 2015-10-28 2016-04-24 2016-08-31 2 910.7851
2001 Placebo Anemia Blood and lymphatic Severe 2015-10-28 2015-11-11 2016-08-31 2 910.7851
2001 Placebo Anemia Blood and lymphatic Moderate 2015-10-28 2016-05-10 2016-08-31 2 910.7851
2001 Placebo Leukocytosis Blood and lymphatic Severe 2015-10-28 2016-08-29 2016-08-31 2 910.7851
2001 Placebo Nausea Gastrointestinal Severe 2015-10-28 2016-02-23 2016-08-31 2 910.7851
2001 Placebo Cold Respiratory Mild 2015-10-28 2016-08-22 2016-08-31 2 910.7851
2001 Placebo Nausea Gastrointestinal Moderate 2015-10-28 2016-06-13 2016-08-31 2 910.7851
2001 Placebo Proteinuria Renal and urinary Severe 2015-10-28 2016-06-28 2016-08-31 2 910.7851
2001 Placebo Anxiety Psychiatric Moderate 2015-10-28 2015-11-11 2016-08-31 2 910.7851
2001 Placebo Vomiting Gastrointestinal Moderate 2015-10-28 2016-03-29 2016-08-31 2 910.7851

Note that for each participant who did not experience any adverse events, a row should be included in the input dataset stating his/her id, arm, date_rand, last_visit and variables to be included in the model. adverse_event, body_system_class and severity column should be specified as NA. For example:

tail(df2 %>% 
       add_row(id=2110, arm="Intervention", ae_pt=NA, aebodsys=NA, severity=NA, date_rand=ymd("2015-05-22"),
               last_visit=ymd("2016-04-22"), variable1=2, variable2=1500), 1)
id arm ae_pt aebodsys severity date_rand date_ae last_visit variable1 variable2
371 2110 Intervention NA NA NA 2015-05-22 NA 2016-04-22 2 1500

We would need to convert the body_system_class and severity columns to factors.

df2$aebodsys <- as.factor(df2$aebodsys)
# for severity to be presented in ascending order, we order the levels
df2$severity <- ordered(df2$severity, c("Mild", "Moderate", "Severe"))

Note that for all the functions below, you would need to specify the column names corresponding to each variable needed unless you rename the column names of your dataset to the default column names as specified in the sample dataset of the documentation. Do refer to the detailed documentation of each function by typing:

help(aetable)

More than 2 treatment arms

The functions aetable, aeseverity, aestacked and aebar can take up to 4 treatment arms. A sample dataset with 3 treatment arms:

data(df3)
head(df3, 10)
id arm ae_pt aebodsys severity date_rand date_ae last_visit
2001 Intervention 1 Cold Respiratory Moderate 2015-10-28 2016-08-03 2016-08-31
2001 Intervention 1 Anemia Blood and lymphatic Severe 2015-10-28 2016-05-24 2016-08-31
2001 Intervention 1 Anemia Blood and lymphatic Moderate 2015-10-28 2016-03-13 2016-08-31
2001 Intervention 1 Leukocytosis Blood and lymphatic Severe 2015-10-28 2016-02-13 2016-08-31
2001 Intervention 1 Nausea Gastrointestinal Severe 2015-10-28 2015-11-05 2016-08-31
2001 Intervention 1 Cold Respiratory Mild 2015-10-28 2016-02-19 2016-08-31
2001 Intervention 1 Nausea Gastrointestinal Moderate 2015-10-28 2016-07-15 2016-08-31
2001 Intervention 1 Proteinuria Renal and urinary Severe 2015-10-28 2015-11-26 2016-08-31
2001 Intervention 1 Anxiety Psychiatric Moderate 2015-10-28 2016-08-29 2016-08-31
2001 Intervention 1 Vomiting Gastrointestinal Moderate 2015-10-28 2016-01-10 2016-08-31
df3$aebodsys <- as.factor(df3$aebodsys)
df3$severity <- ordered(df2$severity, c("Mild", "Moderate", "Severe"))

aetable function

2 treatment arms

aetable plots a table of AE summary by body system class and arm. It contains the total number of participants at risk per arm (N1N_{1}, N2N_{2}), frequency (N), proportion (%), total number of events (n), incidence rate (IR), number of adverse events per participant (mean & SD) and treatment effect estimate with its 95% confidence interval (CI). To include additional covariates besides arm in the model, specify a vector of variable names in the variables argument.

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        treatment_effect_estimate=TRUE, variables = c("variable1", "variable2"))

We can specify the model used to estimate the treatment effect and 95% CI via the model argument. The available model options are Poisson (rate), Poisson (count), Negative Binomial (rate), Negative Binomial (count), Binomial (logit), Binomial (log) and Binomial (identity).

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        treatment_effect_estimate=TRUE, model="Binomial (logit)", variables = c("variable1", "variable2"))

We can specify IR per number of person via the IR_per_person argument. The default is IR per 100 person.

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        IR_per_person=1000)

We can specify the number of decimal places for the proportions, IR, mean and SD columns as well as the number of significant figures for the treatment effect estimate and 95% CI.

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        treatment_effect_estimate=TRUE, variables = c("variable1", "variable2"), proportions_dp=2, IR_dp=2,
        mean_dp=2, SD_dp=2, estimate_sf=4, CI_sf=4)

We can choose to drop the treatment effect estimate and 95% CI by specifying treatment_effect_estimate=FALSE.

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        treatment_effect_estimate=FALSE)

We can also choose to drop the mean column by specifying mean=FALSE.

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        treatment_effect_estimate=FALSE, mean=FALSE)

More than 2 treatment arms

aetable does not include the treatment effect estimates and their 95% CIs for datasets with more than 2 treatment arms. To change the labels of control and interventions in the table, specify the label for control in the argument control_name and specify the intervention labels in the argument intervention_names. Note that intervention_names should be specified using the same order as the interventions specified in intervention_levels.

aetable(df3, body_system_class="aebodsys", control="Placebo", control_name="No Drug",
        intervention_levels=c("Intervention 1", "Intervention 2"), intervention_names=c("Drug A", "Drug B"))

aeseverity function

2 treatment arms

aeseverity plots a table of frequencies and proportions of events by severity categories. We specify the number of decimal places for proportions via the argument proportions_dp.

aeseverity(df2, arm_levels=c("Intervention", "Placebo"), body_system_class="aebodsys", proportions_dp=2)

We can choose to drop the number of events column by specifying n_events=FALSE.

aeseverity(df2, arm_levels=c("Intervention", "Placebo"), body_system_class="aebodsys", n_events=FALSE)

More than 2 treatment arms

aeseverity(df3, arm_levels=c("Intervention 1", "Intervention 2", "Placebo"), 
           arm_names=c("Drug A", "Drug B", "No Drug"), body_system_class="aebodsys", n_events=FALSE)

aedot function

aedot plots a dot plot proportions alongside treatment effect estimates with accompanying 95% confidence interval to visualise AE and harm profiles in two-arm randomised controlled trials.

aedot(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention")

Similar to aetable, we can specify the model used to estimate the treatment effect and 95% CI via the model argument. The available model options are unadjusted (RR), unadjusted (RD), Poisson (rate), Poisson (count), Negative Binomial (rate), Negative Binomial (count), Binomial (logit), Binomial (log) and Binomial (identity). The default model is unadjusted (RR).

aedot(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention", model="unadjusted (RD)")

We can change the colours of the dots on the percentage of participants plot through the dot_colours argument.

aedot(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention", 
      dot_colours=c("#F4B800", "#97D800"))

aestacked function

2 treatment arms

aestacked plots a stacked bar chart of proportions for each body system class by arm and maximum severity. If severity is not ordered, it is required to specify the levels of severity in ascending order in the argument severity_levels.

aestacked(df2, body_system_class="aebodsys", arm_levels=c("Intervention","Placebo"), 
          severity_levels=c("Mild", "Moderate", "Severe"))

We can change the colour for each severity by specifying a vector of colour codes corresponding to each severity level in the severity_colours argument.

aestacked(df2, body_system_class="aebodsys", arm_levels=c("Intervention","Placebo"), 
          severity_levels=c("Mild", "Moderate", "Severe"), severity_colours=c("#D0EE11", "#48B5C4", "#115F9A"))

More than 2 treatment arms

aestacked(df3, body_system_class="aebodsys", arm_levels=c("Intervention 1","Intervention 2", "Placebo"),
          arm_names=c("Drug A","Drug B", "No Drug"), severity_levels=c("Mild", "Moderate", "Severe"))

aebar function

2 treatment arms

aebar plots a bar chart for number of events reported per participant.

aebar(df2, arm_levels=c("Intervention","Placebo"), adverse_event="ae_pt", facets=FALSE)

We can change the colour representing each treatment arm by specifying a vector of colour codes in the arm_colours argument according to the order of arm levels specified in the arm_levels argument.

aebar(df2, arm_levels=c("Intervention","Placebo"), adverse_event="ae_pt", arm_colours=c("#FFB55A", "#B2E061"), facets=FALSE)

More than 2 treatment arms

aebar(df3, arm_levels=c("Intervention 1","Intervention 2", "Placebo"), arm_names=c("Drug A","Drug B", "No Drug"),
      adverse_event="ae_pt", facets=FALSE)

We can plot a bar chart for each treatment arm in separate facets by specifying facets=TRUE.

aebar(df3, arm_levels=c("Intervention 1","Intervention 2", "Placebo"), arm_names=c("Drug A","Drug B", "No Drug"),
      adverse_event="ae_pt", facets=TRUE)

aevolcano function

aevolcano plots a volcano plot of treatment effect estimate against the p-value on the -log10 scale.

aevolcano(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention")

We can specify the model used to estimate the treatment effect via the model argument. The available model options are unadjusted (RD), unadjusted (RR), unadjusted (OR), unadjusted (IRR), Poisson (rate), Poisson (count), Negative Binomial (rate), Negative Binomial (count), Binomial (logit), Binomial (log) and Binomial (identity). The default model is unadjusted (RD).

aevolcano(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention", model="Binomial (logit)",
          variables=c("variable1", "variable2"))

Labels are added to events with p-values less than 0.1 on default. We can change the p-value cutoff for which labels are added to events through the p_value_cutoff argument.

aevolcano(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention", p_value_cutoff=0.05)

The default colours for the bubbles are blue and red, with blue indicating greater risk in the control arm and red indicating greater risk in the intervention arm. We can change the colour of bubbles through the bubble_colours argument, specifying the colour indicating greater risk in the control arm first, followed by the colour indicating greater risk in the intervention arm.

aevolcano(df2, body_system_class="aebodsys", control="Placebo", intervention="Intervention", bubble_colours = c("#B2E061", "#FFB55A"))

aemcf function

2 treatment arms

aemcf plots the mean cumulative function (MCF) with accompanying 95% confidence interval for harm outcomes by treatment arm with embedded table of number of participants at risk.

aemcf(df2, arm_levels=c("Intervention", "Placebo"), adverse_event="ae_pt", body_system_class="aebodsys")

We can plot the MCF for adverse events of specific organ systems or specific adverse events by specifying the conditions through the subset argument.

# this plots the MCF for adverse events of a specific body system class (i.e. Gastrointestinal)
aemcf(df2, arm_levels=c("Intervention", "Placebo"), subset= body_system_class=="Gastrointestinal", adverse_event="ae_pt",
      body_system_class="aebodsys")

# this plots the MCF for a specific adverse event (i.e. Anemia)
aemcf(df2, arm_levels=c("Intervention", "Placebo"), subset= adverse_event=="Anemia", adverse_event="ae_pt",
      body_system_class="aebodsys")

We can change the time units to either seconds, minutes, hours, days, weeks, months or years through the time_units argument.

aemcf(df2, arm_levels=c("Intervention", "Placebo"), adverse_event="ae_pt", body_system_class="aebodsys", time_units="weeks")

We can choose to not plot the 95% confidence intervals by specifying conf.int=FALSE.

aemcf(df2, arm_levels=c("Intervention", "Placebo"), adverse_event="ae_pt", body_system_class="aebodsys", conf.int=FALSE)

We can choose to drop the risk table by specifying risk_table=FALSE.

aemcf(df2, arm_levels=c("Intervention", "Placebo"), adverse_event="ae_pt", body_system_class="aebodsys", risk_table=FALSE)

We can change the colour representing each treatment arm by specifying a vector of colour codes in the arm_colours argument according to the order of arm levels specified in the arm_levels argument.

aemcf(df2, arm_levels=c("Intervention", "Placebo"), adverse_event="ae_pt", body_system_class="aebodsys", 
      arm_colours=c("#C77CFF", "#7CAE00"))

More than 2 treatment arms

aemcf(df3, arm_levels=c("Intervention 1", "Intervention 2", "Placebo"), 
      subset= body_system_class %in% c("Blood and lymphatic", "Respiratory"), adverse_event="ae_pt", body_system_class="aebodsys")

Saving tables and plots

Docx

We can save tables as docx by specifying the filepath in the save_docx_path argument.

aetable(df2, body_system_class="aebodsys", control="Placebo", intervention_levels=c("Intervention"),
        treatment_effect_estimate=TRUE, variables = c("variable1", "variable2"), save_docx_path="aetable.docx")

Image

We can save tables and plots as images by specifying the filepath in the save_image_path argument.

aebar(df3, arm_levels=c("Intervention 1","Intervention 2", "Placebo"), arm_names=c("Drug A","Drug B", "No Drug"),
      adverse_event="ae_pt", facets=TRUE, save_image_path="aeimage.png")