Skip to content

Permutation: habitat diversity

5 messages · Martin Wilkes, Gavin Simpson, Kay Cichini

#
On Fri, 2011-12-23 at 18:41 +0000, Martin Wilkes wrote:
Hi Martin,

Its not immediately clear to me what your data looks like nor what needs
to be shuffled and what doesn't. Could you expand, perhaps with a
simplified example or structure of data and how you want to shuffle it?

In the meantime, take a look at the permute package as it may do what
you want. If it doesn't I'd be interested in knowing how you want to
permute your data as it might be easy to add this sort of thing to
permute at a later date.

All the best,

Gavin

  
    
#
Hi Gavin,

Thanks for the reply, especially given the festive season!

As an example, say we have three sites and six habitat types in total (A-F):

Site 1: HabitatA 13; HabitatB 21; HabitatC 0; HabitatD 14; HabitatE 23; HabitatF 22
Site 2: HabitatA 1; HabitatB 7; HabitatC 9; HabitatD 23; HabitatE 19; HabitatF 2
Site 3: HabitatA 0; HabitatB 5; HabitatC 12; HabitatD 4; HabitatE 13; HabitatF 6

Can we do a pairwise comparison using a permutation test to evaluate the null hypothesis that habitat diversity is not significantly different between sites?  This seems to suggest a shuffling of the habitat scores between two sites at a time, but I have very little experience of hypothesis testing using this approach!  I hope I have explained it a little better now. Can you please help?

Merry Christmas to you and the family.

Martin
3 days later
#
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






_______________________________________________

R-sig-ecology mailing list

R-sig-ecology at r-project.org

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