-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreeFoldValidation.tree.auc.sims.mcc.R
115 lines (113 loc) · 4.56 KB
/
threeFoldValidation.tree.auc.sims.mcc.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
#library(e1071)
library(rpart)
library(caret)
library(ROCR)
library(DescTools)
set.seed(100)
sim.res<-data.frame()
for (n in 1:500){
f<-paste("sim.cod.",n,".split",sep="")
load(f)
tr.sen = c()
tr.spe = c()
tr.acc = c()
tr.auc = c()
tr.mcc = c()
pdfc<-data.frame()
for (i in 1:3) {
d2.1=d2[d2$fold != i,]
d2.1$fold<-NULL
d2.2=d2[d2$fold == i,]
d2.2$fold<-NULL
m.tree<-rpart(CLASS ~ ET + EV + P + H + CP + CT + D, data=d2.1,method="class")
predictions = predict(m.tree, d2.2, type="class")
predictions2 = predict(m.tree, d2.2)
cm<-confusionMatrix(table(predictions,d2.2$CLASS))
tr.sen = append(cm$byClass['Sensitivity'], tr.sen)
tr.spe = append(cm$byClass['Specificity'], tr.spe)
tr.acc = append(cm$overall['Accuracy'], tr.acc)
pa<-predictions
pa<-gsub("rep","TRUE", pa)
pa<-gsub("non","FALSE", pa)
ta<-d2.2$CLASS
ta<-gsub("rep","TRUE", ta)
ta<-gsub("non","FALSE", ta)
mccv<-mcc(as.logical(pa),as.logical(ta))
tr.mcc = append(mccv, tr.mcc)
score <- predictions2[, c("rep")]
actual_class <- d2.2$CLASS
pred <- prediction(score, actual_class)
perf <- performance(pred, "tpr", "fpr")
roc <- data.frame(fpr=unlist(perf@x.values), tpr=unlist(perf@y.values))
tr.auc = append(AUC(roc$fpr, roc$tpr),tr.auc)
roc$fold <- paste("fold",as.character(i),sep="")
roc$method <- "decision tree"
print(dim(roc))
pdfc <- rbind(pdfc,roc)
}
tdf<-data.frame(value=tr.sen,measure=rep("Sensitivity", length(tr.sen)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.spe,measure=rep("Specificity", length(tr.spe)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.acc,measure=rep("Accuracy", length(tr.acc)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.auc,measure=rep("AUC", length(tr.auc)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.mcc,measure=rep("MCC", length(tr.mcc)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
}
save(sim.res, file="sims.coding.tree")
set.seed(100)
sim.res<-data.frame()
for (n in 1:500){
f<-paste("sim.nc.",n,".split",sep="")
load(f)
tr.sen = c()
tr.spe = c()
tr.acc = c()
tr.auc = c()
tr.mcc = c()
pdfnc<-data.frame()
for (i in 1:3) {
d2.1=d2[d2$fold != i,]
d2.1$fold<-NULL
d2.2=d2[d2$fold == i,]
d2.2$fold<-NULL
m.tree<-rpart(CLASS ~ ET + EV + P + CP + CT + D, data=d2.1,method="class")
predictions = predict(m.tree, d2.2, type="class")
predictions2 = predict(m.tree, d2.2)
cm<-confusionMatrix(table(predictions,d2.2$CLASS))
tr.sen = append(cm$byClass['Sensitivity'], tr.sen)
tr.spe = append(cm$byClass['Specificity'], tr.spe)
tr.acc = append(cm$overall['Accuracy'], tr.acc)
pa<-predictions
pa<-gsub("rep","TRUE", pa)
pa<-gsub("non","FALSE", pa)
ta<-d2.2$CLASS
ta<-gsub("rep","TRUE", ta)
ta<-gsub("non","FALSE", ta)
mccv<-mcc(as.logical(pa),as.logical(ta))
tr.mcc = append(mccv, tr.mcc)
score <- predictions2[, c("rep")]
actual_class <- d2.2$CLASS
pred <- prediction(score, actual_class)
perf <- performance(pred, "tpr", "fpr")
roc <- data.frame(fpr=unlist(perf@x.values), tpr=unlist(perf@y.values))
tr.auc = append(AUC(roc$fpr, roc$tpr),tr.auc)
roc$fold <- paste("fold",as.character(i),sep="")
roc$method <- "decision tree"
print(dim(roc))
pdfnc <- rbind(pdfnc,roc)
}
tdf<-data.frame(value=tr.sen,measure=rep("Sensitivity", length(tr.sen)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.spe,measure=rep("Specificity", length(tr.spe)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.acc,measure=rep("Accuracy", length(tr.acc)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.auc,measure=rep("AUC", length(tr.auc)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
tdf<-data.frame(value=tr.mcc,measure=rep("MCC", length(tr.mcc)), method="Classification Tree")
sim.res<-rbind(tdf,sim.res)
}
save(sim.res, file="sims.noncoding.tree")