Re: [R] How to access results of survival analysis

From: Prof Brian D Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 08 May 2006 - 18:07:48 EST

The solution is to use a separate function to do this (and call it from the print method).

On Mon, 8 May 2006, Heinz Tuechler wrote:

> At 12:55 07.05.2006 +0100, Prof Brian Ripley wrote:

>> On Sun, 7 May 2006, Heinz Tuechler wrote:
>>
>>> Hello Xiaochun Li!
>>>
>>> Thank you for submitting the function. At the time I had that problem I
>>> solved it in a somewhat different way.
>>> I changed a few lines in the print.survfit method. I introduced a parameter
>>> "ret.res=FALSE" set to false to preserve the normal behaviour of print.
>>> The second last line "invisible(x)" I changed to:
>>>
>>> if (ret.res)
>>> 	invisible(list(x,x1))
>>> else
>>> 	invisible(x)
>>>
>>> So print.survfit returned the results. Of course, Your method has the
>>> advantage to work as long as the output structure of print.survfit does not
>>> change. At the end I would prefer the original function to be changed and
>>> when I find the time I will submit a worked proposal to Thomas Lumley, the
>>> maintainer of the survival package. In that way it would be available also
>>> in future versions of survival.
>>
>> But all print() methods are required to return their first argument
>> unchanged, so
>>
>> foo
>> print(foo)
>>
>> do the same thing.  See ?print.
>>
>> --
>> Brian D. Ripley,                  ripley@stats.ox.ac.uk
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford,             Tel:  +44 1865 272861 (self)
>> 1 South Parks Road,                     +44 1865 272866 (PA)
>> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>>
>

> I see that my proposal is against the rules.
> So what would be a correct solution? Using the (expanded) example from
> Xiaochun Li, you see that print(fit1) does not _simply_ print its first
> argument, but calculates the median and its confidence interval.
> What would be the correct way to access these values?
>

> # example:
>

> library(survival)
>

> fit1 <- survfit(Surv(time, status) ~ 1, data=aml)
> print(fit1)
>

> Call: survfit(formula = Surv(time, status) ~ 1, data = aml)
>

> n events median 0.95LCL 0.95UCL
> 23 18 27 18 45
>> >
> smed <- function(x) {
> ox <- capture.output(print(x))
> n <- length(ox)
> tmp <- t(sapply(ox[4:n],
> function(l) strsplit(l, split=' +')[[1]]))
> nres <- strsplit(ox[3],split=' +')[[1]][2:6]
> res <- matrix(as.numeric(tmp[,2:6]), ncol=5,
> dimnames=list(tmp[,1], nres))
> res
> }
>

> sf1 <- smed(fit1)
> sf1
>

> Lacking experience in R-programming, my personal opinion is that
> calculations like the median and the confidence interval should not be only
> side effects of a print command but accessible result objects of a
> corresponding function.
>

> Heinz Tüchler
>
>
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


______________________________________________

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon May 08 22:30:42 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 09 May 2006 - 00:10:01 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.