[Picante-commits] r74 - branches/gsoc/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 28 22:57:35 CEST 2008
Author: mrhelmus
Date: 2008-05-28 22:57:35 +0200 (Wed, 28 May 2008)
New Revision: 74
Added:
branches/gsoc/R/specaccum.PSR.r
Log:
Working code to calculate sample-based rarefaction for PSR. Calls function PSVcalc, and for plotting functions requires library vegan.
Added: branches/gsoc/R/specaccum.PSR.r
===================================================================
--- branches/gsoc/R/specaccum.PSR.r (rev 0)
+++ branches/gsoc/R/specaccum.PSR.r 2008-05-28 20:57:35 UTC (rev 74)
@@ -0,0 +1,41 @@
+specaccum.PSR<-function (samp, Cmatrix, permutations = 100, method = "random", ...)
+{
+
+#function adapted from the vegan package specaccum
+
+ x <- as.matrix(samp)
+ n <- nrow(x)
+ p <- ncol(x)
+ if (p == 1)
+ {
+ x <- t(x)
+ n <- nrow(x)
+ p <- ncol(x)
+ }
+ accumulator <- function(x,ind,Cmatrix)
+ {
+ n <- nrow(x)
+ p <- ncol(x)
+ xx<-x
+ xx[1:n,1:p]<-0
+ xx[apply(x[ind, ], 2, cumsum)>0]<-1
+ PSV<-PSVcalc(xx,Cmatrix,compute.var=FALSE)
+ PSV[,1]*PSV[,2]
+ }
+ METHODS <- c("collector", "random", "exact", "rarefaction",
+ "coleman")
+ method <- match.arg(method, METHODS)
+
+ specaccum <- sdaccum <- sites <- perm <- NULL
+ perm <- array(dim = c(n, permutations))
+ for (i in 1:permutations)
+ {
+ perm[, i] <- accumulator(x, sample(n),Cmatrix)
+ }
+ sites <- 1:n
+ specaccum <- apply(perm, 1, mean)
+ sdaccum <- apply(perm, 1, sd)
+ out <- list(call = match.call(), method = method, sites = sites, richness = specaccum, sd = sdaccum, perm = perm)
+ class(out) <- "specaccum"
+ out
+}
\ No newline at end of file
More information about the Picante-commits
mailing list