[R] Surv object in data.frame and Design package

Heinz Tuechler tuechler at gmx.at
Thu Mar 16 12:46:36 CET 2006


Dear All,

there seems to be some strange influence of the Design package on
data.frame. If I build a data.frame containing a Surv object without
loading the package Design, the data frame is usable to coxph. If instead I
just load Design and build a data.frame afterwards, the naming of the Surv
object is different and it does not work with coxph.
(In my real application I loaded Design to use the ie.setup function.)
Even if I detach Design I cannot build a data.frame as before loading
Design. If I include the Surv object with the I() function it seems to
work, but then there appeare the problems discussed in the posting from
yesterday "Surv object in data.frame".
The problem is solvable, but I was surprised of the unexpected
difficulties, especially that detaching Design did not solve the problem.

Is it wrong to expect that R works after detaching a package as before
loading it?
Comments?

Thanks

Heinz Tüchler


## example
starttime <- c(0, 0, 1.5, 0, 2.5)
stoptime  <- c(1, 1.5, 2, 2.5, 3)
event     <- c(1, 0, 1, 0, 0)
ie.status <- c(0, 0, 1, 0, 1)
library(survival)
survobj <- Surv(starttime, stoptime, event)
df.nodesign <- data.frame(survobj, ie.status) # build df without loading
Design
df.nodesign

library(Design)
df.design <- data.frame(survobj, ie.status) # build df after loading Design
df.design
all.equal(df.nodesign, df.design)
detach(package:Design)
detach(package:survival)
df.afterdesign <- data.frame(survobj, ie.status) # building df after
detaching Design
df.afterdesign
library(survival)
rm(survobj, ie.status)
coxph(survobj~ie.status, data=df.nodesign) # works
coxph(survobj~ie.status, data=df.design) # doesn't works
coxph(survobj~ie.status, data=df.afterdesign) # doesn't works


Windows98 SE
Version 2.2.0 Patched (2005-10-31 r36100)




More information about the R-help mailing list