File: plot.surv.R

package info (click to toggle)
zelig 3.3-1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 30,800 kB
  • ctags: 470
  • sloc: sh: 81; makefile: 10
file content (100 lines) | stat: -rw-r--r-- 2,489 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
plot.surv <- function(x,duration,censor,type="line",
plotcensor=TRUE,plottimes=FALSE,int=c(0.025,0.975),...) {	
	
		s.out <- x
		nobj <- length(s.out)
		for (s in 1:nobj) {
		if (s==1) {
			survival <- s.out[[s]]$qi$survival
			survest <- c(1,apply(survival,2,mean))
	
			survest.lb <- apply(survival,2,function(X){quantile(X,int[1])})
	
			survest.ub <- apply(survival,2,function(X){quantile(X,int[2])})
	
			times <- as.numeric(colnames(survival))
	
			#plot(stepfun(times,survest),xlim=c(0,max(duration)),xlab=xlab,ylab=ylab,main=title)
			plot(times,survest[-1],type="n",xlim=c(0,max(duration)),
					...)
			ntimes <- length(times)-1
			for (t in 1:ntimes){
				u <- survest.ub[t]
				l <- survest.lb[t]
			if (type=="poly") {
				x <- c(times[t],times[t+1],times[t+1],times[t])
				y <- c(survest.ub[t],survest.ub[t+1],survest.lb[t+1],survest.lb[t])
				polygon(x,y,density=100,col="grey")
				}
			if (type=="line") {
					segments(times[t],u,times[t],l,col="grey",lwd=.5)
				}
			}
			if (type=="line"){
					t <- length(times)
					u <- survest.ub[t]
					l <- survest.lb[t]
					segments(times[t],u,times[t],l,col="grey",lwd=.5)
			}	

		}
		if (s>1){
			survival <- s.out[[s]]$qi$survival
			survest <- c(1,apply(survival,2,mean))
	
			survest.lb <- apply(survival,2,function(X){quantile(X,int[1])})
	
			survest.ub <- apply(survival,2,function(X){quantile(X,int[2])})
	
			times <- as.numeric(colnames(survival))
	
			#lines(times,survest[-1],type="s")
	
			ntimes <- length(times)-1
			for (t in 1:ntimes){
				u <- survest.ub[t]
				l <- survest.lb[t]
				
				if (type=="poly") {
				x <- c(times[t],times[t+1],times[t+1],times[t])
				y <- c(survest.ub[t],survest.ub[t+1],survest.lb[t+1],survest.lb[t])
				polygon(x,y,density=100,col="grey")
				}
				if (type=="line") {
					segments(times[t],u,times[t],l,col="grey",lwd=.5)
				}

			}
			if (type=="line"){
					t <- length(times)
					u <- survest.ub[t]
					l <- survest.lb[t]
					segments(times[t],u,times[t],l,col="grey",lwd=.5)
			}	

			
			}

				
		
	}
	
	for (s in 1:nobj) {
			survival <- s.out[[s]]$qi$survival
			survest <- c(1,apply(survival,2,mean))
	
			survest.lb <- apply(survival,2,function(X){quantile(X,0.025)})
	
			survest.ub <- apply(survival,2,function(X){quantile(X,0.975)})
	
			times <- as.numeric(colnames(survival))			
			if (plottimes){lines(stepfun(times,survest),lty=s)}
			else {lines(times,survest[-1],type="s",lty=s)}
			}
		if(plotcensor){
				rug(duration[censor==0])
			}
	}