[Vegan-commits] r1609 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri May 27 10:21:20 CEST 2011


Author: jarioksa
Date: 2011-05-27 10:21:20 +0200 (Fri, 27 May 2011)
New Revision: 1609

Modified:
   pkg/vegan/R/specnumber.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/diversity.Rd
Log:
specnumber gained argument 'groups' for easier estimation of Whittaker's beta = gamma/alpha - 1

Modified: pkg/vegan/R/specnumber.R
===================================================================
--- pkg/vegan/R/specnumber.R	2011-05-27 07:59:48 UTC (rev 1608)
+++ pkg/vegan/R/specnumber.R	2011-05-27 08:21:20 UTC (rev 1609)
@@ -1,6 +1,13 @@
 `specnumber` <-
-    function(x, MARGIN = 1)
+    function(x, groups, MARGIN = 1)
 {
+    if (!missing(groups)) {
+        if (length(groups) == 1)
+            groups <- rep(groups, nrow(x))
+        x <- aggregate(x, list(groups), max)
+        rownames(x) <- x[,1]
+        x <- x[,-1]
+    }
     if (length(dim(x)) > 1)
         apply(x > 0, MARGIN, sum)
     else

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-05-27 07:59:48 UTC (rev 1608)
+++ pkg/vegan/inst/ChangeLog	2011-05-27 08:21:20 UTC (rev 1609)
@@ -4,6 +4,10 @@
 
 Version 1.18-31 (opened May 26, 2011)
 
+	* specnumber: gained argument 'groups' to find total richness
+	within each group. An example shows how to use this to find one
+	index that Whittaker suggested to estimate beta diversity.
+
 	* capscale: species scores will be NA if input data were
 	dissimilarities and no 'comm' was given. (BTW, if input data were
 	dissimilarities, update() will fail! -- I don't know why, but

Modified: pkg/vegan/man/diversity.Rd
===================================================================
--- pkg/vegan/man/diversity.Rd	2011-05-27 07:59:48 UTC (rev 1608)
+++ pkg/vegan/man/diversity.Rd	2011-05-27 08:21:20 UTC (rev 1609)
@@ -18,7 +18,7 @@
 rrarefy(x, sample)
 drarefy(x, sample)
 fisher.alpha(x, MARGIN = 1, se = FALSE, ...)
-specnumber(x, MARGIN = 1)
+specnumber(x, groups, MARGIN = 1)
 }
 
 \arguments{
@@ -30,6 +30,8 @@
   \item{sample}{Subsample size for rarefying community, either a single
     value or a vector.}
   \item{se}{Estimate standard errors.}
+  \item{groups}{A grouping factor: if given, finds the total number of
+    species in each group.}
   \item{...}{Parameters passed to \code{\link{nlm}}}
 }
 \details{
@@ -77,8 +79,9 @@
   Normal inference.
   
   Function \code{specnumber} finds the number of species. With
-  \code{MARGIN = 2}, it finds frequencies of species. The function is
-  extremely simple, and shortcuts are easy in plain \R.
+  \code{MARGIN = 2}, it finds frequencies of species. If \code{groups}
+  is given, finds the total number of species in each group (see 
+  example on finding one kind of beta diversity with this option).
   
   Better stories can be told about Simpson's index than about
   Shannon's index, and still grander narratives about
@@ -138,12 +141,19 @@
 invsimp <- diversity(BCI, "inv")
 ## Unbiased Simpson of Hurlbert 1971 (eq. 5):
 unbias.simp <- rarefy(BCI, 2) - 1
+## Fisher alpha
 alpha <- fisher.alpha(BCI)
+## Plot all
 pairs(cbind(H, simp, invsimp, unbias.simp, alpha), pch="+", col="blue")
 ## Species richness (S) and Pielou's evenness (J):
 S <- specnumber(BCI) ## rowSums(BCI > 0) does the same...
 J <- H/log(S)
-
+## beta diversity defined as gamma/alpha - 1:
+data(dune)
+data(dune.env)
+alpha <- with(dune.env, tapply(specnumber(dune), Management, mean))
+gamma <- with(dune.env, specnumber(dune, Management))
+gamma/alpha - 1
 }
 \keyword{ univar }
 



More information about the Vegan-commits mailing list