[R] using survfit
Daniel Malter
daniel at umd.edu
Tue Oct 30 03:09:49 CET 2007
Hi, you may look here http://www.ats.ucla.edu/stat/examples/asa/ to find an
answer to your question. Basically you have to overlay one graph with the
points (lines) that you want to add. Otherwise, R replaces the old graph by
the new and does not add it as far as I know.
Cheers,
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von David Winsemius
Gesendet: Monday, October 29, 2007 8:15 PM
An: r
Betreff: Re: [R] using survfit
raymond chiruka wrote:
> hie
> when i use plot.survfit to plot more than one graph why I only see
> the last graph how do i see the other graphs.for example
>
> n=20
> n1=n/2
> n2=n/4
> a11=4;a12=4 ;a21=4 ;a22=4
> t1<-array(1,c(n1))
> t2<-array(2,c(n1))
> treatgrp=matrix(c(t1,t2))
> st11<-array(1,c(n2))
> st12<-array(2,c(n2))
> st21<-array(1,c(n2))
> st22<-array(2,c(n2))
> strata=matrix(c(st11,st12,st21,st22))
> time11=array(rweibull(n2,a11,1))
> time12=array(rweibull(n2,a11,1))
> time21=array(rweibull(n2,a21,1))
> time22=array(rweibull(n2,a22,1))
> time=matrix(c(time11, time12, time21, time22))
> censorTime=runif(n,0,3)
> m=cbind(treatgrp,strata,time,censorTime)
> colnames(m)=c(treat,strata,time,censorTime)
>
My version of R (2.4.1 on a WindozeXP machine) had problems with the
"smart-quotes" when cut and pasted but I cannot be sure that was not a
problem induced by Thunderbird.
>
> act.surv.time<-pmin(m[,"time"],m[,"censorTime"])
>
> m<-cbind(m,act.surv.time)
> m<-cbind(m,0)
> m[m[,3]<m[,4],6]<-1
> colnames(m)[6]<-"censoring"
> m
> b=data.frame(m)
>
> d2=survfit(Surv(act.surv.time,censoring)~treatgrp,data=b,type=c("flemi
> ng-harrington"),
>
> )
>
> plot(d2, lty=2:3, fun="cumhaz",
>
> xlab="Months", ylab="Cumulative Hazard")
>
It plotted just fine. And you then over-wrote it with the second plot.
You could save (temporarily) a screen plot with > surv.crv<-recordPlot()
### then make another plot, save it too.
### then use
> replayPlot(surv.crv)
You could also save to a file and view in an external viewer. The format of
recorded plots is not guaranteed to be the same from version to version.
Another option (which would be machine specific and assuming a Windows
device) would be to open second screen window with:
> win.graph(width = 7, height = 7, pointsize = 12, restoreConsole = FALSE)
>
> d1=survfit(Surv(act.surv.time,censoring)~treatgrp,data=b,)
>
> plot(d1, lty=2:3,
>
> xlab="Months", ylab="survival curves")
>
> I only see the plot of d1 what happens to d2 and how do l view it.
> thanks
>
If you opened a new device before each plot you could paper your screen with
plots.
--
David Winsemius
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list