ae.dotplot7: AE (Adverse Events) dotplot of incidence and relative risk,... Documentation

AE (Adverse Events) dotplot of incidence and relative risk, support functions


Support functions for the AEdotplot.


  ## S3 method for class 'data.frame'
AEdotplot(xr, ...,
          sub=list(conditionName, cex=.7))

  ## S3 method for class 'AElogrelrisk'
$RAND)[1], " (n=", xr$SN[1], ")", sep=""),
$RAND)[2], " (n=", xr$SN[2], ")", sep=""),
          col.AB=c("red","blue"), pch.AB=c(16,17),
           main=if (sortbyRelativeRisk)
              list("Most Frequent On-Therapy Adverse Events Sorted by Relative Risk",
              list("Most Frequent On-Therapy Adverse Events", cex=1),
          cex.AB.points=NULL, cex.AB.y.scale=.6, cex.x.scale=.6,
          panel.widths=c(.55, .22, .23),
          key.y=-.2, CI.percent=95,
          sub=list(conditionName, cex=.7),

  ## S3 method for class 'AEtable'
AEdotplot(xr, ..., useCondition=TRUE,
                              sub="sub for AEsecond")

  ## S3 method for class 'AEdotplot'
print(x, ...,
      main=attr(x, "main"),
      ae.key=attr(x, "ae.key"),

  ## S3 method for class 'AEdotplot'
c(..., panel.widths=attr(aedp[[1]], "panel.widths"),

               sortbyRelativeRisk=TRUE, ...,
                         sortbyVar=c("PREF", ## Event name
                           "PCT",            ## Percent
                           "SN",             ## Number of Patients
                           "SAE",            ## Number of Observed Events
                           "relrisk",        ## Relative Risk (RR)
                           "ase.logrelrisk", ## Asymptotic Standard Error(log(RR))
                           "relriskCI.lower", ## Confidence Interval Bounds
                         sortbyVarBegin=1)   ## 1 for A treatment, 2 for B treatment

                   AEsecond.AEtable=attr(AEsecond, "AEtable"),
                             function(AEsubtable) levels(AEsubtable$PREF)),
                   main.second=list(paste("Most Frequent On-Therapy Adverse Events",
                                          "Sorted to Match First Table"),

  ## S3 method for class 'AEdotplot'
update(object, ...)



For AElogrelrisk, a data.frame containing at least the first 4 columns of xr.


For the formula method documented in AEdotplot, a formula of the form
AE ~ nAE/nTRT | OrgSys, where the condition variable is optional. For the formula method only, the variable names are not restricted.

For the other methods, xr is a data.frame containing the Adverse Event data in long format. It must have variables named
RAND: treatment as randomized (factor with exactly two levels).
PREF: adverse event symptom name (factor).
SN: number of patients in treatment group.
SAE: number of patients in each group for whom the event PREF was observed.

If the xr object is a AElogrelrisk object, then it must also have variables
PCT: SAE/SN as a percent.
relrisk: Relative risk defined as PCT for the B treatment divided by PCT for the A treatment.
logrelrisk: natural logarithm of relrisk.
ase.logrelrisk: asymptotic standard error of logrelrisk.
logrelriskCI.lower, logrelriskCI.upper: confidence interval for logrelrisk.
relriskCI.lower, relriskCI.upper: back transform of the CI for the log relative risk into the relative risk scale.


logical. If TRUE, then make the Adverse Events an ordered factor ordering by relative risk. If FALSE, then make the Adverse Events an ordered factor retaining the order of the input levels.


Vector of same length as number of rows in xr, it may be one of the columns in xr in which case its full name in the form xr$varname must be used. It will be used to split the data.frame into partitions. It may be used to partition the plot, for example by organ system or by gender.


Character. Name to be used in left.strip.


logical. If FALSE, then a non-NULL ConditionVariable won't be used.


object to be printed.


Vector of three non-negative numerics that sum to 1. These are the widths of each of the three panels in the output plot. The left panel contains the AE names as y-tick labels and the Percent plot. The middle panel contains the Relative Risk plot. The right panel contains a table of the numerical values of number of patients for each treatment, number of adverse events for each treatment, and relative risk. Setting the third value to 0 suppresses the table of numerical values from the display.


logical. For the print.AEdotplot function. If TRUE (the default), display all three panels. If FALSE, then display only the Percent and Relative Risk plots.

main, sub

Main title and subtitle for the combined plot in AEdotplot.


Main title for second plot whose sort order has been changed to match the first plot.,

Names of treatment groups (in x$RAND).

col.AB, pch.AB, cex.AB.points

color, plotting character and character expansion for the individual points on the left plot.


Character expansion for the left tick labels (the Adverse Effects names).


Character expansion for the x-axis tick labels.


Position of the key (legend) in the combined plot. This is the y argument of the key. See the discussion of the key argument to xyplot in xyplot



is a key as described in xyplot.

AEstandard, AEsecond, AEsecond.AEtable, levels.order

Arguments that force the Adverse Events in the panels of AEsecond to have the same sort order levels.order of PREF as the panels of AEstandard. AEstandard and AEsecond are two "AEdotplot" objects with the same set of panels and the same Adverse Events in corresponding panels. AEsecond.AEtable is the AEtable object from AEsecond. levels.order is the new order for AEsecond; normally the same order as in AEprimary.


Critical value used to compute confidence intervals on the log relative risk. Defaults to 1.96. User is responsible for specifying both crit.value and CI.percent consistently.


Confidence percent associated with the crit.value Defaults to 95. User is responsible for specifying both crit.value and CI.percent consistently.


For AEdotplot and, all the arguments listed in the calling sequence for AEddotplot.AErelrisk.. For c.AEdotplot, one or more "AEdotplot" objects. For print.AEdotplot, the ... arguments are ignored.


Specify which variable will be used to provide the sort order in the plot. The names are the internal names for the variables.


1 for A treatment, 2 for B treatment.


An AEdotplot object. The update method updates the components of each of the constituent trellis objects. It does not update the "main" and "sub" attributes (nor any other attribute) of the AEdotplot object.


Default value for strip labels. See xyplot for details.


The first panel is an ordinary dotplot of the percent of AE observed for each treatment by AE.

The second panel shows relative risk of an event on the Treatment B arm (usually the active compound) relative to the Treatment A arm (usually the placebo), with 95% confidence intervals for a 2x2 table. Confidence intervals on the log relative risk are calculated using the asymptotic standard error formula given as Equation 3.18 in Agresti A., Categorical Data Analysis. Wiley: New York, 1990.

By default the AEdotplot function sorts the events by relative risk. To retain the sort order implied by the levels of the AE factor, specify the argument sortbyRelativeRisk=FALSE. To control the sort order, make the AE factor in the input dataset an ordered factor and specify the levels in the order you want.

The third panel shows the numerical values of the number and percent of observed events on each arm and the relative risk. The display of third panel can be suppressed by specifying the panel.widths argument.


The primary interest is in the display of the plot.

The function returns an AEdotplot object which is a list of three trellis objects, one for the the Percent plot, one for the Relative Risk plot, and one for the Text plot containing the table of input values. The object has attributes

  1. main and sub hold the main and subtitles. Each must be a list containing the text in the first component.

  2. ae.key is a key as described in xyplot.

  3. is a vector containing the number of events in each subpanel.

  4. panel.widths is a vector of relative widths of the three components of the graph. The numbers must sum to one. Zero values are permitted. The first width includes the left axis and the Percent plot. The second is the Relative Risk plot, and the third is the plot of the table values.

  5. AEtable is a table containing the data plotted on its row.


Richard M. Heiberger <>


Ohad Amit, Richard M. Heiberger, and Peter W. Lane. (2008) “Graphical Approaches to the Analysis of Safety Data from Clinical Trials”. Pharmaceutical Statistics, 7, 1, 20–35.

See Also



## Not run: 
## variable names in the input data.frame aeanonym
## RAND   treatment as randomized
## PREF   adverse event symptom name
## SN     number of patients in treatment group
## SAE    number of patients  in each group for whom the event PREF was observed
## OrgSys Organ System
## Input sort order is PREF/RAND


## variable names are hard-wired in the program
## names(aeanonym) <- c("RAND", "PREF", "SAE", "SN", "OrgSys")

## Calculate log relative risk and confidence intervals (95
## AElogrelrisk sets the sort order for PREF to match the relative risk.
aeanonymr <- AElogrelrisk(aeanonym) ## PREF sorted by relative risk


AEdotplot(aeanonym, sort=FALSE)

AEdotplot(aeanonym, conditionVariable=aeanonym$OrgSys)

aefake <- rbind(cbind(aeanonym, group="ABC"), cbind(aeanonym, group="DEF"))
aefake$SAE[67:132] <- sample(aefake$SAE[67:132])
aefake$ <- with(aefake, interaction(OrgSys, group))

## fake 2
KEEP <- aefake$OrgSys %in% c("GI","Resp")

AEfakeGR <- AEdotplot(aefake[KEEP,], conditionVariable=aefake$[KEEP],
            sub=list("ABC and DEF have different sort orders for PREF", cex=.7))
AEfakeGR ## ABC and DEF have different sort orders for PREF

AEfakeGR1 <- AEdotplot(aefake[KEEP & (1:132) <= 66,],
                       conditionVariable=aefake$[KEEP & (1:132) <= 66])
AEfakeGR2 <- AEdotplot(aefake[KEEP & (1:132) >= 67,],
                       conditionVariable=aefake$[KEEP & (1:132) >= 67])


AEfakeMatched <- AEmatchSortorder(AEfakeGR1, AEfakeGR2)
update(, AEfakeMatched),
       main="ABC sorted by Relative Risk; DEF matches ABC order")

## End(Not run)
## Please see  ?AEdotplot  for examples using the formula method
## Many more examples are in demo("AEdotplotManyExamples")

HH documentation built on Aug. 9, 2022, 5:08 p.m.

Related to ae.dotplot7 in HH...