[Vegan-commits] r2318 - in pkg/vegan: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Oct 9 18:11:20 CEST 2012
Author: psolymos
Date: 2012-10-09 18:11:20 +0200 (Tue, 09 Oct 2012)
New Revision: 2318
Modified:
pkg/vegan/R/dispindmorisita.R
pkg/vegan/man/dispindmorisita.Rd
Log:
per user request to add p-values to output (plus some clean-up)
Modified: pkg/vegan/R/dispindmorisita.R
===================================================================
--- pkg/vegan/R/dispindmorisita.R 2012-10-08 14:15:27 UTC (rev 2317)
+++ pkg/vegan/R/dispindmorisita.R 2012-10-09 16:11:20 UTC (rev 2318)
@@ -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: pkg/vegan/man/dispindmorisita.Rd
===================================================================
--- pkg/vegan/man/dispindmorisita.Rd 2012-10-08 14:15:27 UTC (rev 2317)
+++ pkg/vegan/man/dispindmorisita.Rd 2012-10-09 16:11:20 UTC (rev 2318)
@@ -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