-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplsr_cox.R
75 lines (59 loc) · 2.05 KB
/
plsr_cox.R
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
library(plsRcox)
library(survival)
library(survivalROC)
library(Hmisc)
library(survcomp)
plsR_cox <- function(x.train,fold){
set.seed(4321)
cv.plsRcox.res=cv.plsRcox(list(x=x.train[,3:ncol(x.train)],
time=x.train$time,
status=x.train$status),
nfold = 5,
nt=10,
verbose = FALSE)
fit <- plsRcox(x.train[,3:ncol(x.train)],
time=x.train$time,
event=x.train$status,
nt=as.numeric(cv.plsRcox.res[5]))
pred_pls <- predict(fit,type="lp",newdata=x.test[,-c(1,2)])
pred_pls <- as.numeric(pred_pls)
cindex_pls = 1-rcorr.cens(pred_pls,Surv(t.test, s.test))[[1]]
print(sprintf("plscox_%d",fold))
print(cindex_pls)
result <- list()
result$best_param =list(nt=as.numeric(cv.plsRcox.res[5]))
result$model = fit
result$cindex = cindex_pls
result$pred = pred_pls
### auc km ###
cutoff = 12*1
if ( min(x.test$time) < cutoff )
{
y <- survivalROC(Stime = t.test, status = s.test, marker = pred_pls,
predict.time = cutoff, method = "KM")
result$km_fp_1 = y$FP
result$km_tp_1 = y$TP
result$km_auc_1 = y$AUC
}else
{
result$km_fp_1 = NA
result$km_tp_1 = NA
result$km_auc_1 = NA
}
cutoff=12*3
y <- survivalROC(Stime = t.test, status = s.test, marker = pred_pls,
predict.time = cutoff,method = "KM")
result$km_fp_3 = y$FP
result$km_tp_3 = y$TP
result$km_auc_3 = y$AUC
cutoff=12*5
y <- survivalROC(Stime = t.test, status = s.test, marker = pred_pls,
predict.time = cutoff,method = "KM")
result$km_fp_5 = y$FP
result$km_tp_5 = y$TP
result$km_auc_5 = y$AUC
dd_ext <- data.frame("time"=x.test$time, "event"=x.test$status, "score"= pred_pls)
Brier_score <- survcomp::sbrier.score2proba(data.tr=dd_ext, data.ts=dd_ext, method="cox")
result$brier_Score <- Brier_score
save("result", file = sprintf("%d_plsRcox_result.RData", fold))
}