Learn R Programming

prodlim (version 1.4.5)

plot.prodlim: Plotting event probabilities over time

Description

Function to plot survival and cumulative incidence curves against time.

Usage

## S3 method for class 'prodlim':
plot(x, type, cause = 1, newdata, add = FALSE, col, lty,
  lwd, ylim, xlim, xlab = "Time", ylab, legend = TRUE, logrank = FALSE,
  marktime = FALSE, confint = TRUE, automar, atrisk = ifelse(add, FALSE,
  TRUE), timeOrigin = 0, axes = TRUE, background = TRUE, percent = TRUE,
  minAtrisk = 0, ...)

Arguments

x
an object of class `prodlim' as returned by the prodlim function.
type
controls what part of the object is plotted. Defaults to "survival" for the Kaplan-Meier estimate of the survival function in two state models and to "incidence" for the Aalen-Johansen estimate of the cumulative incidence
cause
determines the cause of the cumulative incidence function. Currently one cause is allowed at a time, but you may call the function again with add=TRUE to add the lines of the other causes.
newdata
a data frame containing strata for which plotted curves are desired.
add
if 'TRUE' curves are added to an existing plot.
col
color for curves defaults to 1:number(curves)
lty
line type for curves defaults to 1
lwd
line width for all curves
ylim
limits of the y-axis
xlim
limits of the x-axis
ylab
label for the y-axis
xlab
label for the x-axis
legend
if TRUE a legend is plotted by calling the function legend. Optional arguments of the function legend can be given in the form legend.x=val where x is the name of the argument and val the desired value. See also Details.
logrank
If TRUE, the logrank p-value will be extracted from a call to survdiff and added to the legend. This works only for survival models, i.e. Kaplan-Meier with discrete predictors.
marktime
if TRUE the curves are tick-marked at right censoring times by invoking the function markTime. Optional arguments of the function markTime can be given in the form confint.x=val as with legend. See also Detai
confint
if TRUE pointwise confidence intervals are plotted by invoking the function confInt. Optional arguments of the function confInt can be given in the form confint.x=val as with legend. See also Details.
automar
If TRUE the function trys to get good values for figure margins around the main plotting region.
atrisk
if TRUE display numbers of subjects at risk by invoking the function atRisk. Optional arguments of the function atRisk can be given in the form atrisk.x=val as with legend. See also Details.
timeOrigin
Start of the time axis
axes
If true axes are drawn. See details.
background
If TRUE the background color and grid color can be controlled using smart arguments SmartControl, such as background.bg="yellow" or background.bg=c("gray66","gray88"). The following defaults are passed to background by
percent
If true the y-axis is labeled in percent.
minAtrisk
Integer. Show the curve only until the number at-risk is at least minAtrisk
...
Parameters that are filtered by SmartControl and then passed to the functions plot, legend,

Value

  • The (invisible) object.

code

SmartControl

Details

From version 1.1.3 on the arguments legend.args, atrisk.args, confint.args are obsolete and only available for backward compatibility. Instead arguments for the invoked functions atRisk, legend, confInt, markTime, axis are simply specified as atrisk.cex=2. The specification is not case sensitive, thus atRisk.cex=2 or atRISK.cex=2 will have the same effect. The function axis is called twice, and arguments of the form axis1.labels, axis1.at are used for the time axis whereas axis2.pos, axis1.labels, etc. are used for the y-axis.

These arguments are processed via ...

See Also

plot, legend, axis, prodlim,plot.Hist,summary.prodlim, neighborhood, atRisk, confInt, markTime, backGround

Examples

Run this code
## simulate right censored data from a two state model
set.seed(100)
dat <- SimSurv(100)
# with(dat,plot(Hist(time,status)))

### marginal Kaplan-Meier estimator
kmfit <- prodlim(Hist(time, status) ~ 1, data = dat)
plot(kmfit)

# change time range
plot(kmfit,xlim=c(0,100))

# change scale of y-axis
plot(kmfit,percent=FALSE)

# change axis label and position of ticks
plot(kmfit,
     xlim=c(0,100),
     axis1.at=seq(0,100,30.25),
     axis1.labels=0:(length(seq(0,100,30.25))-1),
     xlab="Months",
     axis2.las=2,
     atrisk.at=seq(0,100,30.25),
     atrisk.label="Patients")

# change background color
plot(kmfit,
     xlim=c(0,100),
     confint.citype="shadow",
     col=1,
     axis1.at=seq(0,100,30.25),
     axis1.labels=0:(length(seq(0,100,30.25))-1),
     xlab="Months",
     axis2.las=2,
     atrisk.at=seq(0,100,30.25),
     atrisk.label="Patients",
     background=TRUE,
     background.fg="white",
     background.horizontal=seq(0,1,.25/2),
     background.vertical=seq(0,100,30.25),
     background.bg=c("gray88"))

# change type of confidence limits
plot(kmfit,
     xlim=c(0,100),
     confint.citype="dots",
     col=4,
     background=TRUE,
     background.bg=c("white","gray88"),
     background.fg="gray77",
     background.horizontal=seq(0,1,.25/2),
     background.vertical=seq(0,100,30.25))


### Kaplan-Meier in discrete strata
kmfitX <- prodlim(Hist(time, status) ~ X1, data = dat)
plot(kmfitX)
# move legend
plot(kmfitX,legend.x="bottomleft",atRisk.cex=1.3)

## Control the order of strata
## unfortunately prodlim does not obey the order of
## factor levels
dat$group <- factor(cut(dat$X2,c(-Inf,0,0.5,Inf)),labels=c("Low","Intermediate","High"))
kmfitG <- prodlim(Hist(time, status) ~ group, data = dat)
plot(kmfitG)

## we want to re-order the labels such
## that in the legend and in the numbers at-risk
## "Low" comes before "Intermediate" before "High"
dat$group2 <- as.numeric(dat$group)
kmfitG2 <- prodlim(Hist(time, status) ~ group2, data = dat)
plot(kmfitG2,legend.legend=levels(dat$group),atrisk.labels=levels(dat$group))

# add log-rank test to legend
plot(kmfitX,
     atRisk.cex=1.3,
     logrank=TRUE,
     legend.x="topright",
     atrisk.title="at-risk")

# change atrisk labels
plot(kmfitX,
     legend.x="bottomleft",
     atRisk.cex=1.3,
     atrisk.title="Patients",
     atrisk.labels=c("X1=0","X1=1"))

### Kaplan-Meier in continuous strata
kmfitX2 <- prodlim(Hist(time, status) ~ X2, data = dat)
plot(kmfitX2,xlim=c(0,50))

# specify values of X2 for which to show the curves
plot(kmfitX2,xlim=c(0,50),newdata=data.frame(X2=c(-1.8,0,1.2)))

### Cluster-correlated data
library(survival)
cdat <- cbind(SimSurv(20),patnr=sample(1:5,size=20,replace=TRUE))
kmfitC <- prodlim(Hist(time, status) ~ cluster(patnr), data = cdat)
plot(kmfitC,atrisk.labels=c("Units","Patients"))

## simulate right censored data from a competing risk model
datCR <- SimCompRisk(100)
with(datCR,plot(Hist(time,event)))

### marginal Aalen-Johansen estimator
ajfit <- prodlim(Hist(time, event) ~ 1, data = datCR)
plot(ajfit) # same as plot(ajfit,cause=1)

# cause 2
plot(ajfit,cause=2)

# both in one
plot(ajfit,cause=1)
plot(ajfit,cause=2,add=TRUE,col=2)

### stacked plot

plot(ajfit,cause="stacked")

### conditional Aalen-Johansen estimator
ajfitX <- prodlim(Hist(time, event) ~ X1+X2, data = datCR)
plot(ajfitX,newdata=data.frame(X1=c(1,1,0),X2=c(4,10,10)))
plot(ajfitX,newdata=data.frame(X1=c(1,1,0),X2=c(4,10,10)),cause=2)

## stacked plot

plot(ajfitX,
     newdata=data.frame(X1=0,X2=0.1),
     cause="stacked",
     legend.title="X1=0,X2=0.1",
     legend.legend=paste("cause:",getStates(ajfitX$model.response)),
     plot.main="Subject specific stacked plot")

Run the code above in your browser using DataLab