[Vegan-commits] r1059 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 28 11:09:05 CET 2009


Author: jarioksa
Date: 2009-10-28 11:09:03 +0100 (Wed, 28 Oct 2009)
New Revision: 1059

Modified:
   pkg/vegan/R/pcnm.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/pcnm.Rd
Log:
making pcnm a vegan function

Modified: pkg/vegan/R/pcnm.R
===================================================================
--- pkg/vegan/R/pcnm.R	2009-10-28 09:38:12 UTC (rev 1058)
+++ pkg/vegan/R/pcnm.R	2009-10-28 10:09:03 UTC (rev 1059)
@@ -1,25 +1,18 @@
 "pcnm" <-
-    function(matdist, threshold, support = c("vegan", "ade4"), w)
+    function(dis, threshold, w)
 {
     EPS <- sqrt(.Machine$double.eps)
     wa.old <- options(warn = -1)
     on.exit(options(wa.old))
-    matdist <- as.dist(matdist)
+    dis <- as.dist(dis)
     if (missing(threshold)) {
-        support <- match.arg(support)
-        if (!missing(w) && support == "ade4")
-            stop("weights are not supported with 'ade4'")
-        threshold <- 
-            switch(support,
-                   vegan =  max(spantree(matdist)$dist),
-                   ade4 = max(neig2mat(mstree(matdist)) * as.matrix(matdist))
-                   )
+        threshold <- max(spantree(dis)$dist)
     }
-    matdist[matdist > threshold] <- 4*threshold
-    ## vegan:::wcmdscale used to be able to use weights which also
-    ## means that 'k' need not be given, but all vecctorw with >0
-    ## eigenvalues will be found
-    mypcnm <- wcmdscale(matdist, eig = TRUE, w=w)
+    dis[dis > threshold] <- 4*threshold
+    ## vegan:::wcmdscale is able to use weights which also means that
+    ## 'k' need not be given, but all vecctors with >0 eigenvalues
+    ## will be found
+    mypcnm <- wcmdscale(dis, eig = TRUE, w=w)
     res <- list(vectors = mypcnm$points, values = mypcnm$eig,
                 weights = mypcnm$weig)
     k <- ncol(mypcnm$points)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-10-28 09:38:12 UTC (rev 1058)
+++ pkg/vegan/inst/ChangeLog	2009-10-28 10:09:03 UTC (rev 1059)
@@ -4,6 +4,12 @@
 
 Version 1.16-32 (opened October 24, 2009)
 
+	* pcnm: new function for PCNM (Principal Coordinates of
+	Neighbourhood Matrix) with option for row weighs allowing PCNM for
+	cca. Based on Stéphane Dray's PCNM function in his (unreleased)
+	SpacemakeR package. Imported with history from sedarVegan in
+	http://sedar.r-forge.r-project.org/. 
+
 	* decostand: implemented Marti Anderson's log scaling of type
 	log(x, base = logbase) + 1 as a part of Feature Request #473. The
 	coding follows closely Etienne Laliberte's suggestion, and also

Modified: pkg/vegan/man/pcnm.Rd
===================================================================
--- pkg/vegan/man/pcnm.Rd	2009-10-28 09:38:12 UTC (rev 1058)
+++ pkg/vegan/man/pcnm.Rd	2009-10-28 10:09:03 UTC (rev 1059)
@@ -1,45 +1,84 @@
 \name{pcnm}
 \alias{pcnm}
-\title{ Function to compute classical PCNM(Principal Coordinates of Neighborhood Matrix). }
+\title{ Function to compute classical PCNM (Principal Coordinates of
+  Neighbourhood Matrix). }
 \description{
   This function computed classical PCNM by the principal coordinate
   analysis of a truncated distance matrix. 
 }
 \usage{
-pcnm(matdist, threshold, support = c("vegan", "ade4"), w)
+pcnm(matdist, threshold, w)
 }
 
 \arguments{
-  \item{matdist}{ A distance matrix. }
-  \item{threshold}{ A threshold value or truncation distance. If missing,
-    minimum distance giving connected network will be used. This is found
-    as the longest distance in the minimum spanning tre of
-    \code{matdist}. }
-  \item{support}{Use either \pkg{vegan} or \pkg{ade4} function for the
-    minimum spanning tree.}
+  \item{dis}{ A distance matrix. }
+  \item{threshold}{ A threshold value or truncation distance. If
+    missing, minimum distance giving connected network will be
+    used. This is found as the longest distance in the minimum spanning
+    tree of \code{dis}. }
   \item{w}{Prior weights for rows.}
 }
 
 \details{
-  The function is based on \code{pcnm} function in Dray's
+  Principal Coordinates of Neighbourhood Matrix (PCNM) map distances
+  between rows onto rectangular matrix on rows using a truncation
+  threshold for long distances (Borcard & Legendre 2002). If original
+  distances were Euclidean distances in two dimensions (like normal
+  spatial distances), they could be mapped onto two dimensions if there
+  is no truncation of distances. Because of truncation, there will be a
+  higher number of principal coordinates. The selection of truncation
+  distance has a huge influence on the PCNM vectors. The default is to
+  use the longest distance to keep data connected. The distances above
+  truncation threshold are given an arbitrary value of 4 times
+  threshold.  For regular data, the first PCNM vectorsshow a wide scale
+  variation and later PCNM vectors show smaller scale variation (Borcard
+  & Legendre 2002), but for irregular data the intepretation is not as
+  clear.
+
+  The PCNM functions are used to express distances in rectangular form
+  that is similar to normal explanatory variables used in, e.g.,
+  constrained ordination (\code{\link{rda}}, \code{\link{cca}} and
+  \code{\link{capscale}}) or univariate regression (\code{\link{lm}})
+  together with environmental variables (row weights should be supplied
+  with \code{\link{cca}}; see Examples). This is regarded as a more
+  powerful method than forcing rectangular environmental data into
+  distances and using them in partial mantel analysis
+  (\code{\link{mantel.partial}}) together with geographic distances
+  (Legendre et al. 2008, but see Tuomisto & Ruokolainen 2008).
+  
+  The function is based on \code{pcnm} function in Dray's unreleased
   \pkg{spacemakeR} package. The differences are that the current
-  function can use either \code{\link[vegan]{spantree}} of \pkg{vegan}
-  or \code{\link[ade4]{mstree}} and \code{\link[ade4]{neig2mat}} of
-  \pkg{ade4} as internal support function. The current function also can
-  use prior weights for rows by using weighted metric scaling of
-  \code{\link[vegan]{wcmscale}} of \pkg{vegan}. The use of row weights
-  allows finding orthonormal PCNMs also for correspondence analysis
-  (e.g., \code{\link[vegan]{cca}} or \code{\link[ade4]{cca}}).  }
+  function usesr \code{\link[vegan]{spantree}} as an internal support
+  function. The current function also can use prior weights for rows by
+  using weighted metric scaling of \code{\link[vegan]{wcmscale}} of
+  \pkg{vegan}. The use of row weights allows finding orthonormal PCNMs
+  also for correspondence analysis (e.g., \code{\link[vegan]{cca}} or
+  \code{\link[ade4]{cca}}).
+}
 
 \value{
   A list of three elements:
-  \item{values }{Eigenvalues obtained by the principal coordinates analysis.}
-  \item{vectors }{Eigenvectors obtained by the principal coordinates analysis. They have been normalized to unit norm.}
+  \item{values }{Eigenvalues obtained by the principal coordinates
+    analysis.} 
+  \item{vectors }{Eigenvectors obtained by the principal coordinates
+    analysis. They have been normalized to unit norm.}
  \item{threshold}{Truncation distance.} 
 }
