Pearson’s correlation test for each two pairs
#Do Pearson's correlation test for each two pairs
extent.H.inv.cor.test<-cor.test(extent,H.inv)
extent.cooccur.cor.test<-cor.test(extent,cooccur)
H.inv.coccur.cor.test<-cor.test(H.inv, cooccur)
#Extent with habitat index
extent.H.inv.cor.test
##
## Pearson's product-moment correlation
##
## data: extent and H.inv
## t = 2.1883, df = 32, p-value = 0.03607
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.02575616 0.62294402
## sample estimates:
## cor
## 0.3607795
#Extent with co-occurrence (Jaccard) index
extent.cooccur.cor.test
##
## Pearson's product-moment correlation
##
## data: extent and cooccur
## t = 2.8002, df = 32, p-value = 0.008588
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1240828 0.6798125
## sample estimates:
## cor
## 0.4436334
# Habitat and co-occurrence indices
H.inv.coccur.cor.test
##
## Pearson's product-moment correlation
##
## data: H.inv and cooccur
## t = 2.2104, df = 32, p-value = 0.03435
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.02939639 0.62516827
## sample estimates:
## cor
## 0.3639442
Blomberg’s K
#find Blomberg's 'K' value
#rownames(extent.sqrt.rescale)<-h.inv.ordered.rownames
#Extent K
extent.K<-Kcalc(extent, sedges.tree, checkdata=TRUE)
extent.K
## [,1]
## [1,] 0.07953233
#Habitat K
H.inv.K<-Kcalc(H.inv, sedges.tree, checkdata=TRUE)
H.inv.K
## [,1]
## [1,] 0.09785613
#Cooccur K
cooccur.K<-Kcalc(cooccur, sedges.tree, checkdata=TRUE)
cooccur.K
## [,1]
## [1,] 0.07196142
# Use phylosignal to calculate so get p values from phylogenetic contrasts
# Extent phylosignal
extent.ps<-phylosignal(extent,sedges.tree, reps=999, checkdata=TRUE)
extent.ps
## K PIC.variance.obs PIC.variance.rnd.mean PIC.variance.P
## 1 0.07953233 0.01485334 0.0100982 0.904
## PIC.variance.Z
## 1 1.270905
# Habitat phylosignal
H.inv.ps<-phylosignal(H.inv,sedges.tree, reps=999, checkdata=TRUE)
H.inv.ps
## K PIC.variance.obs PIC.variance.rnd.mean PIC.variance.P
## 1 0.09785613 0.01825359 0.0148916 0.775
## PIC.variance.Z
## 1 0.6390491
# Co-occurrence phylosignal
cooccur.ps<-phylosignal(cooccur,sedges.tree, reps=999, checkdata=TRUE)
cooccur.ps
## K PIC.variance.obs PIC.variance.rnd.mean PIC.variance.P
## 1 0.07196142 0.01933529 0.01146276 0.944
## PIC.variance.Z
## 1 1.96972
#dev.new(width=3.15, height=4.2)
par(mai=c(1,0,0, 0.15))
plot(sedges.tree,x.lim=100,show.tip.label = FALSE,edge.width=4)
# Then weâll plot line segments corresponding to each trait. The plotting parameters in here are very specific to this data set, and should be viewed as a template. The great thing is that you can change any of them yourself â youâll need to play around with them (e.g., changing the starting positions of the segments, or their scaling) to get your own data plotted.
nspecies <- length(sedges.tree$tip.label)
segments(rep(65,nspecies),1:nspecies,rep(65,nspecies)+(10*H.inv), 1:nspecies,lwd=3, col="grey40")
mtext("Habitat", at = 68, side = 1, line = 0, cex=.65,font=2)
segments(rep(77,nspecies),1:nspecies,rep(77,nspecies)+(10*cooccur), 1:nspecies,lwd=3, col="grey10")
mtext("Co-occurrence", srt=45,at = 82, side = 1, line = 0, cex=.65,font=2)
segments(rep(89,nspecies),1:nspecies,rep(89,nspecies)+(10*extent), 1:nspecies,lwd=3, col="grey60")
mtext("Extent", at = 97, side = 1, line = 0, cex=.65,font=2)
box(which='outer',lwd=3, col = 'black')

#textClick("Habitat", cex=1)
#textClick("Co-occurrence", cex=1)
#textClick("Extent", cex=1)