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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Oct 9 08:01:44 CEST 2015


Author: jarioksa
Date: 2015-10-09 08:01:44 +0200 (Fri, 09 Oct 2015)
New Revision: 2970

Modified:
   pkg/vegan/R/rrarefy.R
   pkg/vegan/man/rarefy.Rd
Log:
Merge branch 'cran-2.3' into r-forge-svn-local

Modified: pkg/vegan/R/rrarefy.R
===================================================================
--- pkg/vegan/R/rrarefy.R	2015-10-07 08:22:02 UTC (rev 2969)
+++ pkg/vegan/R/rrarefy.R	2015-10-09 06:01:44 UTC (rev 2970)
@@ -14,7 +14,12 @@
     sample <- rep(sample, length=nrow(x))
     colnames(x) <- colnames(x, do.NULL = FALSE)
     nm <- colnames(x)
+    ## warn if something cannot be rarefied
+    if (any(rowSums(x) < sample))
+        warning("Some row sums < 'sample' and are not rarefied")
     for (i in 1:nrow(x)) {
+        if (sum(x[i,]) <= sample[i]) ## nothing to rarefy: take all
+            next
         row <- sample(rep(nm, times=x[i,]), sample[i])
         row <- table(row)
         ind <- names(row)
@@ -33,12 +38,19 @@
         stop("function accepts only integers (counts)")
     if (length(sample) > 1 &&  length(sample) != nrow(x))
         stop(gettextf(
-             "length of  'sample' and number of rows of 'x' do not match"))
+             "length of 'sample' and number of rows of 'x' do not match"))
     x <- drop(as.matrix(x))
+    ## warn on too large samples
+    if (is.matrix(x))
+        rs <- rowSums(x)
+    else
+        rs <- sum(x)
+    if (any(rs) < sample)
+        warning("Some row sums < 'sample' and probabilities either 0 or 1")
     ## dfun is kluge: first item of  vector x must be the sample size,
     ## and the rest  is the community data. This  seemed an easy trick
     ## to evaluate dfun in an apply() instead of a loop.
-    dfun <- function(x, sample) {
+    dfun <- function(x) {
         J <- sum(x[-1])
         sample <- min(x[1], J)
         1 - exp(lchoose(J - x[-1], sample) - lchoose(J, sample))

Modified: pkg/vegan/man/rarefy.Rd
===================================================================
--- pkg/vegan/man/rarefy.Rd	2015-10-07 08:22:02 UTC (rev 2969)
+++ pkg/vegan/man/rarefy.Rd	2015-10-09 06:01:44 UTC (rev 2970)
@@ -47,17 +47,20 @@
   \code{rarefy} is based on Hurlbert's (1971) formulation, and the
   standard errors on Heck et al. (1975).
 
-  Function \code{rrarefy} generates one randomly rarefied community data
-  frame or vector of given \code{sample} size. The \code{sample} can be
-  a vector giving the sample sizes for each row, and its values must be
-  less or equal to observed number of individuals. The random
-  rarefaction is made without replacement so that the variance of
-  rarefied communities is rather related to rarefaction proportion than
-  to to the size of the \code{sample}.
+  Function \code{rrarefy} generates one randomly rarefied community
+  data frame or vector of given \code{sample} size. The \code{sample}
+  can be a vector giving the sample sizes for each row.  If the
+  \code{sample} size is equal to or smaller than the observed number
+  of individuals, the non-rarefied community will be returned.  The
+  random rarefaction is made without replacement so that the variance
+  of rarefied communities is rather related to rarefaction proportion
+  than to the size of the \code{sample}.
 
-  Function \code{drarefy} returns probabilities that species occur in a
-  rarefied community of size \code{sample}. The \code{sample} can be a
-  vector giving the sample sizes for each row.
+  Function \code{drarefy} returns probabilities that species occur in
+  a rarefied community of size \code{sample}. The \code{sample} can be
+  a vector giving the sample sizes for each row. If the \code{sample}
+  is equal to or smaller than the observed number of individuals, all
+  observed species will have sampling probability 1.
 
   Function \code{rarecurve} draws a rarefaction curve for each row of
   the input data. The rarefaction curves are evaluated using the



More information about the Vegan-commits mailing list