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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 14 08:59:05 CEST 2009


Author: jarioksa
Date: 2009-05-14 08:59:05 +0200 (Thu, 14 May 2009)
New Revision: 819

Added:
   pkg/vegan/R/eigenvals.R
   pkg/vegan/man/eigenvals.Rd
Modified:
   pkg/vegan/DESCRIPTION
   pkg/vegan/inst/ChangeLog
Log:
eigenvals: a new function to extract eigenvalus from an ordination result

Modified: pkg/vegan/DESCRIPTION
===================================================================
--- pkg/vegan/DESCRIPTION	2009-05-04 20:03:58 UTC (rev 818)
+++ pkg/vegan/DESCRIPTION	2009-05-14 06:59:05 UTC (rev 819)
@@ -1,7 +1,7 @@
 Package: vegan
 Title: Community Ecology Package
-Version: 1.16-18
-Date: April 21, 2009
+Version: 1.16-19
+Date: May 14, 2009
 Author: Jari Oksanen, Roeland Kindt, Pierre Legendre, Bob O'Hara, Gavin L. Simpson, 
    Peter Solymos, M. Henry H. Stevens, Helene Wagner  
 Maintainer: Jari Oksanen <jari.oksanen at oulu.fi>

Added: pkg/vegan/R/eigenvals.R
===================================================================
--- pkg/vegan/R/eigenvals.R	                        (rev 0)
+++ pkg/vegan/R/eigenvals.R	2009-05-14 06:59:05 UTC (rev 819)
@@ -0,0 +1,54 @@
+# Extract eigenvalues from an object that has them
+
+`eigenvals` <-
+    function(x)
+{
+    UseMethod("eigenvals")
+}
+
+`eigenvals.default`<-
+    function(x)
+{
+    ## svd and eigen return unspecified 'list', see if this could be
+    ## either of them
+    if (is.list(x)) {
+        ## eigen
+        if (length(x) == 2 && all(names(x) %in% c("values", "vectors")))
+            return(x$values)
+        ## svd: return squares of singular values
+        if (length(x) == 3 && all(names(x) %in% c("d", "u", "v")))
+            return(x$d^2)
+        else
+            stop("No eigenvalues found")
+    }
+    else
+        stop("No eigenvalues found")
+}
+
+## squares of sdev 
+`eigenvals.prcomp` <-
+    function(x)
+{
+    x$sdev^2
+}
+
+## squares of sdev
+`eigenvals.princomp` <-
+    function(x)
+{
+    x$sdev^2
+}
+
+## concatenate constrained and unconstrained eigenvalues in cca, rda
+## and capscale (vegan) -- ignore pCCA component
+`eigenvals.cca` <- function(x)
+{
+   c(x$CCA$eig, x$CA$eig) 
+}
+
+## wcmdscale (in vegan)
+`eigenvals.wcmdscale` <-
+    function(x)
+{
+    x$eig
+}

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-05-04 20:03:58 UTC (rev 818)
+++ pkg/vegan/inst/ChangeLog	2009-05-14 06:59:05 UTC (rev 819)
@@ -2,10 +2,17 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 1.16-18 (opened April 21, 2009)
+Version 1.16-19 (opened May 14, 2009)
 
-	* tsallis: got new argument 'hill' similar that of renyi.
+	* eigenvals: new function to extract eigenvalues of cca, rda,
+	capscale (constrained & unconstrained), wcmdscale, prcomp,
+	princomp, eigen and svd. For svd returns squares of singular
+	values, and for prcomp and princomp squares of 'sdev'.
 
+Version 1.16-18 (closed May 14, 2009)
+
+	* tsallis: got new argument 'hill' similar to that of renyi.
+
 	* twostagechao: function that calculates multiple-community
 	similarity based on Chao et al. 2008 (Biometrics 64, 1178-86).
 	Some debugging is needed since it cannot reproduce the numbers

Added: pkg/vegan/man/eigenvals.Rd
===================================================================
--- pkg/vegan/man/eigenvals.Rd	                        (rev 0)
+++ pkg/vegan/man/eigenvals.Rd	2009-05-14 06:59:05 UTC (rev 819)
@@ -0,0 +1,62 @@
+\name{eigenvals}
+\Rdversion{1.1}
+\alias{eigenvals}
+
+\title{
+  Extract Eigenvalues from an Ordination Object
+}
+\description{
+  Function extracts eigenvalues from an object that has them. Many
+  multivariate methods return such objects. 
+}
+\usage{
+eigenvals(x)
+}
+
+\arguments{
+  \item{x}{
+    An object from which to extract eigenvalues.
+}
+}
+
+\details{
+  This is a generic function that has methods for \code{\link{cca}},
+  \code{\link{wcmdscale}}, \code{\link{prcomp}} and
+  \code{\link{princomp}} result objects. The default method also
+  extracts eigenvalues if the result looks like being from
+  \code{\link{eigen}} or \code{\link{svd}}.  Functions
+  \code{\link{prcomp}} and \code{\link{princomp}} contain square roots
+  of eigenvalues that all called standard deviations, but
+  \code{eigenvals} function returns their squares.  Function
+  \code{\link{svd}} contains singular values, but function
+  \code{eigenvals} returns their squares. For constrained ordination
+  methods \code{\link{cca}}, \code{\link{rda}} and
+  \code{\link{capscale}} the function returns the both constrained and
+  unconstrained eigenvalues concatenated in one vector, but the partial
+  component will be ignored.
+}
+
+\value{
+  Vector of eigenvalues.
+}
+
+\author{
+ Jari Oksanen.
+}
+
+\seealso{
+ \code{\link{eigen}}, \code{\link{svd}}, \code{\link{prcomp}},
+ \code{\link{princomp}}, \code{\link{cca}}, \code{\link{rda}},
+ \code{\link{capscale}}, \code{\link{wcmdscale}},
+ \code{\link{cca.object}}. 
+}
+\examples{
+data(varespec)
+data(varechem)
+mod <- cca(varespec ~ Al + P + K, varechem)
+ev <- eigenvals(mod)
+ev
+ev/sum(ev)
+}
+\keyword{ multivariate }
+



More information about the Vegan-commits mailing list