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
| process_surfit <- function(covariate, color){
covariate <- deparse(substitute(covariate)) # 取得變數名稱字串
if(color==1){
survfit(as.formula(paste("Surv(agepn, hospital) ~", covariate)), data = pneumon) %>%
plot( col = c("blue"), lty = 1,
xlab = "agepn", ylab = "Survival Probability",
main = "Survival Curves",
ylim = c(0.9, 1))
}
else if(color==2){
survfit(as.formula(paste("Surv(agepn, hospital) ~", covariate)), data = pneumon) %>%
plot( col = c("blue", "red"), lty = 1,
xlab = "agepn", ylab = "Survival Probability",
main = paste("Survival Curves by", covariate),
ylim = c(0.9, 1),
conf.int = FALSE)
legend("bottomright", legend = c("0","1"),
col = c("blue", "red"), lty = 1,
title = covariate)
}
else if(color==3){
survfit(as.formula(paste("Surv(agepn, hospital) ~", covariate)), data = pneumon) %>%
plot( col = c("blue", "red", "purple"), lty = 1,
xlab = "agepn", ylab = "Survival Probability",
main = paste("Survival Curves by", covariate),
ylim = c(0.9, 1),
conf.int = FALSE)
legend("bottomright", legend = c("0","1","2"),
col = c("blue", "red", "purple"), lty = 1,
title = covariate)
}
else if(color==4){
survfit(as.formula(paste("Surv(agepn, hospital) ~", covariate)), data = pneumon) %>%
plot( col = c("blue", "red", "purple", "orange"), lty = 1,
xlab = "agepn", ylab = "Survival Probability",
main = paste("Survival Curves by", covariate),
ylim = c(0.9, 1),
conf.int = FALSE)
legend("bottomright", legend = c("0","1","2","3"),
col = c("blue", "red", "purple", "orange"), lty = 1,
title = covariate)
}
}
|