[R] Extracting values from Surv function in survival package

CALUM POLWART po|c1410 @end|ng |rom gm@||@com
Thu May 16 15:15:27 CEST 2024


I don't think that gives the summary of event numbers without extra work.

library(survival)
fit <- survfit( Surv(time,status)~sex,data=lung)
summary(fit)$n.event

[1] 3 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 3 1 1 1 1 1 2
 [38] 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1
 [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1
[112] 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[149] 1 1


You can get something out using:

summary(fit)$table[,"events"]

sex=1 sex=2
  112    53


But there are sub-options in the summary that might work.

summary(fit, times =1022, extend=T)$n.event

[1] 112  53



times=1022 is the maximum time in the lung dataset (you will need your
maximum) and extend=T, extends the other curves to that data point allowing
totals for events at that data point



On Thu, 16 May 2024, 08:53 Göran Broström, <gb using ehar.se> wrote:

> Hi Dennis,
>
> look at the help page for summary.survfit, the Value n.event.
>
> Göran
>
> On 2024-05-15 22:41, Dennis Fisher wrote:
> > OS X
> > R 4.3.3
> >
> > Colleagues
> >
> > I have created objects using the Surv function in the survival package:
> >> FIT.1
> > Call: survfit(formula = FORMULA1)
> >
> >                                         n events median 0.95LCL 0.95UCL
> > SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0 18     13    345     156      NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1 13      5     NA     186      NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=2  5      5    168      81      NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3  1      1     22      NA      NA
> >
> > I am interested in extracting the “n” and “events” values.
> > “n” is easy:
> >> FIT.1[[1]]
> > [1] 18 13  5  1
> >
> > or
> >> FIT.1$n
> > [1] 18 13  5  1
> >
> > But I can’t figure out how to access “events”.
> >
> > str(FIT.1) provides no insights:
> > List of 17
> >   $ n        : int [1:4] 18 13 5 1
> >   $ time     : num [1:37] 45 106 107 124 152 156 170 176 319 371 ...
> >   $ n.risk   : num [1:37] 18 17 16 15 14 13 12 11 10 9 ...
> >   $ n.event  : num [1:37] 1 1 1 1 1 1 1 1 1 1 ...
> >   $ n.censor : num [1:37] 0 0 0 0 0 0 0 0 0 0 ...
> >   $ surv     : num [1:37] 0.944 0.889 0.833 0.778 0.722 ...
> >   $ std.err  : num [1:37] 0.0572 0.0833 0.1054 0.126 0.1462 ...
> >   $ cumhaz   : num [1:37] 0.0556 0.1144 0.1769 0.2435 0.315 ...
> >   $ std.chaz : num [1:37] 0.0556 0.0809 0.1022 0.1221 0.1414 ...
> >   $ strata   : Named int [1:4] 18 13 5 1
> >    ..- attr(*, "names")= chr [1:4] "SUBDATA$ARM=1, SUBDATA[,
> EXP.STRAT]=0" "SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1" "SUBDATA$ARM=2,
> SUBDATA[, EXP.STRAT]=2" "SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3"
> >   $ type     : chr "right"
> >   $ logse    : logi TRUE
> >   $ conf.int : num 0.95
> >   $ conf.type: chr "log"
> >   $ lower    : num [1:37] 0.844 0.755 0.678 0.608 0.542 ...
> >   $ upper    : num [1:37] 1 1 1 0.996 0.962 ...
> >   $ call     : language survfit(formula = FORMULA1)
> >   - attr(*, "class")= chr "survfit"
> >
> > If I could access:
> >                                         n events median 0.95LCL 0.95UCL
> > SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0 18     13    345     156      NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1 13      5     NA     186      NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=2  5      5    168      81      NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3  1      1     22      NA      NA
> > it should be easy to get “events”.
> >
> > Any thoughts?
> >
> > Dennis
> >
> > Dennis Fisher MD
> > P < (The "P Less Than" Company)
> > Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> > www.PLessThan.com
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list