-\references{ Borcard D. and Legendre P. (2002) All-scale spatial analysis of ecological data by means of principal coordinates of neighbour matrices. \emph{Ecological Modelling} \bold{153}, 51--68. }
-\author{ Stephane Dray, adapted to vegan by Jari Oksanen }
-\seealso{ \code{\link[vegan]{spantree}}, \code{\link[ade4]{mstree}}. }
+\references{
+  Borcard D. and Legendre P. (2002) All-scale spatial analysis of
+  ecological data by means of principal coordinates of neighbour
+  matrices. \emph{Ecological Modelling} \bold{153}, 51--68.
+  
+  Legendre, P., Bordard, D and Peres-Neto, P. (2008) Analyzing or
+  explaining beta diversity? Comment. \emph{Ecology} \bold{89},
+  3238--3244.
+
+  Tuomisto, H. & Ruokolainen, K. (2008) Analyzing or explaining beta
+  diversity? A reply. \emph{Ecology} \bold{89}, 3244--3256.
+}
+
+\author{Jari Oksanen, based on the code of Stephane Dray.}
+\seealso{ \code{\link[vegan]{spantree}}. }
 \examples{
 data(mite.xy)
 pcnm1 <- pcnm(dist(mite.xy))
@@ -55,3 +94,4 @@
 ord <- cca(mite ~ pcnmw$vectors)
 }
 \keyword{ spatial }
+\keyword{ multivariate }



More information about the Vegan-commits mailing list