Learn R Programming

riskRegression (version 2020.12.08)

autoplot.ate: Plot Average Risks

Description

Plot average risks.

Usage

# S3 method for ate
autoplot(
  object,
  type = "meanRisk",
  first.derivative = FALSE,
  estimator = object$estimator[1],
  ci = object$inference$ci,
  band = object$inference$band,
  plot.type = "1",
  plot = TRUE,
  smooth = FALSE,
  digits = 2,
  alpha = NA,
  ylab = NULL,
  ...
)

Arguments

object

Object obtained with the function ate.

type

[character vector] what to displayed. Can be "meanRisk" to display the risks specific to each treatment group, "diffRisk" to display the difference in risks between treatment groups, or "ratioRisk" to display the ratio of risks between treatment groups,.

first.derivative

[logical] If TRUE, display the first derivative over time of the risks/risk differences/risk ratios. (confidence intervals are obtained via simulation).

estimator

[character] The type of estimator relative to which the risks should be displayed.

ci

[logical] If TRUE display the confidence intervals for the average risks.

band

[logical] If TRUE display the confidence bands for the average risks.

plot.type

[character] Type of plot to be used. plot.type="2" is useful when looking simulateneous at all eventtimes. Otherwise use plot.type="1".

plot

[logical] Should the graphic be plotted.

smooth

[logical] Should a smooth version of the risk function be plotted instead of a simple function?

digits

[integer, >0] Number of decimal places.

alpha

[numeric, 0-1] Transparency of the confidence bands. Argument passed to ggplot2::geom_ribbon.

ylab

[character] Label for the y axis.

...

Additional parameters to cutomize the display.

Value

Invisible. A list containing:

  • plot: the ggplot object.

  • data: the data used to create the plot.

See Also

ate to compute average risks.

Examples

Run this code
# NOT RUN {
library(survival)
library(rms)
library(ggplot2)

#### simulate data ####
n <- 1e2
set.seed(10)
dtS <- sampleData(n,outcome="survival")
seqTimes <- c(0,sort(dtS$time[dtS$event==1]),max(dtS$time))

#### Cox model ####
fit <- cph(formula = Surv(time,event)~ X1+X2,data=dtS,y=TRUE,x=TRUE)

#### plot.type = 1: for few timepoints ####
ateFit <- ate(fit, data = dtS, treatment = "X1",
              times = c(1,2,5,10), se = TRUE, band = TRUE)
ggplot2::autoplot(ateFit)
ggplot2::autoplot(ateFit, band = FALSE)
ggplot2::autoplot(ateFit, type = "diffRisk")
ggplot2::autoplot(ateFit, type = "ratioRisk")

#### plot.type = 2: when looking at all jump times ####
ateFit <- ate(fit, data = dtS, treatment = "X1",
              times = seqTimes, se = TRUE, band = TRUE)

ggplot2::autoplot(ateFit, plot.type = "2")

## customize plot
outGG <- ggplot2::autoplot(ateFit, plot.type = "2", alpha = 0.25)
outGG$plot + facet_wrap(~X1, labeller = label_both)


## Looking at the difference after smoothing
# }
# NOT RUN {
outGGS <- ggplot2::autoplot(ateFit, plot.type = "2", alpha = NA, smooth = TRUE)
outGGS$plot + facet_wrap(~X1, labeller = label_both)
# }
# NOT RUN {
## first derivative
## (computation of the confidence intervals takes time)
## (based on simulation - n.sim parameter)
# }
# NOT RUN {
ggplot2::autoplot(ateFit, plot.type = "2", smooth = TRUE,
                  band = FALSE, type = "diffRisk")
ggplot2::autoplot(ateFit, plot.type = "2", smooth = TRUE, first.derivative = TRUE,
                  band = FALSE, type = "diffRisk")
# }

Run the code above in your browser using DataLab