[Vegan-commits] r1522 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 6 10:03:08 CET 2011
Author: jarioksa
Date: 2011-03-06 10:03:07 +0100 (Sun, 06 Mar 2011)
New Revision: 1522
Modified:
pkg/vegan/R/rrarefy.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/diversity.Rd
Log:
add drarefy: occurrence probabilities in a rarefied community
Modified: pkg/vegan/R/rrarefy.R
===================================================================
--- pkg/vegan/R/rrarefy.R 2011-03-06 06:21:20 UTC (rev 1521)
+++ pkg/vegan/R/rrarefy.R 2011-03-06 09:03:07 UTC (rev 1522)
@@ -1,5 +1,7 @@
-rrarefy <-
-function(x, sample)
+### Random rarefied subsample: sample without replacement
+
+`rrarefy` <-
+ function(x, sample)
{
if (length(sample) > 1 && length(sample) != nrow(x))
stop("length of 'sample' and number of rows of 'x' do not match")
@@ -15,3 +17,22 @@
}
x
}
+
+### Probabilities that species occur in a rarefied 'sample'
+
+`drarefy` <-
+ function(x, sample)
+{
+ if (length(sample) > 1)
+ stop(gettextf("only scalar 'sample' is accepted"))
+ x <- drop(as.matrix(x))
+ dfun <- function(x, sample) {
+ J <- sum(x)
+ sample <- min(sample, J)
+ 1 - exp(lchoose(J - x, sample) - lchoose(J, sample))
+ }
+ if (length(dim(x) > 1))
+ t(apply(x, 1, dfun, sample = sample))
+ else
+ dfun(x, sample)
+}
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2011-03-06 06:21:20 UTC (rev 1521)
+++ pkg/vegan/inst/ChangeLog 2011-03-06 09:03:07 UTC (rev 1522)
@@ -23,6 +23,10 @@
concern cca(); rda() and capscale() are only changed after (and
if) this change appears sensible and correct in cca().
+ * drarefy: a new function to return the probabilities that a
+ species occurs in a rarefied sample (= sampled without
+ replacement) of a given size.
+
Version 1.18-23 (closed February 28, 2011)
* opened with the release of 1.17-7 based on version 1.18-22 on
Modified: pkg/vegan/man/diversity.Rd
===================================================================
--- pkg/vegan/man/diversity.Rd 2011-03-06 06:21:20 UTC (rev 1521)
+++ pkg/vegan/man/diversity.Rd 2011-03-06 09:03:07 UTC (rev 1522)
@@ -3,6 +3,7 @@
\alias{diversity}
\alias{rarefy}
\alias{rrarefy}
+\alias{drarefy}
\alias{fisher.alpha}
\alias{specnumber}
@@ -13,13 +14,10 @@
\usage{
diversity(x, index = "shannon", MARGIN = 1, base = exp(1))
-
rarefy(x, sample, se = FALSE, MARGIN = 1)
-
rrarefy(x, sample)
-
+drarefy(x, sample)
fisher.alpha(x, MARGIN = 1, se = FALSE, ...)
-
specnumber(x, MARGIN = 1)
}
@@ -64,6 +62,13 @@
that the variance of rarefied communities is rather related to
rarefaction proportion than to to the size of the \code{sample}.
+ Function \code{drarefy} returns probabilities that species occur in
+ a rarefied community of size \code{sample}. Only a single scalar of
+ \code{sample} size is accepted. If \code{x} is a single site, the
+ function returns a vector of species occurrence probabilities. If
+ \code{x} is a data frame or a matrix, a matrix of probabilities for
+ each row is returned.
+
\code{fisher.alpha} estimates the \eqn{\alpha} parameter of
Fisher's logarithmic series (see \code{\link{fisherfit}}).
The estimation is possible only for genuine
More information about the Vegan-commits
mailing list