Created
April 26, 2015 04:37
-
-
Save oleon12/c1d96f3be22f363cc8f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Terminal | I | |
---|---|---|
1 | 1 | |
2 | 2 | |
3 | 4 | |
4 | 6 | |
5 | 6 | |
6 | 6 | |
7 | 7 | |
8 | 8 | |
9 | 9 | |
10 | 9 | |
11 | 4 | |
12 | 5 | |
13 | 6 | |
14 | 8 | |
15 | 9 | |
16 | 9 | |
17 | 8 | |
18 | 9 | |
19 | 10 | |
20 | 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1,(2,((3,((4,5),(6,(7,(8,(9,10)))))),(11,(12,(13,((14,(15,16)),(17,(18,(19,20)))))))))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ape) | |
library(phangorn) | |
##This is the tree who I'll want to calculate Vane-Wright index | |
## | |
tree <- read.tree("puranius.tre") | |
plot(tree) | |
##Now a read the table | |
##This table have terminal and the number of nodes who belong each terminal | |
##Index I | |
data <- read.table("index.csv",header = T, sep=",") | |
data | |
##I values | |
data[,2] | |
##Summatory of all I values | |
total.I <- as.numeric(sum(data[,2])) | |
##Now the Q index is calculate | |
##Total I value / each I value | |
Q <- total.I/data$I | |
data$Q <- Q | |
data | |
##Foun the minimum Q value | |
min.Q <- min(data$Q) | |
##Whith the minimum Q value, the W index is calculate | |
## each Q value / minimum Q value | |
W <- data$Q/min.Q | |
data$W <- W | |
data | |
#Here, I create the basic function. | |
vane91 <- function(x){ | |
data <- x | |
total.I <- as.numeric(sum(data[,2])) | |
Q <- total.I/data[,2] | |
data$Q <- Q | |
min.Q <- min(data$Q) | |
W <- data$Q/min.Q | |
data$W <- W | |
a <- 0 | |
l <- length(data[,1]) | |
#Find the highest W value and his terminal | |
for (i in seq(1:l)){ | |
if (data[i,4]>a){ | |
a <- data[i,4] | |
n <- i | |
} | |
} | |
print(data) | |
print("The terminal which highest W values is:") | |
print(data[n,1]) | |
print("With W value =") | |
print(a) | |
} | |
vane91(data) | |
##Remember vane91 use a data frame with just 2 columns (Terminals first and I index second) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment