dardisco
dardisco

Reputation: 5274

Comparison error for quantiles for survival (survfit object)

I am trying to follow a textbook example of survival analysis and am not sure where I'm going wrong here:

df1 <- as.data.frame( cbind(seq(1:5),c(6,44,21,14,62),c(1,1,0,1,1)) )
names(df1) <- c('subject','time','censor')
require(survival)
f1 <- survfit(Surv(time=time, event=censor) ~1, data=df1)
quantile(f1)

Which gives the following:

Error in xi == xj : comparison of these types is not implemented
In addition: Warning messages:
1: In `[.survfit`(x, !nas) :Survfit object has only a single survival curve
2: In `[.survfit`(x, i) : Survfit object has only a single survival curve
3: In `[.survfit`(x, j) : Survfit object has only a single survival curve

I have tried this with survfit objects with more than one curve and still get the same message...

"R version 2.14.1 (2011-12-22)"

"x86_64-pc-linux-gnu"

Output from search():

[1] ".GlobalEnv"        "package:km.ci"     "package:survival" 
[4] "package:splines"   "package:stats"     "package:graphics" 
[7] "package:grDevices" "package:utils"     "package:datasets" 
[10] "package:methods"   "Autoloads"         "package:base"     

Many thanks!

EDIT: thanks DWin and sorry I missed that in help(Surv).

However I'm still getting the same error message. I'm reading the help for: quantile.survfit {survival} which is documented as an S3 generic, so I was expecting that using quantile(f1) should invoke this method.

However I'm finding that the following doesn't work:

survival:::quantile.survfit(f1) 

Gives:

Error: 'quantile.survfit' is not an exported object from 'namespace:survival'

Tried re-installing survival and it's still the most current version: survival_2.36-10

Upvotes: 0

Views: 703

Answers (1)

IRTFM
IRTFM

Reputation: 263301

Two concerns I have. In the help page for Surv I see this sentence: "The time,time2 and event arguments are matched by position, not by name, so use, eg, Surv(time, dead) rather than Surv(time, event=dead)". Which solves the first problem I had with your code by dropping the event argument in the call:

f1 <- survfit(Surv(time=time, censor) ~1, data=df1)

But then I was expecting to find that was a fit object, i.e. a list, and I was not surprised that quantile objected:

> quantile(f1)
Error in approx(c(0, 1 - newy), c(0:length(newy)), p) : 
  need at least two non-NA values to interpolate

So did you want:

> quantile(f1$time)
  0%  25%  50%  75% 100% 
   6   14   21   44   62     # ???

Edit: Apparently sometime in the intervening 10 years there is now a quantile method for survfit objects and you now get.

> quantile(f1)
$quantile
25 50 75 
14 44 62 

$lower
25 50 75 
 6 14 44 

$upper
25 50 75 
NA NA NA 

Upvotes: 2

Related Questions