Learn R Programming

rstpm2 (version 1.3.2)

plot-methods: plots for an stpm2 fit

Description

Given an stpm2 fit, return a plot

Usage

"plot"(x,y,newdata,type="surv", xlab="Time",line.col=1,ci.col="grey", add=FALSE,ci=TRUE,rug=TRUE, var=NULL,...)

Arguments

x
an stpm2 object
y
not used (for generic compatibility)
newdata
required list of new data. This defines the unexposed newdata (excluding the event times).
type
specify the type of prediction:
  • "surv"survival probabilities
  • "cumhaz"cumulative hazard
  • "hazard"hazard
  • "hr"hazard ratio
  • "sdiff"survival difference
  • "hdiff"hazard difference

xlab
x-axis label
line.col
line colour
ci.col
confidence interval colour
ci
whether to plot the confidence interval band (default=TRUE)
add
whether to add to the current plot (add=TRUE) or make a new plot (add=FALSE) (default=FALSE)
rug
whether to add a rug plot of the event times to the current plot (default=TRUE)
var
specify the variable name or names for the exposed/unexposed (names are given as characters)
...
additional arguments (add to the plot command)

Methods

x = "stpm2", y = "missing"
an stpm2 fit

See Also

stpm2

Examples

Run this code


## The function is currently defined as
setMethod("plot", signature(x="stpm2", y="missing"),
          function(x,y,newdata,type="surv",
                      xlab="Time",line.col=1,ci.col="grey",
                      add=FALSE,ci=TRUE,rug=TRUE,
                      var=NULL,...) {
  y <- predict(x,newdata,type=type,var=var,grid=TRUE,se.fit=TRUE)
  ylab <- switch(type,hr="Hazard ratio",hazard="Hazard",surv="Survival",
                 sdiff="Survival difference",hdiff="Hazard difference")
  xx <- attr(y,"newdata")
  xx <- xx[,ncol(xx)]
  if (!add) matplot(xx, y, type="n", xlab=xlab, ylab=ylab, ...)
  if (ci) polygon(c(xx,rev(xx)), c(y[,2],rev(y[,3])), col=ci.col, border=NA)
  lines(xx,y[,1],col=line.col)
  if (rug) {
      Y <- x@y
      eventTimes <- Y[Y[,ncol(Y)]==1,ncol(Y)-1]
      rug(eventTimes)
    }
})

  

Run the code above in your browser using DataLab