annotate survival/survival.R @ 16:53dff79c833b draft

Uploaded
author testtool
date Mon, 02 Oct 2017 08:23:18 -0400
parents 744cf0f4d1b1
children b4d7a110dd32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
5b70a33bf327 Uploaded
testtool
parents: 0
diff changeset
1 require(survival, quietly = TRUE)
0
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
2 args <- commandArgs(trailingOnly = TRUE)
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
3
4
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
4 input = args[1]
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
5 type = args[2]
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
6 error = args[3]
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
7 conf.type = args[4]
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
8 conf.lower = args[5]
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
9 fit = args[6]
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
10 png = args[7]
0
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
11
4
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
12 tofit <- survival::survfit(Surv(obsT, status) ~ X1, type = type, error = error, conf.type = conf.type , conf.lower = conf.lower, data = read.csv(input))
0
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
13
2
ce6df2bd21cd Uploaded
testtool
parents: 1
diff changeset
14 res <- summary(tofit,times=c(1,2,3))
0
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
15 save.df <- as.data.frame(res[c("strata", "time", "n.risk", "n.event", "surv", "std.err", "lower", "upper")])
2
ce6df2bd21cd Uploaded
testtool
parents: 1
diff changeset
16 write.csv(save.df, fit)
0
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
17
2
ce6df2bd21cd Uploaded
testtool
parents: 1
diff changeset
18 png(png)
4
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
19 plot(tofit,xlab="Survival (days)", ylab="Survival", lwd=2,xlim=c(0,1900),ylim=c(0.3,1),col=c("red","blue"))
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
20 legend("topright",legend=c("low","high"),lty=c(1,1),
744cf0f4d1b1 Uploaded
testtool
parents: 2
diff changeset
21 lwd=c(2.5,2.5),col=c("red","blue"))
0
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
22 dev.off()
6cc0c5eb71b2 Uploaded
testtool
parents:
diff changeset
23