Learn R Programming

survMisc (version 0.4.6)

dx: Diagnostics for coxph models

Description

Diagnostics for coxph models

Usage

dx(x, ...)

## S3 method for class 'coxph': dx(x, ..., what = c("all", "ph", "lin", "inf"), toPdf = TRUE, file = "dxPlots.pdf", maxStrata = 5, defCont = 2, noQuantiles = 3, maxFact = 4, identify = FALSE, degfP = 3, degfRS = 4, degfSS = 4, timeTrans = c("km", "log", "rank", "identity"), ties)

Arguments

x
An object of class coxph.
...
Additional arguments. Can be passed to graphics::plot or graphics::matplot. See ?par for details.
what
Which plots to make. See Value below.
toPdf
Print plots to pdf. This is usually recommended as each plot is created on a new device and 'R' can typically only have 61 devices open simultaneously.
  • IftoPdf=TRUE, each plot is created on a new page.
  • IftoPdf=FALSE
file
Filename to store plots. Default is "dxPlots.pdf".
maxStrata
Used for time vs. log-log survival plot. If there are $>$ maxStrata strata, no plot is shown for this. Recommended is $\leq 5$ to prevent the plot from becoming visually cluttered.
defCont
Definition of continuous variable. Variables with more than defCont unique values will be split into quantiles to facilitate graphs. (This does not apply to factor variables).
noQuantiles
No. of quantiles into which to split continuous variables
maxFact
Maximum number of levels in a factor. Used in plotting differences in log-hazard curves.
identify
Identify outliers manually. Cannot be used with toPdf=TRUE.
degfP
Degrees of freedom for smoothing spline in Poisson model.
degfRS
Degrees of freedom for regression splines.
degfSS
Degrees of freedom for smoothing splines. If degFSS=0, the 'optimal' degrees of freedom is chosen according to the AIC.
timeTrans
Type of time transformation to use when refitting model with time-transformed covariate. See ?survival::cox.zph for details.
ties
Method of handling ties when refitting model (for stratified plots). Default is the same as the original model, x. Usually one of "breslow" or "efron".

Value

  • Plots with base graphics. If what="ph":
  • $\pm$Time vs. $-\log -\log$ survival. If not too many strata to plot, as per argument maxStrata.
  • *Quantile-quantile plot. Unit exponential distribution vs. expected events (or Cox-Snell residuals)
  • *Observed vs. expected hazard
  • *Expected events vs. hazard based on sorted expected events
  • *Time vs. hazard, per predictor. Continuous variables are split into quantiles.
  • *Time vs. difference in log hazards, per predictor. Continuous variables are split into quantiles.
  • *Reference hazard vs. hazard for predictor. Continuous variables are split into quantiles.
  • If what="lin" (only applies to continuous variables):
  • $\pm$Predictor vs. residuals from a Poisson model with smoothing spline.
  • $\pm$Predictor vs. partial residual for predictor (with regression spline). For predictors with $>$ degfRS.
  • $\pm$Predictor vs. partial residual for predictor (with smoothing spline). For predictors with $>$ degfSS.
  • *Time vs. scaled Schoenfeld residuals, per predictor.
  • If what="inf":
  • *Observation vs. jacknife influence.
  • *Observation vs. jacknife influence (scaled by standard error of coefficients).
  • *Observation vs. leverage (=scaled score residual).
  • *Martingale residuals vs. likelihood displacement residuals.
  • If what="lin", a list of data.tables is also returned to the console:
  • PoissonResults from anova for a Poisson fit (via gam) with nonparametric effects. The model is re-fit with smoothing splines for continuous variables. Needs at least one predictor to have $>3$ unique values.
  • ttResults from the time-transformed fit, using survival::cox.zph.

References

Examples are from K&M Example 11.1 - 11.7, pg 355--66.

Last example is from: Therneau T, Grambsch P 2000. Modeling Survival Data, 1st edition. New York: Springer. Section 5.1.2, pg 91. http://dx.doi.org/10.1007/978-1-4757-3294-8{Springer (paywall)}

Andersen PK, Borgan O, Gill R, Keiding N 1982. Linear Nonparametric Tests for Comparison of Counting Processes, with Applications to Censored Survival Data, Correspondent Paper. International Statistical Review 50(3):219--44. http://www.jstor.org/stable/1402489{JSTOR}

Examples

Run this code
### running these examples with toPdf=FALSE will
### open too many devices to be compatible with R CMD check
### results from these examples can be found in the package source
### under /survMisc/inst/doc/
###
### for log-log plot
if(require(devtools)){
### this package is now archived, so need to install from url
 install_url("http://cran.r-project.org/src/contrib/Archive/surv2sample/surv2sample_0.1-2.tar.gz")
     library(surv2sample)
     data(gastric, package="surv2sample")
     dx(coxph(Surv(time/365, event) ~ treatment, data=gastric), file="gasDx.pdf")
 }
data(bmt, package="KMsurv")
bmt <- within(bmt, {
z1 <- z1 -28
z2 <- z2- 28
z3 <- z1*z2
z4 <- as.double(group == 2)
z5 <- as.double(group == 3)
z6 <- z8
z7 <- (z7 / 30) - 9
z8 <- z10
})
c1 <- coxph(Surv(t2, d3) ~ z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8,
         method="breslow", data=bmt)
dx(c1, file="bmtDx.pdf")
###
data(alloauto, package="KMsurv")
c1 <- coxph(Surv(time,delta) ~ factor(type),
            method="breslow", data=alloauto)
dx(c1, file="alloDx.pdf")
### GAM model. Therneau 5.3
data(pbc, package="survival")
w1 <- which(is.na(pbc$protime))
pbc <- pbc[-w1, ]
c1 <- coxph(Surv(time, status==2) ~ age + edema + bili + protime + albumin,
            data=pbc, method="breslow")
dx(c1, file="pbcDx.pdf")
### Time dependent covariate. Therneau 6.3
data(veteran, package="survival")
veteran$celltype <- relevel(veteran$celltype, ref="adeno")
c1 <- coxph(Surv(time, status) ~ trt * celltype + karno + diagtime + log(age) + prior,
            data=veteran[-1, ])
dx(c1, what="ph", file="vetDx.pdf")
### simple example which doesn't take up too many devices
c1 <- coxph(formula = Surv(time, status == 2) ~ age + log(bili), data=pbc)
dx(c1)

Run the code above in your browser using DataLab