Learn R Programming

rstpm2 (version 1.2.2)

plot-methods: plots for an stpm2 fit

Description

Given an stpm2 fit, return a plot

Usage

## S3 method for class 'stpm2':
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}

item

  • xlab
  • line.col
  • ci.col
  • ci
  • add
  • rug
  • var
  • ...

code

plot

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