Skip to content

Extracting results from a function output

4 messages · Cem Girit, R. Michael Weylandt, William Dunlap +1 more

#
Assuming I'm reading your post correctly -- fit is the output object
and the lines following >fit are the console output, which implicitly
calls print -- it looks like the median isn't stored in fit but is
calculated on the fly in the print call. But this doesn't seem
consistent with your claim that:

"Print" function does not reveal them either.

Could you perhaps clarify your statement about print(fit)?

Cheers from Princeton!

Michael Weylandt
On Mon, Oct 17, 2011 at 11:13 AM, Cem Girit <girit at biopticon.com> wrote:
#
Often the summary() methods for the modelling functions
contain the kinds of details you are looking for.  Sometimes
there are special extractor functions but often not.
You have to study the help file for summary.<objectClass>
and the vignettes for the package, and perhaps do a little
experimentation to figure it out.

  > library(survival)
  > fit <- survfit(Surv(time, status) ~ x, data=leukemia)
  > fit
  Call: survfit(formula = Surv(time, status) ~ x, data = leukemia)
  
                  records n.max n.start events median 0.95LCL 0.95UCL
  x=Maintained         11    11      11      7     31      18      NA
  x=Nonmaintained      12    12      12     11     23       8      NA
  > summary(fit)$table[, "median"]
     x=Maintained x=Nonmaintained 
               31              23 
  > summary(fit)$table["x=Maintained", "median"]
  [1] 31


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
On Oct 17, 2011, at 11:13 AM, Cem Girit wrote:

            
I'm not sure what you mean when you say the "Print" function does not  
"reveal them".  For one thing the function is spelled "print" and for  
another thing I see the desired "48" in the output.

http://tolstoy.newcastle.edu.au/R/e6/help/09/05/15413.html

So the answer in your case is:

summary(fit)$table[1, ]