Skip to content

Passing arguments to panels in trellis plots

4 messages · Marco Chiarandini, Deepayan Sarkar

#
Dear all,

I am trying to produce survfit plots in a trellis environment and I
would like the plots to be logarithmic.

I am trying this:

print(Ecdf(~time | size*type, groups=alg,data=B,subscripts=TRUE,
            panel=function(x,groups,subscripts)
            {
              t <- survfit(Surv(time[subscripts],event[subscripts])~groups[subscripts],data=B)
              panel.xyplot(t[1]$time,1-t[1]$ssurv,type="s",lty=2)
              panel.xyplot(t[2]$time,1-t[2]$ssurv,type="s",lty=2)
            },
 	   scale=list(log=TRUE)
)



but data are transformed in logarithm before being passed to the panel
and hence the output of the function survfit is not the expected one.

Is there a way to plot this correctly, ie, having first the survfit
computed and then the plot, like in:

plot(survfit(Surv(time,event)~groups,data=B),log=true)

Thanks in advance.

- 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
#
On 12/13/06, Marco Chiarandini <marco at imada.sdu.dk> wrote:
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:


library(survival)

fm <- survfit(Surv(time, status) ~ x, data=aml)

xyplot(surv ~ time, data = fm, type = "s",
       groups = rep(names(strata), strata))

xyplot(surv ~ time, data = fm, type = "s",
       groups = rep(names(strata), strata),
       scales = list(log = TRUE))

xyplot(surv + lower + upper ~ time | rep(names(strata), strata),
       data = fm, type = "s",
       scales = list(y = list(log = TRUE)))

-Deepayan
#
Dear Deepayan,
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
#
On 12/13/06, Marco Chiarandini <marco at imada.sdu.dk> wrote:
Yes, that's a feature of lattice.
Not if you insist on using 'scales = list(log = TRUE)' to specify log
scales. Use a different argument that gets passed to the panel
function, and then use it in the panel function. I suspect you are
using Ecdf simply to get a probability scale on the y-axis; the proper
way to specify data-based limits is to write a prepanel function, as
explained in ?xyplot.

-Deepayan