[Vegan-commits] r326 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 23 13:07:09 CEST 2008
Author: jarioksa
Date: 2008-04-23 13:07:09 +0200 (Wed, 23 Apr 2008)
New Revision: 326
Modified:
pkg/R/rarefy.R
pkg/man/diversity.Rd
Log:
rarefy accepts now a vector of sample sizes
Modified: pkg/R/rarefy.R
===================================================================
--- pkg/R/rarefy.R 2008-04-23 10:39:47 UTC (rev 325)
+++ pkg/R/rarefy.R 2008-04-23 11:07:09 UTC (rev 326)
@@ -1,4 +1,4 @@
-"rarefy" <-
+`rarefy` <-
function (x, sample, se = FALSE, MARGIN = 1)
{
x <- as.matrix(x)
@@ -28,9 +28,18 @@
}
out
}
- S.rare <- apply(x, MARGIN, rarefun, sample = sample)
- if (se)
- rownames(S.rare) <- c("S", "se")
+ if (length(sample) > 1) {
+ S.rare <- sapply(sample, function(n) apply(x, MARGIN, rarefun, sample = n))
+ colnames(S.rare) <- paste("N", sample, sep="")
+ if (se) {
+ dn <- unlist(dimnames(x)[MARGIN])
+ rownames(S.rare) <- paste(rep(dn, each=2), c("S","se"), sep=".")
+ }
+ } else {
+ S.rare <- apply(x, MARGIN, rarefun, sample = sample)
+ if (se)
+ rownames(S.rare) <- c("S", "se")
+ }
attr(S.rare, "Subsample") <- sample
S.rare
}
Modified: pkg/man/diversity.Rd
===================================================================
--- pkg/man/diversity.Rd 2008-04-23 10:39:47 UTC (rev 325)
+++ pkg/man/diversity.Rd 2008-04-23 11:07:09 UTC (rev 326)
@@ -26,7 +26,8 @@
\code{"simpson"} or \code{"invsimpson"}.}
\item{MARGIN}{Margin for which the index is computed. }
\item{base}{ The logarithm \code{base} used in \code{shannon}.}
- \item{sample}{Subsample size for rarefying community.}
+ \item{sample}{Subsample size for rarefying community, either a single
+ value or a vector.}
\item{se}{Estimate standard errors.}
\item{...}{Parameters passed to \code{\link{nlm}}}
}
@@ -46,7 +47,9 @@
subsamples of size \code{sample} from the community. The size of
\code{sample} should be smaller than total community size, but the
function will silently work for larger \code{sample} as well and
- return non-rarefied species richness (and standard error = 0).
+ return non-rarefied species richness (and standard error = 0). If
+ \code{sample} is a vector, rarefaction is performed for each sample
+ size separately.
Rarefaction can be performed only with genuine counts of individuals.
The function \code{rarefy} is based on Hurlbert's (1971) formulation,
and the standard errors on Heck et al. (1975).
@@ -79,9 +82,13 @@
\value{
A vector of diversity indices or rarefied species richness values. With
- option \code{se = TRUE}, function \code{rarefy} returns a 2-row matrix
+ a single \code{sample} and \code{se = TRUE}, function \code{rarefy}
+ returns a 2-row matrix
with rarefied richness (\code{S}) and its standard error
- (\code{se}).
+ (\code{se}). If \code{sample} is a vector in \code{rarefy}, the
+ 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.
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
More information about the Vegan-commits
mailing list