[Vegan-commits] r2013 - branches/2.0 branches/2.0/R branches/2.0/inst branches/2.0/man www

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 20 17:36:17 CET 2011


Author: jarioksa
Date: 2011-11-20 17:36:16 +0100 (Sun, 20 Nov 2011)
New Revision: 2013

Added:
   branches/2.0/R/rarecurve.R
Modified:
   branches/2.0/NAMESPACE
   branches/2.0/inst/ChangeLog
   branches/2.0/inst/NEWS.Rd
   branches/2.0/man/diversity.Rd
   www/NEWS.html
Log:
merge rarecurve (revs 2008,9,11,12)

Modified: branches/2.0/NAMESPACE
===================================================================
--- branches/2.0/NAMESPACE	2011-11-20 16:03:44 UTC (rev 2012)
+++ branches/2.0/NAMESPACE	2011-11-20 16:36:16 UTC (rev 2013)
@@ -21,10 +21,10 @@
 ordixyplot, orglpoints, orglsegments, orglspider, orgltext, 
 pcnm, permatfull, permatswap, permutest, poolaccum, postMDS, prc,
 prestondistr, prestonfit, procrustes, protest, radfit, radlattice,
-rankindex, rarefy,raupcrick, rda, renyiaccum, renyi, rrarefy, scores,
-showvarparts, spandepth, spantree, specaccum, specnumber,
-specpool2vect, specpool, spenvcor, stepacross, stressplot, swan,
-taxa2dist, taxondive, tolerance, treedist, treedive, treeheight,
+rankindex, rarecurve, rarefy, raupcrick, rda, renyiaccum, renyi,
+rrarefy, scores, showvarparts, spandepth, spantree, specaccum,
+specnumber, specpool2vect, specpool, spenvcor, stepacross, stressplot,
+swan, taxa2dist, taxondive, tolerance, treedist, treedive, treeheight,
 tsallisaccum, tsallis, varpart, vectorfit, vegandocs, vegdist,
 vegemite, veiledspec, wascores, wcmdscale, wisconsin)
 

Copied: branches/2.0/R/rarecurve.R (from rev 2009, pkg/vegan/R/rarecurve.R)
===================================================================
--- branches/2.0/R/rarecurve.R	                        (rev 0)
+++ branches/2.0/R/rarecurve.R	2011-11-20 16:36:16 UTC (rev 2013)
@@ -0,0 +1,37 @@
+`rarecurve` <-
+    function(x, step = 1, sample, xlab = "Sample Size", ylab = "Species",
+             label = TRUE,...)
+{
+    tot <- rowSums(x)
+    S <- specnumber(x)
+    nr <- nrow(x)
+    ## Rarefy
+    out <- lapply(seq_len(nr), function(i) {
+        n <- seq(1, tot[i], by = step)
+        if (n[length(n)] != tot[i])
+            n <- c(n, tot[i])
+        drop(rarefy(x[i,], n))
+    })
+    Nmax <- sapply(out, function(x) max(attr(x, "Subsample")))
+    Smax <- sapply(out, max)
+    ## set up plot
+    plot(c(1, max(Nmax)), c(1, max(Smax)), xlab = xlab, ylab = ylab,
+         type = "n", ...)
+    ## rarefied richnesses for given 'sample'
+    if (!missing(sample)) {
+        abline(v = sample)
+        rare <- sapply(out, function(z) approx(x = attr(z, "Subsample"), y = z,
+                                             xout = sample, rule = 1)$y)
+        abline(h = rare, lwd=0.5)
+    }
+    ## rarefaction curves
+    for(ln in seq_len(length(out))) {
+        N <- attr(out[[ln]], "Subsample")
+        lines(N, out[[ln]], ...)
+    }
+    ## label curves at their endpoitns
+    if (label) {
+        ordilabel(cbind(tot, S), labels=rownames(x), ...)
+    }
+    invisible(out)
+}

Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog	2011-11-20 16:03:44 UTC (rev 2012)
+++ branches/2.0/inst/ChangeLog	2011-11-20 16:36:16 UTC (rev 2013)
@@ -4,6 +4,7 @@
 
 Version 2.0-3 (opened November 13, 2011)
 
+	* merge r2008,9,11,12: add rarecurve.
 	* merge r2007: FAQ update for arrow scaling.
 	* merge r2004: metaMDS(..., noshare=0) triggers stepacross(), but
 	'noshare = FALSE' never does.

