[Vegan-commits] r2326 - in branches/2.0: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Oct 14 16:19:03 CEST 2012


Author: jarioksa
Date: 2012-10-14 16:19:03 +0200 (Sun, 14 Oct 2012)
New Revision: 2326

Modified:
   branches/2.0/R/clamtest.R
   branches/2.0/R/dispindmorisita.R
   branches/2.0/R/plot.procrustes.R
   branches/2.0/inst/ChangeLog
   branches/2.0/man/clamtest.Rd
   branches/2.0/man/dispindmorisita.Rd
Log:
merge improvements in dispindmorisita (r2318) and fixes in clamtest (r2139, 2323) and plot.procrustes (r2325)

Modified: branches/2.0/R/clamtest.R
===================================================================
--- branches/2.0/R/clamtest.R	2012-10-14 06:57:34 UTC (rev 2325)
+++ branches/2.0/R/clamtest.R	2012-10-14 14:19:03 UTC (rev 2326)
@@ -97,7 +97,7 @@
     tmp <- ifelse(cbind(gen, specY, specX, sr), 1, 0)
     types <- c("Generalist", paste("Specialist", glabel[1], sep="_"),
         paste("Specialist", glabel[2], sep="_"), "Too_rare")
-    classes <- as.factor((1:4)[rowSums(tmp*col(tmp))])
+    classes <- factor((1:4)[rowSums(tmp*col(tmp))], levels=1:4)
     levels(classes) <- c("Generalist", paste("Specialist", glabel[1], sep="_"),
         paste("Specialist", glabel[2], sep="_"), "Too_rare")
     tab <- data.frame(Species=spp, y=Y, x=X, Classes=classes)

Modified: branches/2.0/R/dispindmorisita.R
===================================================================
--- branches/2.0/R/dispindmorisita.R	2012-10-14 06:57:34 UTC (rev 2325)
+++ branches/2.0/R/dispindmorisita.R	2012-10-14 14:19:03 UTC (rev 2326)
@@ -1,17 +1,18 @@
 `dispindmorisita` <-
