library(ape) library(geiger) library(ade4) library(picante) library(phytools) # load tree produced by MrBayes tree<-read.nexus("minnows.tre") # get a list of outgroup taxa outgroup<-c("Moxostoma_duquesnii","Moxostoma_erythrurum","Moxostoma_macrolepidotum") # root the tree based on one of the outgroup species rooted_tree<-root(tree,outgroup[1]) # drop the outgroup species rooted_tree<-drop.tip(rooted_tree,outgroup) # plot tree plot.phylo(rooted_tree) # Read the trait data, we are interested in the "eggs" column which has egg size traits<-read.csv("minnow_data.csv",sep=",", header=T,row.names="species") # sort traits frame to match tree traits<-traits[match(rooted_tree$tip.label[],row.names(traits)),] # Make a pretty picture. Map egg size onto the phylogeny egg_size<-as.numeric(traits$egg) names(egg_size)<-row.names(traits) contMap(rooted_tree,egg_size) habitat<-factor(traits$habitat) names(habitat)<-row.names(traits) ############################################################################## # Assignment ############################################################################## # calculate phylogenetic signal phylosignal(phy = rooted_tree,x=egg_size,reps = 10000) # phylogenetic ANOVA model1<-aov.phylo(egg_size~habitat,rooted_tree,nsim=5000,test="Wilks") # For comparison, let's randomize the egg size data and compare x<-sample(egg_size,size = 60,replace=F) names(x)<-rooted_tree$tip.label phylosignal(phy=rooted_tree,x=x,reps=10000) model1<-aov.phylo(x~habitat,rooted_tree,nsim=5000,test="Wilks") # similar approach using the pic function # Get indipendent contrasts for egg size and habitat pic_egg<-pic(traits$egg,rooted_tree) pic_habitat<-pic(traits$habitat,rooted_tree) # plot independent contrasts plot(pic_egg, pic_habitat,pch=16) # anova anova(lm(pic_egg~pic_habitat)) # Evolutionary models brownian_motion<-fitContinuous(phy = rooted_tree,dat=egg_size,model="BM") OU<-fitContinuous(phy = rooted_tree,dat=egg_size,model="OU") lambda<-fitContinuous(phy = rooted_tree,dat=egg_size,model="lambda") white_noise<-fitContinuous(phy = rooted_tree,dat=egg_size,model="white") # compare aicc values brownian_motion$opt$aicc OU$opt$aicc lambda$opt$aicc white_noise$opt$aicc # lambda mdoel is best, look at lambda value # Lambda ranges from 0-1, with higher values indicating importance of tree branch lengths lambda$opt$lambda