[R] plot(cox.zph())

Terry Therneau therneau at mayo.edu
Fri Sep 28 00:32:27 CEST 2007


The problem posed was the following:
	> fit <- coxph(....
	> zp  <- cox.zph(fit)
	> plot(zp[1])
     Error in plot.window(xlim, ylim, log, asp, ...) :
        need finite 'ylim' values

There were 21 covariates, but over 7000 events, so the Cox model fits ok.
After sending me the data, the problem, which I haven't seen before, is thus:

  In order to put a smooth curve onto the plot, cox.zph calls lm essentially 
thus
  		lm( resid ~ ns(x, df=4)
where x is the set of death times, and resid is a scaled Schoenfeld residual.  
For the data set in question x is of length 7109, and the lm call fails due to a 
singular fit!   This leads to a missing value and then eventually to the error 
message reported above.   Further exploration reveals that 4022 of the x values 
are log(.01), with the other 3087 spread out from 0 to log(365) in an 
approximately Gaussian shape.  The residuals are in two clumps from -4 to 0 and 
2 to 5, each clump dense, the histogram has two unimodal humps.

  I don't see why lm is failing.
  
  I have fixed plot.cox.zph so that it now prints an error message
     "Spline fit is singular, try a smaller degrees of freedom"
when the fit is singular.  This will at least be less confusing.  For the
data in hand
	plot(zp[1], df=2)
works fine.  

The repair will migrate to the R code in due course.  (I am currently working on 
some other updates to the survival package).

	Terry Therneau



More information about the R-help mailing list