Paul Miller
2013-Apr-15 16:31 UTC
[R] Convert results from print(survfit(formula, ...)) into a matrix or data frame
Hello All, Below is some sample survival analysis code. I'd like to able to get the results from print(gehan.surv) into a matrix or data frame, so I can manipulate them and then create a table using odfWeave. Trouble is, I'm not quite sure how make such a conversion using the results from a print method. Is there some simple way of doing this? Thanks, Paul require(survival) require(MASS) attach(gehan) gehan.surv <- survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = "log-log") print(gehan.surv)
Marc Schwartz
2013-Apr-15 16:51 UTC
[R] Convert results from print(survfit(formula, ...)) into a matrix or data frame
On Apr 15, 2013, at 11:31 AM, Paul Miller <pjmiller_57 at yahoo.com> wrote:> Hello All, > > Below is some sample survival analysis code. I'd like to able to get the results from print(gehan.surv) into a matrix or data frame, so I can manipulate them and then create a table using odfWeave. Trouble is, I'm not quite sure how make such a conversion using the results from a print method. > > Is there some simple way of doing this? > > Thanks, > > Paul > > require(survival) > require(MASS) > > attach(gehan) > gehan.surv <- survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = "log-log") > print(gehan.surv) >Hi Paul, If I am correctly understanding the output that you want to save, which is the summary results table output:> gehan.survCall: survfit(formula = Surv(time, cens) ~ treat, data = gehan, conf.type = "log-log") records n.max n.start events median 0.95LCL 0.95UCL treat=6-MP 21 21 21 9 23 13 NA treat=control 21 21 21 21 8 4 11 You can use:> summary(gehan.surv)$tablerecords n.max n.start events median 0.95LCL 0.95UCL treat=6-MP 21 21 21 9 23 13 NA treat=control 21 21 21 21 8 4 11> str(summary(gehan.surv)$table)num [1:2, 1:7] 21 21 21 21 21 21 9 21 23 8 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:2] "treat=6-MP" "treat=control" ..$ : chr [1:7] "records" "n.max" "n.start" "events" ... See ?summary.survfit and note the 'table' part of the Value section. Regards, Marc Schwartz
Possibly Parallel Threads
- odfWeave: Some questions about potential formatting options
- median survival time from survfit
- Incorrect 'n' returned by survfit()
- Obtaining value of median survival for survfit function to use in calculation
- Kaplan Meier analysis: 95% CI wider in R than in SAS