-function(x, unique.rm=FALSE, crit=0.05)
+function(x, unique.rm=FALSE, crit=0.05, na.rm=FALSE)
 {
     x <- as.matrix(x)
     n <- nrow(x)
     p <- ncol(x)
-    Imor <- numeric(p)
     Imor <- apply(x, 2, function(y) n * ((sum(y^2) - sum(y)) / (sum(y)^2 - sum(y))))
     Smor <- Imor
     chicr <- qchisq(c(0+crit/2, 1-crit/2), n-1, lower.tail=FALSE)
     Muni <- apply(x, 2, function(y) (chicr[2] - n + sum(y)) / (sum(y) - 1))
     Mclu <- apply(x, 2, function(y) (chicr[1] - n + sum(y)) / (sum(y) - 1))
+    rs <- colSums(x, na.rm=na.rm)
+    pchi <- pchisq(Imor * (rs - 1) + n - rs, n-1, lower.tail=FALSE)
     for (i in 1:p) {
-        if (apply(x, 2, sum)[i] > 1) {
+        if (rs[i] > 1) {
             if (Imor[i] >= Mclu[i] && Mclu[i] > 1)
                 Smor[i] <- 0.5 + 0.5 * ((Imor[i] - Mclu[i]) / (n - Mclu[i]))
             if (Mclu[i] > Imor[i] && Imor[i] >=1)
@@ -22,8 +23,9 @@
                 Smor[i] <- -0.5 + 0.5 * ((Imor[i] - Muni[i]) / Muni[i])
         }
     }
-    out <- data.frame(imor=Imor,mclu=Mclu,muni=Muni,imst=Smor)
-    usp <- which(apply(x > 0, 2, sum) == 1)
+    out <- data.frame(imor = Imor, mclu = Mclu, muni = Muni,
+        imst = Smor, pchisq = pchi)
+    usp <- which(colSums(x > 0) == 1)
     if (unique.rm && length(usp) != 0)
         out <- out[-usp,]
     out

Modified: branches/2.0/R/plot.procrustes.R
===================================================================
--- branches/2.0/R/plot.procrustes.R	2012-10-14 06:57:34 UTC (rev 2325)
+++ branches/2.0/R/plot.procrustes.R	2012-10-14 14:19:03 UTC (rev 2326)
@@ -32,8 +32,9 @@
                 b <- abs(x$rotation[1,1])
                 EPS <- 1e-8
                 if (1 - b > EPS && b > EPS) {
-                    abline(0, tan(acos(x$rotation[1, 1])), lty = 1)
-                    abline(0, 1/tan(acos(-x$rotation[1, 1])), lty = 1)
+                    rot <- x$rotation
+                    abline(0, rot[1,2]/rot[1,1], lty = 1)
+                    abline(0, rot[2,2]/rot[2,1], lty = 1)
                 } else {
                     abline(v = 0, h = 0)
                 }

Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog	2012-10-14 06:57:34 UTC (rev 2325)
+++ branches/2.0/inst/ChangeLog	2012-10-14 14:19:03 UTC (rev 2326)
@@ -4,6 +4,10 @@
 
 Version 2.0-6 (opened October 8, 2012)
 
+	* merge 2318: dispindmorista gains p-values of output
+	* merge 2319, 2323: clamtest bug fixes and clarifications-
+	* merge 2325: fix rotation of axes in 2-d plot.procrustes().
+	
 Version 2.0-5 (released October 8, 2012)
 
 	* merge r2309: anova.cca.Rd edits.

Modified: branches/2.0/man/clamtest.Rd
===================================================================
--- branches/2.0/man/clamtest.Rd	2012-10-14 06:57:34 UTC (rev 2325)
+++ branches/2.0/man/clamtest.Rd	2012-10-14 14:19:03 UTC (rev 2326)
@@ -24,7 +24,8 @@
 }
   \item{groups}{
 A vector identifying the two habitats. Must have exactly
-two unique values or levels.
+two unique values or levels. Habitat IDs in the grouping vector
+must match corresponding rows in the community matrix \code{comm}.
 }
   \item{coverage.limit}{
 Integer, below this limit the sample coverage based correction

Modified: branches/2.0/man/dispindmorisita.Rd
===================================================================
--- branches/2.0/man/dispindmorisita.Rd	2012-10-14 06:57:34 UTC (rev 2325)
+++ branches/2.0/man/dispindmorisita.Rd	2012-10-14 14:19:03 UTC (rev 2326)
@@ -6,33 +6,42 @@
 Calculates the Morisita index of dispersion, standardized index values, and the so called clumpedness and uniform indices.
 }
 \usage{
-dispindmorisita(x, unique.rm = FALSE, crit = 0.05)
+dispindmorisita(x, unique.rm = FALSE, crit = 0.05, na.rm = FALSE)
 }
 \arguments{
-  \item{x}{community data matrix, with sites (samples) as rows and species as columns.}
-  \item{unique.rm}{logical, if \code{TRUE}, unique species (occurring in only one sample) are removed from the result.}
-  \item{crit}{two-sided p-value used to calculate critical Chi-squared values.}
+  \item{x}{community data matrix, with sites (samples) as rows and 
+    species as columns.}
+  \item{unique.rm}{logical, if \code{TRUE}, unique species (occurring 
+    in only one sample) are removed from the result.}
+  \item{crit}{two-sided p-value used to calculate critical 
+    Chi-squared values.}
+  \item{na.rm}{logical. 
+    Should missing values (including \code{NaN}) be omitted from the 
+    calculations?}
 }
 \details{
 The Morisita index of dispersion is defined as (Morisita 1959, 1962):
 
 \code{Imor = n * (sum(xi^2) - sum(xi)) / (sum(xi)^2 - sum(xi))}
 
-where \eqn{xi} is the count of individuals in sample \eqn{i}, and \eqn{n} is the
-number of samples (\eqn{i = 1, 2, \ldots, n}). \eqn{Imor} has values from 0 to
-\eqn{n}. In uniform (hyperdispersed) patterns its value falls between 0 and
-1, in clumped patterns it falls between 1 and \eqn{n}. For increasing sample
-sizes (i.e. joining neighbouring quadrats), \eqn{Imor} goes to \eqn{n} as the
-quadrat size approaches clump size. For random patterns, \eqn{Imor = 1} and
-counts in the samples follow Poisson frequency distribution.
+where \eqn{xi} is the count of individuals in sample \eqn{i}, and 
+\eqn{n} is the number of samples (\eqn{i = 1, 2, \ldots, n}). 
+\eqn{Imor} has values from 0 to \eqn{n}. In uniform (hyperdispersed) 
+patterns its value falls between 0 and 1, in clumped patterns it falls 
+between 1 and \eqn{n}. For increasing sample sizes (i.e. joining 
+neighbouring quadrats), \eqn{Imor} goes to \eqn{n} as the
+quadrat size approaches clump size. For random patterns, 
+\eqn{Imor = 1} and counts in the samples follow Poisson 
+frequency distribution.
 
-The deviation from random expectation can be tested using critical
-values of the Chi-squared distribution with \eqn{n-1} degrees of
-freedom. Confidence interval around 1 can be calculated by the clumped
+The deviation from random expectation (null hypothesis)
+can be tested using criticalvalues of the Chi-squared 
+distribution with \eqn{n-1} degrees of freedom. 
+Confidence intervals around 1 can be calculated by the clumped
 \eqn{Mclu} and uniform \eqn{Muni} indices (Hairston et al. 1971, Krebs
 1999) (Chi2Lower and Chi2Upper refers to e.g. 0.025 and 0.975 quantile
 values of the Chi-squared distribution with \eqn{n-1} degrees of
-freedom, respectively, for \code{alpha = 0.05}):
+freedom, respectively, for \code{crit = 0.05}):
 
 \code{Mclu = (Chi2Lower - n + sum(xi)) / (sum(xi) - 1)}
 
@@ -54,13 +63,15 @@
 }
 
 \value{ Returns a data frame with as many rows as the number of columns
-in the input data, and with four columns. Columns are: \code{imor}
+in the input data, and with four columns. Columns are: \code{imor} the
 unstandardized Morisita index, \code{mclu} the clumpedness index,
-\code{muni} the uniform index, \code{imst} standardized Morisita index.
+\code{muni} the uniform index, \code{imst} the standardized Morisita 
+index, \code{pchisq} the Chi-squared based probability for the null
+hypothesis of random expectation.
 }
 
 \references{
-  
+
 Morisita, M. 1959. Measuring of the dispersion of individuals and
 analysis of the distributional patterns.  \emph{Mem. Fac. Sci. Kyushu
 Univ. Ser. E} 2, 215--235.



More information about the Vegan-commits mailing list