Pregunta

I use R's survival package and generated a survfit object with different groups.

I know want to access the number of events (which is records - right censored) for each group.

When I use print(survobject) there is a column events which shows the number of events for each group. However, I don't succeed to extract this column for instance as a vector.

¿Fue útil?

Solución

As example used data from library survival help page. Using function print() on survfit object prints part of the all summary.survfit() object.

library(survival)
print(survfit( Surv(futime, fustat)~rx, data=ovarian))
Call: survfit(formula = Surv(futime, fustat) ~ rx, data = ovarian)

     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

If we save the summary() object and look at the structure of it, there is an element table.

gg<-summary(survfit( Surv(futime, fustat)~rx, data=ovarian))
 str(gg)
List of 15
 $ n        : int [1:2] 13 13
 $ time     : num [1:12] 59 115 156 268 329 431 638 353 365 464 ...
 $ n.risk   : num [1:12] 13 12 11 10 9 8 5 13 12 9 ...
 $ n.event  : num [1:12] 1 1 1 1 1 1 1 1 1 1 ...
 $ n.censor : num [1:12] 0 0 0 0 0 0 0 0 0 0 ...
 $ surv     : num [1:12] 0.923 0.846 0.769 0.692 0.615 ...
 $ type     : chr "right"
 $ strata   : Factor w/ 2 levels "rx=1","rx=2": 1 1 1 1 1 1 1 2 2 2 ...
 $ std.err  : num [1:12] 0.0739 0.1001 0.1169 0.128 0.1349 ...
 $ upper    : num [1:12] 1 1 1 0.995 0.946 ...
 $ lower    : num [1:12] 0.789 0.671 0.571 0.482 0.4 ...
 $ conf.type: chr "log"
 $ conf.int : num 0.95
 $ call     : language survfit(formula = Surv(futime, fustat) ~ rx, data = ovarian)
 $ table    : num [1:2, 1:7] 13 13 13 13 13 13 7 5 638 NA ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:2] "rx=1" "rx=2"
  .. ..$ : chr [1:7] "records" "n.max" "n.start" "events" ...
 - attr(*, "class")= chr "summary.survfit"

Element table contains the same information you get with print(). So event values can be accessed just by selecting column you are interested in.

gg$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

gg$table[,4]
rx=1 rx=2 
   7    5 

Otros consejos

str( Surv(heart$start, heart$stop, heart$event)[1:10, 1:3] )
#-----------------------------
 labelled [1:10, 1:3] 0 0 0 1 0 36 0 0 0 51 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:3] "start" "stop" "status"
 - attr(*, "units")= chr "Day"

These are the times:

 Surv(heart$start, heart$stop, heart$event)[1:10, "stop"]
# [Day] 
# [1]  50   6   1  16  36  39  18   3  51 675
 Surv(heart$start, heart$stop, heart$event)[1:10, "start"]
# [Day] 
# [1]  0  0  0  1  0 36  0  0  0 51

So if you want the times associated with events you just:

> Surv(heart$start, heart$stop, heart$event)[ , "stop"][ Surv(heart$start, heart$stop, heart$event)[ , "status"] == 1]
 [Day] 
 [1]   50    6   16   39   18    3  675   40   85   58  153    8   81 1387    1  308   36
[18]   43   37   28 1032   51  733  219  263   72   35  852   16   77   12  100   66    5
[35]   53    3    2   40   45  996   72    9  980  285  102  188    3   61  149  343   68
[52]    2   69  584   78   32  285   68   30   90   17    2   21   96   80  334    5  110
[69]  207  186  340  165   16   21    6

Or to get the number just sum the event markers:

 sum( Surv(heart$start, heart$stop, heart$event)[ , "status"] == 1)
[1] 75

And to tabulate by a potential covariate:

> with(lung, table(Surv(time, status)[, "status"], ph.ecog ))
   ph.ecog
     0  1  2  3
  0 26 31  6  0
  1 37 82 44  1
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top