-
Notifications
You must be signed in to change notification settings - Fork 0
/
Load phylogeny and make CDO.R
30 lines (26 loc) · 1.35 KB
/
Load phylogeny and make CDO.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
#load phylogeny and set up pgls analysis
birdtree<-read.tree("JZ tree Prum merged hackett.tree")
birdtree<-drop.tip(birdtree,c("Alle_alle","Phalacrocorax_auritus"))
birdtree$tip.label<-as.character(birdtree$tip.label)
birdtreels<-birdtree
#make 'distinct df' dataframe with only one species per line, and append variables back onto avgdf
distinctdf<-distinct(df, Binomial, .keep_all = TRUE)
distinctdforder<-arrange(distinctdf,Binomial)
#put current correct binomials on the tree, updated from the birdtree
new<-cbind.data.frame(birdtreels$tip.label,distinctdf$Binomial,gsub(" ","_",distinctdf$Birdtree))
colnames(new)<-c("tiplabel","binomial","birdtree")
#View(new)
match(new$tiplabel,new$birdtree)#get ordered with correct binomials
new$binomialordered<-new$binomial[match(new$tiplabel,new$birdtree)]
str(new)
str(new$binomialordered)
str(birdtreels$tip.label)
birdtreels$tip.label<-new$binomialordered
birdtreels$tip.label<-as.character(birdtreels$tip.label)
#make comparative data object for caper's pgls function
birdCDO<-comparative.data(phy = birdtreels,data = distinctdf, #avgdf[avgdf$Category!="Terrestrial",]
names.col = Binomial,
vcv = TRUE, na.omit = FALSE,
warn.dropped = TRUE)
#check any tips dropped between linking phylogeny and dataframe
birdCDO$dropped