Mercurial > repos > testtool > survival
comparison survival/survival.R @ 2:ce6df2bd21cd draft
Uploaded
author | testtool |
---|---|
date | Fri, 29 Sep 2017 18:41:35 -0400 |
parents | 5b70a33bf327 |
children | 744cf0f4d1b1 |
comparison
equal
deleted
inserted
replaced
1:5b70a33bf327 | 2:ce6df2bd21cd |
---|---|
3 | 3 |
4 input =args[1] | 4 input =args[1] |
5 fit = args[2] | 5 fit = args[2] |
6 png = args[3] | 6 png = args[3] |
7 | 7 |
8 #fit a Kaplan-Meier and plot it | 8 tofit <- survival::survfit(Surv(obsT, status) ~ X1, type="kaplan-meier", conf.type="log", data=read.csv(input)) |
9 input<-("test-data/input.csv") | |
10 fit <- survival::survfit(Surv(obsT, status) ~ X1, type="kaplan-meier", conf.type="log", data=read.csv(input)) | |
11 | 9 |
12 res <- summary(fit,times=c(1,2,3)) | 10 res <- summary(tofit,times=c(1,2,3)) |
13 save.df <- as.data.frame(res[c("strata", "time", "n.risk", "n.event", "surv", "std.err", "lower", "upper")]) | 11 save.df <- as.data.frame(res[c("strata", "time", "n.risk", "n.event", "surv", "std.err", "lower", "upper")]) |
14 write.csv(save.df, file = "survfit.csv") | 12 write.csv(save.df, fit) |
15 | 13 |
16 png("fit.png") | 14 png(png) |
17 plot(fit) | 15 plot(tofit) |
18 dev.off() | 16 dev.off() |
19 | 17 |