[R-sig-eco] Permutation: habitat diversity

Martin Wilkes m.wilkes at worc.ac.uk
Tue Dec 27 17:52:24 CET 2011


Thanks Kay,
That seems to do exactly what I wanted it to!  I am a little concerned about some of the results I am getting using the code below, which suggests a highly significant difference for diversity between two of my sites (PodLow and PodInt) which does not seem to tally with the null-distribution.  Am I reading the results wrong?
##PodLow vs PodInt##Habitat counts for PodLowPodLow <- c(20,0,2,21,3,15,23)##Habitat counts for PodIntPodInt <- c(17,1,3,19,1,21,15)
require (vegan)
DivPodLow=diversity(t(PodLow),"shannon") ##Diversity for PodLowDivPodInt=diversity(t(PodInt),"shannon") ##Diversity for PodIntDivPodLowDivPodIntRichPodLow=sum(PodLow>0) ##Richness for PodLowRichPodInt=sum(PodInt>0) ##Richness for PodInt
tr.diff.div=abs(PodLow-PodInt) ##Observed difference in diversitytr.diff.rich=abs(PodLow-PodInt) ##Observed difference in richness
tr.diff.div
K=2100
pop.div=rep(NA,K) ##Dataframe for null population of differencespop.rich=rep(NA,K)pop.div[1:length(tr.diff.div)]=tr.diff.divpop.rich[1:length(tr.diff.div)]=tr.diff.rich
for(j in 2:K){   ### loop to generate null pop. of differences indPodLow<-sum(PodLow)indPodInt<-sum(PodInt)pool<-c(rep(1:length(PodLow),PodLow),rep(1:length(PodInt),PodInt))
tempPodLow=sample(pool,indPodLow,replace=T)   ### resample PodLowtempPodInt=sample(pool,indPodInt,replace=T)   ### resample PodInt ### calculate diversity:DivPodLow.temp=diversity(t(tabulate(tempPodLow)),"shannon")DivPodInt.temp=diversity(t(tabulate(tempPodInt)),"shannon") RichPodLow.temp=sum(tabulate(tempPodLow)>0)RichPodInt.temp=sum(tabulate(tempPodInt)>0) temp.diff.div=abs(DivPodLow.temp-DivPodInt.temp)pop.div[j]=temp.diff.div temp.diff.rich=abs(RichPodLow.temp-RichPodInt.temp)pop.rich[j]=temp.diff.rich} p.div=sum(pop.div>=abs(tr.diff.div))/Kp.rich=sum(pop.rich>=abs(tr.diff.rich))/K ### diagrams to show null-distributions with obs. differences par(mfrow=c(1,1))hist(pop.div, breaks=500, xlim=c(0,0.5))abline(v=abs(DivPodLow-DivPodInt),lty=3,col=2,lwd=2) ##Showing observed differencep.divDivPodLowDivPodInttr.diff.div
hist(pop.rich)abline(v=tr.diff.rich,lty=3,col=2,lwd=2)p.richRichPodLowRichPodInttr.diff.rich

Best wishes,
Martin




From: Kay Cichini [kay.cichini at gmail.com]

Sent: 24 December 2011 15:30

To: Martin Wilkes

Cc: r-sig-ecology at r-project.org

Subject: Re: [R-sig-eco] Permutation: habitat diversity



hi,



i don't exactly know what you want to do but this may serve as a starter: 
http://thebiobucket.blogspot.com/2011/04/test-difference-between-diversity.html



if you want to test difference in habitat diversity between sites you just need to replace my species in the example with your habitats.



cheers,

kay




2011/12/23 Martin Wilkes <m.wilkes at worc.ac.uk>


We have counts of habitat types at three sites and want to permute the sets of counts between sites to get a distribution of habitat (H) diversity. We have tried several R functions (perm, sample, permtest) but none seems to do what we want.  We're happy writing
 the code to calculate the H distribution but need some help getting the permutations right if possible please.



Thanks



Martin Wilkes

University of Worcester



       [[alternative HTML version deleted]]



_______________________________________________

R-sig-ecology mailing list

R-sig-ecology at r-project.org

https://stat.ethz.ch/mailman/listinfo/r-sig-ecology











More information about the R-sig-ecology mailing list