This is just a small collection of miscellaneous functions that may be useful, primarily for community ecology analyses, particularly for paleoecological data. They are here mainly for pedagogical reasons (i.e. for students) as they don't appear to be available in other ecology-focused packages.
1 2 3 4
The community abundance matrix. Must be a matrix with two dimensions for
Should absent taxa be dropped? Must be one of either 'bothAbsent' (drop taxa absent in both sites for a given pairwise comparison),'eitherAbsent' (drop taxa absent in either site), or 'noDrop' (drop none of the taxa). The default 'bothAbsent' is recommended, see examples.
Should the rho coefficients be rescaled on a scale similar to dissimilarity metrics, i.e. bounded 0 to 1, with 1 representing maximum dissimilarity (i.e. a Spearman rho correlation of -1)? ( dissimilarity = (1 - rho) / 2 )
Should the diagonal of the output distance matrix be included?
Should the upper triangle of the output distance matrix be included?
Should taxa listed with NA values be dropped from a pair-wise site comparison? If FALSE, the returned value for that site pair will be NA if NAs are present.
Allows users to select that PIE be calculated only on
pairwiseSpearmanRho returns Spearman rho correlation coefficients
based on the rank abundances of taxa (columns) within sites (rows) from
the input matrix, by internally wrapping the function
It allows for various options that automatically allow
for dropping taxa not shared between two sites (the default), as well as
several other options. This allows the rho coefficient to behave like the
Bray-Curtis distance, in that it is not affected by the number of taxa absent
in both sites.
pairwiseSpearmanRho can also rescale the rho coefficients with (1-rho)/2
to provide a measure similar to a dissimilarity metric, bounded between 0 and 1.
This function was written so several arguments would be in a similar format to
vegan library function
vegdist. If used to obtain rho
rescaled as a dissimilarity, the default output will be the lower triangle of
a distance matrix object, just as is returned by default by
This behavior can be modified via the arguments for including the diagonal
and upper triangle of the matrix. Otherwise, a full matrix is returned (by default)
asDistance argument is not enabled.
HurlbertPIE provides the 'Probability of Interspecific Encounter' metric for
relative community abundance data, a commonly used metric for evenness of community
abundance data based on derivations in Hurlbert (1971). An optional argument allows
users to apply Hurlbert's PIE to only a subselection of the most abundant taxa.
pairwiseSpearmanRho will return either a full matrix (the default) or (if
asDistance is true, a distance matrix, with only the lower triangle
shown (by default). See details.
HurlbertPIE returns a named vector of PIE values for the input data.
David W. Bapst
Hurlbert, S. H. 1971. The nonconcept of species diversity: a critique and alternative parameters. Ecology 52(4):577-586.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
# let's load some example data: # a classic dataset collected by Satoshi and Okido from the Kanto region data(kanto) rhoBothAbsent<-pairwiseSpearmanRho(kanto,dropAbsent="bothAbsent") #other dropping options rhoEitherAbsent<-pairwiseSpearmanRho(kanto,dropAbsent="eitherAbsent") rhoNoDrop<-pairwiseSpearmanRho(kanto,dropAbsent="noDrop") #compare layout(1:3) lim<-c(-1,1) plot(rhoBothAbsent, rhoEitherAbsent, xlim=lim, ylim=lim) abline(0,1) plot(rhoBothAbsent, rhoNoDrop, xlim=lim, ylim=lim) abline(0,1) plot(rhoEitherAbsent, rhoNoDrop, xlim=lim, ylim=lim) abline(0,1) layout(1) #using dropAbsent="eitherAbsent" reduces the number of taxa so much that # the number of taxa present drops too low to be useful #dropping none of the taxa restricts the rho measures to high coefficients # due to the many shared 0s for absent taxa ############# # Try the rho coefficients as a rescaled dissimilarity rhoDist<-pairwiseSpearmanRho(kanto,asDistance=TRUE,dropAbsent="bothAbsent") # What happens if we use these in typical distance matrix based analyses? # Cluster analysis clustRes<-hclust(rhoDist) plot(clustRes) # Principle Coordinates Analysis pcoRes <- pcoa(rhoDist,correction="lingoes") scores <- pcoRes$vectors #plot the PCO plot(scores,type="n") text(labels=rownames(kanto),scores[,1],scores[,2],cex=0.5) ################################## # measuring evenness with Hurlbert's PIE kantoPIE<-HurlbertPIE(kanto) #histogram hist(kantoPIE) #evenness of the kanto data is fairly high #barplot parX<-par(mar=c(7,5,3,3)) barplot(kantoPIE,las=3,cex.names=0.7, ylab="Hurlbert's PIE",ylim=c(0.5,1),xpd=FALSE) par(parX) #and we can see that the Tower has extremely low unevenness #...overly high abundance of ghosts? #let's look at evenness of 5 most abundant taxa kantoPIE_5<-HurlbertPIE(kanto,nAnalyze=5) #barplot parX<-par(mar=c(7,5,3,3)) barplot(kantoPIE_5,las=3,cex.names=0.7, ylab="Hurlbert's PIE for 5 most abundant taxa",ylim=c(0.5,1),xpd=FALSE) par(parX)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.