The various causalRisk plot methods produce paneled ggplot2 objects depicting each set of estimates or effect measures of interest and their associated confidence intervals. In the case of the cumrisk and cumcount methods, the results are plotted over time, wheras for the hr method the plot simply displays a single data point for each hazard ratio since by construction the ratios are constant over time.

Note that the plot and forest_plot methods for the hr class are aliases for each other.

# S3 method for cumrisk
plot(
  ...,
  rd = FALSE,
  effect_measure_type = NULL,
  overlay = FALSE,
  smooth = FALSE,
  ncol = 2,
  panel_dim = 1,
  time_lab,
  alpha = 0.05,
  scales = "free_y",
  stepribbon = TRUE,
  legend_title = "Treatment \nGroups",
  colors = "Dark2",
  ref = 1,
  boot_method = "normal"
)

# S3 method for cumcount
plot(
  ...,
  cd = FALSE,
  effect_measure_type = NULL,
  overlay = FALSE,
  smooth = FALSE,
  ncol = 2,
  panel_dim = 1,
  time_lab,
  alpha = 0.05,
  scales = "free_y",
  stepribbon = TRUE,
  legend_title = "Treatment \nGroups",
  colors = "Dark2",
  ref = 1,
  boot_method = "normal"
)

# S3 method for hr
plot(..., alpha = 0.05, legend_title = "Treatment \nGroups", colors = "Dark2")

Arguments

...

Objects with an associated method for creating plots supplied as either as seperate arguments or as a list.

rd

A flag to indicate whether the risk difference should be plotted or the individual risk functions (deprecated, now use the effect_measure_ttype parameter)

effect_measure_type

Either NULL to display the original estimates of interrest or a string identifying the type of effect measure to be displayed from among the following options for a given method.

  • cumrisk: "RD" (risk difference), "RR" (risk ratio), "logRR" (logarithm of the risk ratio), or "AR" (attributable risk)

  • cumcount: "CD" (count difference) or "CR" (count ratio)

Note that when a given input results object was created using bootstrap estimation and boot_method is "log-normal", then only effect measures with support on the positive real line can be used (i.e. "RR" or "CR", depending on the method). See the Cumulative risk effect measure types and Cumulative count effect measure types sections for the definitions of the various effect measures.

overlay

A flag to indicate that the risk difference curves should be overlayed rather than paneled

smooth

A flag to indicate the use of LOESS smoothing for risk difference

ncol

The number of columns for the faceting.

panel_dim

The number of dimensions for the faceting (either 1 or 2). Panels are faceted using the first (and if panel_dim = 2) and second elements of the labels vector in the supplied objects.

time_lab

A numeric vector denoting the x-axis tick marks to be labeled. Default is the ggplot2 default. Setting the parameter to NULL suppressed labeling.

alpha

The desired significance level of the confidence intervals.

scales

A ggplot2 option for facet_grid/facet_wrap that controls the scales on facted plots. It can be fixed ("fixed"), free ("free"), or free in one dimension ("free.x", "free.y"). The default is "free.y."

stepribbon

A flag to determine whether to force the confidence intervals to be plotted using the stepribbon geom. The default is TRUE.

legend_title

A string used to title the legend, default is "Treatment Groups"

colors

Set colors for resulting ggplot object. Either a vector of strings which are interpreted as RGB codes or a sinlge string that identifies a color brewer palette. If set to NULL, the methods will use grey shades via the color brewer palette 'Dark2'.

ref

Identifies the treatment group in the supplied object(s) to be used as a referent category for risk differecence curves. Defaults to 1.

boot_method

The specific bootstrap approach used to compute confidence intervals (default method = "normal" for a normal approximation on the risk scale, other choices include "log normal" for normal approximation on the log scale).

cd

A flag to indicate whether the count difference should be plotted or the individual count functions (deprecated, now use the effect_measure_type parameter)

Value

A ggplot2 object that can be further modified by the user before plotting.

Methods (by class)

  • plot(cumrisk): Plot a panel of (possibly overlayed) cumulative risk functions or cumulative risk effect measures and confidence intervals.

  • plot(cumcount): Plot a panel of (possibly overlayed) cumulative count functions or cumulative count effect measures and confidence intervals.

  • plot(hr): Plot hazard ratios for analyses relative to their respective control groups.

Cumulative risk effect measure types

Risk difference

Mean: \(\mathrm{E}[Y^{1}] - \mathrm{E}[Y^{0}]\)

