-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexample.R
61 lines (48 loc) · 1.49 KB
/
example.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
# Before starting:
#1. make sure you have installed the "ape" package.
#2. the file code.R is in the working directory.
library("ape")
source("code.R")
#SOME PARAMETERS...
lambda0 <- 0.1 #rate parameter of the proposal
se <- 0.5 #standard deviation of the proposal
sim <- 10000 #number of iterations
thin <- 10 #we kept only each 10th iterate
burn <- 100 #100 iterates are burned-in
#RANDOM TREE:
#same for both examples, only the trait vector varies.
set.seed(25)
ns <- 20 #20 species
tree <- rtree(ns)
##########
# CASE A # : with phylogenetic signal
##########
trait <- c(2,1,3,1,1,3,1,3,2,1,1,2,2,2,2,1,1,3,1,1)
#CALCULATE DELTA A
deltaA <- delta(trait,tree,lambda0,se,sim,thin,burn)
print(deltaA)
#DRAW THE TREE...
par(mfrow=c(1,2))
tree$tip.label <- rep("",ns)
plot(tree,main="SCENARIO A")
ar <- ace(trait,tree,type="discret",method="ML",model="ARD")$lik.anc
nodelabels(pie = ar, cex = 1,frame="n")
mtrait <- matrix(0,ncol=3,nrow=ns)
for ( i in 1:ns) {
mtrait[i,trait[i]] <- 1
}
tiplabels(pie=mtrait,cex=0.5)
##########
# CASE B # : no phylogenetic signal
##########
trait <- c(2,3,1,3,3,3,3,2,2,3,1,2,1,2,3,1,2,3,1,2)
#CALCULATE DELTA B
deltaB <- delta(trait,tree,lambda0,se,sim,thin,burn)
print(deltaB)
#DRAW THE TREE...
ar <- ace(trait,tree,type="discret",method="ML",model="ARD")$lik.anc
plot(tree,main="SCENARIO B")
nodelabels(pie = Re(ar), cex = 1)
mtrait <- matrix(0,ncol=3,nrow=ns)
for ( i in 1:ns) { mtrait[i,trait[i]] <- 1 }
tiplabels(pie=mtrait,cex=0.5)