[R] simple save question

David Winsemius dwinsemius at comcast.net
Wed Jul 13 05:05:36 CEST 2011


On Jul 12, 2011, at 5:43 PM, Tom La Bone wrote:

> Thank you for the reply Dr. Winsemius. Can you take your answer a step
> further and, in the context of the simple, reproducible example,  
> illustrate
> how it is done? I would appreciate it.
>
> Tom


The easy way is:

 > sfit <- summary(fit)
 > sfit$table[ , 5]
     rx=1     rx=2
649.6000 888.5983


Before reading Therneau's answer again I did not realize that the  
`table` sub-object of summary(fit)  was where to look because str()  
does not give  the names of matrix columns beyond the third entry. I  
see that I also failed to read for understanding the material that I  
had copied from help(print.survfit). So I had already gone through the  
code of multiple functions in order to find this material:

The code in print.summary.survfit that results in the screen output is

#--- code extract--------
  temp <- survmean(x, scale = scale, rmean)
     print(temp$matrix)
     if (rmean != "none") {
         if (rmean == "individual")
             cat("   * restricted mean with variable upper limit\n")
         else cat("    * restricted mean with upper limit = ",
             format(temp$end.time[1]), "\n")
# ---- end extract-------

 > survival::survmean(fit, rmean="individual")
Error: 'survmean' is not an exported object from 'namespace:survival'
# So OK, "::" didn't work, so use ":::"

 > survival:::survmean(fit, rmean="individual")
$matrix
      records n.max n.start events   *rmean *se(rmean) median 0.95LCL  
0.95UCL
rx=1      13    13      13      7 649.6000   120.1388    638      
268      NA
rx=2      13    13      13      5 888.5983   115.3327     NA      
475      NA

$end.time
[1] 1106 1227

 > str(survival:::survmean(fit, rmean="individual") )
List of 2
  $ matrix  : num [1:2, 1:9] 13 13 13 13 13 ...
   ..- attr(*, "dimnames")=List of 2
   .. ..$ : chr [1:2] "rx=1" "rx=2"
   .. ..$ : chr [1:9] "records" "n.max" "n.start" "events" ...
  $ end.time: num [1:2] 1106 1227

 > survival:::survmean(fit, rmean="individual")$matrix[ ,5]
     rx=1     rx=2
649.6000 888.5983

Heh, the hard way.

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list