-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.3.Plotting.randomF.v2.R
126 lines (75 loc) · 2.94 KB
/
5.3.Plotting.randomF.v2.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
library(gplots)
library(plyr)
library(SDMTools)
library(reshape)
library("RColorBrewer")
brewer.pal(3,"Dark2")
###The results seems to be all the same, I will go on with just one analysis.
#### Add weights
meta=read.csv("Data/01metadata.Train.csv", stringsAsFactors = F)
meta=meta[,c("Species", "MicAbundance")]
meta=unique(meta)
meta.c=count(meta, "MicAbundance")
wt=(meta.c$freq)
#
meta=merge.data.frame(meta, meta.c, by="MicAbundance")
meta$freq=1/meta$freq
i=1
dato=paste('4.1.random.forest/R4.1.all.', '.out', sep=as.character(i))
##################
dato=read.delim(dato, header=F, stringsAsFactors = F)
dato=dato[,c(1,3,5,6)]
colnames(dato)=c("Species", "Correctly.classified", "Level", "Number.of.estimators" )
###
dato=dato[dato$Level %in% c("01phylum", "02class" ),]
###
dim(dato)
###
dato=merge.data.frame(dato, meta, by="Species")
###
dim(dato)
dato$Level=paste(dato$Number.of.estimators,dato$Level, sep="!" )
dato.new=data.frame(Level=character(),
Mean=numeric(),
Standart.deviation=numeric(),
stringsAsFactors=FALSE)
n=0
for (z in unique(dato$Level)){
n=n+1
dato.temp=dato[dato$Level == z,]
dato.new[n,"Level"]=z
dato.new[n, "Mean"]=wt.mean(dato.temp$Correctly.classified, dato.temp$freq)
dato.new[n, "Standart.deviation"]=wt.sd(dato.temp$Correctly.classified, dato.temp$freq)
}
new.cols=colsplit(dato.new$Level, "!" , c("Number.of.estimators", "Level"))
dato.new$Level=new.cols$Level
dato.new$Number.of.estimators=new.cols$Number.of.estimators
dato.new$Level=as.character(dato.new$Level)
###Get averages and Sd for the iterations
av=aggregate(dato.new$Mean, by=list(dato.new$Number.of.estimators), mean)
sd=aggregate(dato.new$Mean, by=list(dato.new$Number.of.estimators), sd)
av$x= paste(round(av$x, 1), " (", round(sd$x,1), ")", sep="")
##Check limits
borders.u=dato.new$Mean + dato.new$Standart.deviation
borders.l=dato.new$Mean - dato.new$Standart.deviation
#############
pdf("R5.randomF.pdf")
d.mean=cast(dato.new[, c("Mean", "Level", "Number.of.estimators")], Level ~ Number.of.estimators, value="Mean")
rownames(d.mean)=d.mean[,1]
d.mean=d.mean[,-1]
d.sd=cast(dato.new[, c("Standart.deviation", "Level", "Number.of.estimators")], Level ~ Number.of.estimators, value="Standart.deviation")
rownames(d.sd)=d.sd[,1]
d.sd=d.sd[,-1]
d.sd.u=d.mean+ d.sd
d.sd.l=d.mean- d.sd
#change names
rownames(d.mean)[rownames(d.mean)=="01phylum"]="Phylum"
rownames(d.mean)[rownames(d.mean)=="02class"]="Class"
par(mar=c(2,2,2,5))
mp=barplot2(as.matrix(d.mean), beside = TRUE,ylim = c(0, 100),
col=brewer.pal(3,"Set3")[1:2],
plot.ci = TRUE, ci.l = as.matrix(d.sd.l), ci.u = as.matrix(d.sd.u), legend = rownames(d.mean), names.arg = colnames(d.mean), las=1 )
mtext(side = 3, at = colMeans(mp), line=1.3,
text =round(colMeans(d.mean),2), cex=1)
#legend(x=11,y=11,legend=rownames(d.mean),col=brewer.pal(3,"Dark2")[1:2],pch=1,bty="n",xpd=N)
dev.off()