library(ape) library(picante) library(geiger) library(spacodiR) ## convert community dataset to be Spacodi format comm <- read.table(file="community.csv", header=T, row.names=1, sep=",") comm.new <- as.spacodi(data=comm) write.csv(comm.new, file="community dataset Spacodi format.csv") ## randomize a community phylogenetic matrix to null model 1s in Hardy 2008 by using SpacodiR package community.spacodi <- read.table(file="community dataset Spacodi format.csv", header=T, row.names=1, sep=",") randomize.1s <- resamp.1s(obj=community.spacodi) ## convert randomized community data to picante format new.community<-as.picante(ramdomize.1s) ## phylogenic tree (newick format), use read.nexus for nexus format file tree <- read.tree(file="rooted tree.NWK") ## apply branch length on phylogenetic tree (incase if tree has no branch lenght) tree.branch <- compute.brlen(tree, method="power") ### check for mismatches/missing species between phylogenetic tree and community data combined <- match.phylo.comm(tree.branch,new.community) ## convert phylogenetic tree to distance matrix phydist<-cophenetic(tree.branch) ### calculate SES Mean Pairwise distance and nri ses.fri<-ses.mpd(new.community, phy, null.model=NULL, abundance.weighted=T) nri.fri<- -1*((ses.fri$mpd.obs-ses.fri$mpd.rand.mean)/(ses.fri$mpd.rand.sd))