autoplot.predictCox: Plot Predictions From a Cox Model

Description Usage Arguments Examples

Description

Plot predictions from a Cox model.

Usage

1
2
3
4
## S3 method for class 'predictCox'
autoplot(object, type = NULL, ci = FALSE,
  band = FALSE, group.by = "row", reduce.data = FALSE, plot = TRUE,
  ylab = NULL, digits = 2, alpha = NA, ...)

Arguments

object

Object obtained with the function predictCox.

type

[character] The type of predicted value to display. Choices are: "hazard" the hazard function, "cumhazard" the cumulative hazard function, or "survival" the survival function.

ci

[logical] If TRUE display the confidence intervals for the predictions.

band

[logical] If TRUE display the confidence bands for the predictions.

group.by

[character] The grouping factor used to color the prediction curves. Can be "row", "strata", or "covariates".

reduce.data

[logical] If TRUE only the covariates that does take indentical values for all observations are displayed.

plot

[logical] Should the graphic be plotted.

ylab

[character] Label for the y axis.

digits

[integer] Number of decimal places.

alpha

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

...

Not used. Only for compatibility with the plot method.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(survival)
library(ggplot2)

#### simulate data ####
set.seed(10)
d <- sampleData(1e2, outcome = "survival")

#### Cox model ####
m.cox <- coxph(Surv(time,event)~ X1 + X2 + X3,
                data = d, x = TRUE, y = TRUE)

## display baseline hazard
e.basehaz <- predictCox(m.cox)

autoplot(e.basehaz, type = "cumhazard")

## display predicted survival
pred.cox <- predictCox(m.cox, newdata = d[1:4,],
  times = 1:5, type = "survival", keep.newdata = TRUE)
autoplot(pred.cox)
autoplot(pred.cox, group.by = "covariates")
autoplot(pred.cox, group.by = "covariates", reduce.data = TRUE)

## predictions with confidence interval/bands
pred.cox <- predictCox(m.cox, newdata = d[1,,drop=FALSE],
  times = 1:5, type = "survival", band = TRUE, se = TRUE, keep.newdata = TRUE)
autoplot(pred.cox, ci = TRUE, band = TRUE)
autoplot(pred.cox, ci = TRUE, band = TRUE, alpha = 0.1)

#### Stratified Cox model ####
m.cox.strata <- coxph(Surv(time,event)~ strata(X1) + strata(X2) + X3 + X6,
                      data = d, x = TRUE, y = TRUE)

pred.cox.strata <- predictCox(m.cox.strata, newdata = d[1:5,,drop=FALSE],
                              time = 1:5, keep.newdata = TRUE)

## display
res <- autoplot(pred.cox.strata, type = "survival", group.by = "strata")

## customize display
res$plot + facet_wrap(~strata, labeller = label_both)
res$plot %+% res$data[strata == "0, 1"]

bozenne/riskRegressionLight documentation built on May 7, 2019, 12:52 a.m.