[R] Median In Survival

Marc Schwartz marc_schwartz at me.com
Thu Feb 23 05:18:43 CET 2012


On Feb 22, 2012, at 7:47 PM, David Winsemius wrote:

> 
> On Feb 22, 2012, at 6:59 PM, niloo javan wrote:
> 
>> hi
>> I have a problem with  Median in Survival.
>> when I use
>> S1=survfit(Surv(Time,Status))
>> the result shows the median but I cannot use it as numeric!
>> S1$median in Null
> 
> That does not look like a formula.

Yeah, the OP is missing the '~ 1' part:

  survfit(Surv(Time, Status) ~ 1, data = ...)

> 
> Furthermore I do not think there is an element in a survfit.object named 'median'. (It's certainly not documented on the help pages.)  Objects are passed to their print methods and the `print.survfit` function passes off its data argument first to `survmean`, then to `pfun`, then to `minmin` which does the job of calculating a median, which print.survfit then prints (as a side-effect using `cat`), but never stores in a returned object.
> 
> Is this is homework?



Perhaps, but the information is available from ?summary.survfit, where the Value section indicates that the returned object includes a 'table' component:

> summary(survfit(Surv(futime, fustat) ~ 1, data = ovarian))$table
records   n.max n.start  events  median 0.95LCL 0.95UCL 
     26      26      26      12     638     464      NA 

> RES <- summary(survfit(Surv(futime, fustat) ~ 1, data = ovarian))$table

> RES["median"]
median 
   638 

> RES["0.95LCL"]
0.95LCL 
    464 

> RES["0.95UCL"]
0.95UCL 
     NA 


This will be a matrix rather than a vector, if the analysis consists of RHS covariates:

> summary(survfit(Surv(futime, fustat) ~ rx, data = ovarian))$table
     records n.max n.start events median 0.95LCL 0.95UCL
rx=1      13    13      13      7    638     268      NA
rx=2      13    13      13      5     NA     475      NA

...

> RES[, "median"]
rx=1 rx=2 
 638   NA 


If memory serves, the 'table' component was added about three years ago, as previously, one would have to use capture.output() on the result of explicitly using print.survfit() and then parse the textual results to get the median and CI's. It was one of those 'infelicities' in using these functions where the print method included code to calculate new values, rather than simply printing the results derived in the core function.

HTH,

Marc Schwartz



More information about the R-help mailing list