At 09:23 15.03.2006 -0800, Thomas Lumley wrote: >On Wed, 15 Mar 2006, Heinz Tuechler wrote: > >> Dear All, >> >> a Surv object I put in a data frame behaves somehow unexpected (see example). >> If I do a Cox regression on the original Surv object it works. If I put it >> in a data.frame and do the regression on the data frame it does not work. >> Seemingly it has to do with the class attribute, because if I change the >> class attribute to let "Surv" appeare first, again it works. >> Is this known? Should I have found information on it? > >Well, this is the sort of thing that happens when you use kludges like >AsIs. > >The problem is with [.AsIs > survobj[,1] is supposed to be a vector of times (that's what [.Surv >returns), but [.AsIs sticks the original class attribute on to it. > >> str(survobj[,1]) > num [1:5] 0 0 0 0 0 >> str(I(survobj)[,1]) >Classes 'AsIs', 'Surv' num [1:5] 0 0 0 0 0 > >The solution is not to use I() -- there's no problem with putting survival >objects in a data frame >> df.right<-data.frame(survobj,group) >> df.right > survobj group >1 (0,1 ] 1 >2 (0,2+] 1 >3 (0,3 ] 1 >4 (0,4 ] 2 >5 (0,5 ] 2 > > > -thomas
Thank you, Thomas. You are right, it works, but why then I find on the help page for Surv{survival} the following sentence: "To include a survival object inside a data frame, use the I() function. Surv objects are implemented as a matrix of 2 or 3 columns." Heinz ______________________________________________ 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