[R] Passing arguments to panels in trellis plots
Marco Chiarandini
marco at imada.sdu.dk
Wed Dec 13 23:53:30 CET 2006
Dear Deepayan,
> Since you haven't bothered to follow the posting guide at all, it took
> me a while to figure out that you live in that alternate R universe
> created by Prof Harrell. Can't help you there, but in the standard
> universe, things seem fairly simple:
I am sorry for not having been clear. I hope this time I get closer to
the correct post practice.
Here is what I am trying to do:
D <- expand.grid(rep=c(1:10),b=c("M","N"),a=c("10","20"),alg=c("A","B"))
D1 <- data.frame(D[,c(2,3,4)],time=runif(80,1,100))
D2 <- data.frame(D1,event=rbinom(80,1,0.9))
library(survival)
library(lattice)
library(Hmisc)
Ecdf(~time | a*b, groups=alg,data=D2,
subscripts=TRUE,
panel=function(x,groups,subscripts)
{
t <-
survfit(Surv(time[subscripts],event[subscripts])~groups[subscripts],
data=D2,type="kaplan-meier",
conf.type="plain",conf.int=.95, se.fit=T)
panel.xyplot(t[2]$time,1-t[2]$surv,type="s",lty=2)
panel.xyplot(t[1]$time,1-t[1]$surv,type="s",lty=1)
}
)
Although not very elegant this does the job. Nevertheless, when I try to
add:
scales = list(log=TRUE)
in the Ecdf fucntion above I incurr in problems because the
transformation of data occurs before applying the function Surv.
Hence my question, is there a way to plot survfit in trellis plots with
different strata (the alg factor above) in the same plot and conditional
to combination of other factors (the a and b factors above)?
Here is my sessionInfo():
R version 2.4.0 (2006-10-03)
i686-pc-linux-gnu
locale:
LC_CTYPE=en_DK.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
attached base packages:
[1] "grid" "splines" "methods" "stats" "graphics"
"grDevices"
[7] "utils" "datasets" "base"
other attached packages:
Hmisc lattice survival
"3.1-2" "0.14-9" "2.29"
Regards,
- Marco.
--
Marco Chiarandini http://www.imada.sdu.dk/~marco
Department of Mathematics Email: marco at imada.sdu.dk
and Computer Science, Phone: +45 6550 4031
University of Southern Denmark Fax: +45 6593 2691
More information about the R-help
mailing list