Variance with IPW: \( \mathrm{Var}[Y^{1}] + \mathrm{Var}[Y^{0}] + \frac{2}{n} \mathrm{E}[Y^{1}] \, \mathrm{E}[Y^{0}] \)

Variance otherwise: \(\mathrm{Var}[Y^{1}] + \mathrm{Var}[Y^{0}]\)

Risk ratio

Mean: \(\frac{\mathrm{E}[Y^{1}]}{\mathrm{E}[Y^{0}]}\)

Variance with IPW: \( \frac{\mathrm{Var}[Y^{1}]}{(\mathrm{E}[Y^{0}])^{2}} + \frac{\mathrm{Var}[Y^{0}]\,(\mathrm{E}[Y^{1}])^2} {(\mathrm{E}[Y^{0}])^{4}} + \frac{2\,(\mathrm{E}[Y^{1}])^2}{n\,(\mathrm{E}[Y^{0}])^2} \)

Variance otherwise: \( \frac{\mathrm{Var}[Y^{1}]}{(\mathrm{E}[Y^{0}])^{2}} + \frac{\mathrm{Var}[Y^{0}]\,(\mathrm{E}[Y^{1}])^2} {(\mathrm{E}[Y^{0}])^{4}} \)

Logarithm of the risk ratio

Mean: \(\mathrm{log}\frac{\mathrm{E}[Y^{1}]}{\mathrm{E}[Y^{0}]}\)

Variance with IPW: \( \frac{\mathrm{Var}[Y^{1}]}{(\mathrm{E}[Y^{1}])^{2}} + \frac{\mathrm{Var}[Y^{0}]}{(\mathrm{E}[Y^{0}])^{2}} + \frac{2}{n} \)

Variance otherwise: \( \frac{\mathrm{Var}[Y^{1}]}{(\mathrm{E}[Y^{1}])^{2}} + \frac{\mathrm{Var}[Y^{0}]}{(\mathrm{E}[Y^{0}])^{2}} \)

Attributable risk

Mean: \(\frac{\mathrm{E}[Y^{1}] - \mathrm{E}[Y^{0}]}{\mathrm{E}[Y^{1}]}\)

Variance with IPW: \( \frac{\mathrm{Var}[Y^{0}]}{(\mathrm{E}[Y^{1}])^{2}} + \frac{\mathrm{Var}[Y^{1}]\,(\mathrm{E}[Y^{0}])^{2}} {(\mathrm{E}[Y^{1}])^{4}} + \frac{2\,(\mathrm{E}[Y^{0}])^{2}}{n\,(\mathrm{E}[Y^{1}])^{2}} \)

Variance otherwise: \( \frac{\mathrm{Var}[Y^{0}]}{(\mathrm{E}[Y^{1}])^{2}} + \frac{\mathrm{Var}[Y^{1}]\,(\mathrm{E}[Y^{0}])^{2}} {(\mathrm{E}[Y^{1}])^{4}} \)

Cumulative count effect measure types

Count difference

Mean: \(\mathrm{E}[Y^{1}] - \mathrm{E}[Y^{0}]\)

Variance with IPW: \( \mathrm{Var}[Y^{1}] + \mathrm{Var}[Y^{0}] + \frac{2}{n} \mathrm{E}[Y^{1}] \, \mathrm{E}[Y^{0}] \)

Variance otherwise: \(\mathrm{Var}[Y^{1}] + \mathrm{Var}[Y^{0}]\)

Count ratio

Mean: \(\frac{\mathrm{E}[Y^{1}]}{\mathrm{E}[Y^{0}]}\)

Variance with IPW: \( \frac{\mathrm{Var}[Y^{1}]}{(\mathrm{E}[Y^{0}])^{2}} + \frac{\mathrm{Var}[Y^{0}]\,(\mathrm{E}[Y^{1}])^2} {(\mathrm{E}[Y^{0}])^{4}} + \frac{2\,(\mathrm{E}[Y^{1}])^2}{n\,(\mathrm{E}[Y^{0}])^2} \)

Variance otherwise: \( \frac{\mathrm{Var}[Y^{1}]}{(\mathrm{E}[Y^{0}])^{2}} + \frac{\mathrm{Var}[Y^{0}]\,(\mathrm{E}[Y^{1}])^2} {(\mathrm{E}[Y^{0}])^{4}} \)

Author

plot.cumrisk: M. Alan Brookhart

plot.cumcount: M. Alan Brookhart & Alexander Breskin

plot.hr: Brendan Brown