[R] Sorting Surv objects
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Feb 12 19:57:28 CET 2015
On 12/02/2015 16:26, Professor Bickis wrote:
> It seems that Surv objects do not sort correctly. This seems to be a bug. Anyone else found this?
This is presumably about Surv() from package survival, not mentioned.
There was a bug, corrected in R-devel (and I will port to R-patched
before 3.1.3).
However, sorting censored survival events is a matter of definition (in
?xtfrm but cross-referenced from ?sort) and the definition chosen is not
that of lifetimes (as deaths at T sort after those alive at T and so
lived longer).
>> survival.data
> [1] 4+ 3 1+ 2 5+
Please follow the posting guide and give a reproducible example.
library(survival)
d <- Surv(c(2,1,4,3,5), c(1,0,1,0,1))
> d
[1] 2 1+ 4 3+ 5
> sort(d)
[1] 1+ 2 3+ 4 5
in R-devel. But
> sort(Surv(c(2,2,4,3,5), c(1,0,1,0,1)))
[1] 2+ 2 3+ 4 5
>> class(survival.data)
> [1] "Surv"
>> sort(survival.data)
> [1] 2 1+ 4+ 3 5+
>
> An easy work-around is to define a function sort.Surv
>
> sort.Surv<-function(a){ord<-order(a[,1])
> + a[ord]}
>
>> sort(survival.data)
> [1] 1+ 2 3 4+ 5+
>
> I am using R 3.1.2 GUI 1.65 Mavericks build (6833) running under Yosemite.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK
More information about the R-help
mailing list