Modified: branches/2.0/inst/NEWS.Rd
===================================================================
--- branches/2.0/inst/NEWS.Rd	2011-11-20 16:03:44 UTC (rev 2012)
+++ branches/2.0/inst/NEWS.Rd	2011-11-20 16:36:16 UTC (rev 2013)
@@ -3,6 +3,19 @@
 \encoding{UTF-8}
 
 \section{Changes in version 2.0-3}{
+
+  \subsection{NEW FUNCTIONS}{
+    \itemize{
+
+      \item Added function \code{rarecurve} to draw rarefaction curves
+      for each row (sampling unit) of the input data, optionally with
+      lines showing rarefied species richness with given sample size
+      for each curve.
+
+    }
+  } % end new functions
+
+		  
   \subsection{NEW FEATURES}{
      \itemize{
 

Modified: branches/2.0/man/diversity.Rd
===================================================================
--- branches/2.0/man/diversity.Rd	2011-11-20 16:03:44 UTC (rev 2012)
+++ branches/2.0/man/diversity.Rd	2011-11-20 16:36:16 UTC (rev 2013)
@@ -4,6 +4,7 @@
 \alias{rarefy}
 \alias{rrarefy}
 \alias{drarefy}
+\alias{rarecurve}
 \alias{fisher.alpha}
 \alias{specnumber}
 
@@ -17,6 +18,8 @@
 rarefy(x, sample, se = FALSE, MARGIN = 1)
 rrarefy(x, sample)
 drarefy(x, sample)
+rarecurve(x, step = 1, sample, xlab = "Sample Size", ylab = "Species",
+   label = TRUE, ...)
 fisher.alpha(x, MARGIN = 1, se = FALSE, ...)
 specnumber(x, groups, MARGIN = 1)
 }
@@ -30,9 +33,13 @@
   \item{sample}{Subsample size for rarefying community, either a single
     value or a vector.}
   \item{se}{Estimate standard errors.}
+  \item{step}{Step size for sample sizes in rarefaction curves.}
+  \item{xlab, ylab}{Axis labels in plots of rarefaction curves.}
+  \item{label}{Label rarefaction curves by rownames of \code{x} (logical).}
   \item{groups}{A grouping factor: if given, finds the total number of
     species in each group.}
-  \item{...}{Parameters passed to \code{\link{nlm}}}
+  \item{...}{Parameters passed to \code{\link{nlm}}, or to \code{\link{plot}}, 
+    \code{\link{lines}} and \code{\link{ordilabel}} in \code{rarecurve}.}
 }
 \details{
   Shannon or Shannon--Weaver (or Shannon--Wiener) index is defined as
@@ -69,6 +76,13 @@
   rarefied community of size \code{sample}. The \code{sample} can be a
   vector giving the sample sizes for each row.
 
+  Function \code{rarecurve} draws a rarefaction curve for each row of
+  the input data. The rarefaction curves are evaluated using the
+  interval of \code{step} sample sizes, always including 1 and total
+  sample size.  If \code{sample} is specified, a vertical line is
+  drawn at \code{sample} with horizontal lines for the rarefied
+  species richnesses.
+
   \code{fisher.alpha} estimates the \eqn{\alpha} parameter of
   Fisher's logarithmic series (see \code{\link{fisherfit}}). 
   The estimation is possible only for genuine
@@ -105,6 +119,10 @@
   function returns a matrix with a column for each \code{sample} size,
   and if \code{se = TRUE}, rarefied richness and its standard error are
   on consecutive lines.
+
+  Function \code{rarecurve} retunrs \code{\link{invisible}} list of
+  \code{rarefy} results corresponding each drawn curve.
+
   With option \code{se = TRUE}, function \code{fisher.alpha} returns a
   data frame with items for \eqn{\alpha} (\code{alpha}), its approximate
   standard errors (\code{se}), residual degrees of freedom
@@ -154,6 +172,12 @@
 alpha <- with(dune.env, tapply(specnumber(dune), Management, mean))
 gamma <- with(dune.env, specnumber(dune, Management))
 gamma/alpha - 1
+## Rarefaction
+(raremax <- min(rowSums(BCI)))
+Srare <- rarefy(BCI, raremax)
+plot(S, Srare, xlab = "Observed No. of Species", ylab = "Rarefied No. of Species")
+abline(0, 1)
+rarecurve(BCI, step = 20, sample = raremax, col = "blue", cex = 0.6)
 }
 \keyword{ univar }
 

Modified: www/NEWS.html
===================================================================
--- www/NEWS.html	2011-11-20 16:03:44 UTC (rev 2012)
+++ www/NEWS.html	2011-11-20 16:36:16 UTC (rev 2013)
@@ -11,8 +11,33 @@
 <h3>Changes in version 2.0-3</h3>
 
 <p>
+</p>
+<p>
 
 
+<h4>NEW FUNCTIONS</h4>
+
+<p>
+
+</p>
+<p>
+<ul>
+<li> Added function <code>rarecurve</code> to draw rarefaction curves
+for each row (sampling unit) of the input data, optionally with
+lines showing rarefied species richness with given sample size
+for each curve.
+</p>
+<p>
+</ul>
+
+</p>
+ 
+</p>
+<p>
+</p>
+<p>
+
+
 <h4>NEW FEATURES</h4>
 
 <p>



More information about the Vegan-commits mailing list