-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRAINmultiComparison.R
148 lines (100 loc) · 4.34 KB
/
TRAINmultiComparison.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
############ Ground Truth on TRAINING DATA ###################################
##############################################################
###########
### K-means + Penalized CoxPH
### K-means + Penalized AFT
### FlexMix + CoxPH
### FlexMix + AFT
### iCLUSTER
### k CCA
### kmean sparse CCA
multigroundtruth = function(){
Y <- cbind(Y1,Y2)
D <- D1 + D2
smod <- Surv(exp(time), censoring)
############ No CLUSTERING INFORMATION ############################################
##### Both Data Sets put together
### Fitting A Penalized Cox Proportional Hazard's Model
reg.pcox <- cv.glmnet(x = Y, y = smod, family = "cox")
lp <- predict(object =reg.pcox, newx = Y, s= "lambda.min")
cindex.pcox <- survConcordance(smod ~lp)[1]
cindex.pen.cox <<- as.numeric(cindex.pcox)
#### Fitting A AFT Model
reg <- cv.glmnet(x = Y, y = time, family = "gaussian")
linear.aft <- predict(object = reg, newx = Y, s = "lambda.min")
cindex.paft <- survConcordance(smod ~ exp(-linear.aft))[1]
cindex.pen.aft <<- as.numeric(cindex.paft)
#############################################
########### K-means #########################
#############################################
#############################################
gr.km <- kmeans(Y, F, nstart =10)
gr.km.rand <- adjustedRandIndex(c.true,as.factor(gr.km$cluster))
################# Combined Data Set ########################
cindex.km.pcox <-0
cindex.km.paft <- 0
######## Penalized Cox PH ###########################################
linear.pred <- c(0)
for ( q in 1:F){
ind <- which((gr.km$cluster) == q)
time.tmp <- time[ind]
censoring.tmp <- censoring[ind]
Y.tmp <- Y[ind,]
coxreg <- list(0)
coxreg$x <- Y.tmp
coxreg$time <- exp(time.tmp)
coxreg$status <- censoring.tmp
reg.pcox <- cv.glmnet(x = Y.tmp, y = Surv(coxreg$time, coxreg$status), family = "cox")
linear.pred[ind] <- predict(object =reg.pcox, newx = Y.tmp, s= "lambda.min")
}
cindex.km.pcox <- survConcordance(smod ~ linear.pred)[1]
######## Penalized AFT ######################################################
linear.aft <- c(0)
for ( q in 1:F){
ind <- which((gr.km$cluster) == q)
L= length(ind)
time.tmp <- time[ind]
censoring.tmp <- censoring[ind]
Y.tmp <- Y[ind,]
reg <- cv.glmnet(x = Y.tmp, y = time.tmp, family = "gaussian")
linear.pred <- predict(object =reg, newx = Y.tmp, s= "lambda.min")
coeff.pred <- coef(object =reg, newx = Y.tmp, s= "lambda.min")
rel.coeff <- coeff.pred[2:(D+1)]
ind.rel <- which(rel.coeff !=0)
linear.aft[ind] <- predict(object = reg, newx = Y.tmp, s = "lambda.min")
}
cindex.km.paft <- survConcordance(smod ~ exp(-linear.aft))[1]
##### Save some Ground truth statistics
gr.km.rand.final <<- gr.km.rand
cindex.km.pcox.final <<- as.numeric(cindex.km.pcox)
cindex.km.paft.final <<- as.numeric(cindex.km.paft)
#################################################################################
##############################################################################
############### FlexMix #######################################################
################################################################################
gr.flx <- flexmix(time ~ Y, k =F)
gr.flx.rand <- adjustedRandIndex(c.true,clusters(gr.flx))
########## CoxPH #############################
fit.cox.flx <- coxph(smod ~ Y[,1:D]*strata(as.factor(clusters(gr.flx))), data = as.data.frame(Y))
## C-Index
cindex.flx.cox <- survConcordance(smod ~ predict(fit.cox.flx))[1]
## Brier Score
fit.coxph <- survfit(fit.cox.flx, newdata = as.data.frame(Y[,1:D]))
gr.flx.rand.final <<- gr.flx.rand
cindex.flx.cox.final <<- as.numeric(cindex.flx.cox)
############## Using iCluster #######
datas <- list(0)
datas[[1]] <- Y1
datas[[2]] <- Y2
cv.fit <- tune.iCluster2(datas, k)
fit <- iCluster2(datas, k= k, lambda= cv.fit$best.fit$lambda)
randindexiCLUSTER <<- adjustedRandIndex(fit$clusters,c.true)
########### Using CCA ################
fit.cc <- cc(Y1, Y2)
y1 <- fit.cc$scores$xscores
y2 <- fit.cc$scores$yscores
f <- length(which(fit.cc$cor > 0.5))
Y.CCA <- cbind(y1[,1:f],y2[,1:f])
km <- kmeans(Y.CCA, centers =k, nstart =10)
randindexCCA <<- adjustedRandIndex(c.true,as.factor(km$cluster))
}