[Analogue-commits] r229 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 23 10:48:37 CEST 2011


Author: gsimpson
Date: 2011-08-23 10:48:37 +0200 (Tue, 23 Aug 2011)
New Revision: 229

Added:
   pkg/R/varExpl.R
   pkg/man/varExpl.Rd
Log:
Adds a variance explained generic and methods

Added: pkg/R/varExpl.R
===================================================================
--- pkg/R/varExpl.R	                        (rev 0)
+++ pkg/R/varExpl.R	2011-08-23 08:48:37 UTC (rev 229)
@@ -0,0 +1,28 @@
+varExpl <- function(object, ...)
+    UseMethod("varExpl")
+
+varExpl.default <- function(object, ...) {
+    stop("No default method for 'varExpl()'")
+}
+
+varExpl.cca <- function(object, axes = 1L, cumulative = FALSE,
+                        pcent = FALSE, ...) {
+    if(is.null(object$CCA))
+        res <- object$CA$eig[axes]
+    else
+        res <- object$CCA$eig[axes]
+    res <- res / object$tot.chi
+    if(cumulative)
+        res <- cumsum(res)
+    if(pcent)
+        res <- 100 * res
+    res
+}
+
+varExpl.prcurve <- function(object, pcent = FALSE, ...) {
+    res <- 1 - object$dist / object$totalDist
+    if(pcent)
+        res <- 100 * res
+    names(res) <- "PrC"
+    res
+}

Added: pkg/man/varExpl.Rd
===================================================================
--- pkg/man/varExpl.Rd	                        (rev 0)
+++ pkg/man/varExpl.Rd	2011-08-23 08:48:37 UTC (rev 229)
@@ -0,0 +1,72 @@
+\name{varExpl}
+\alias{varExpl}
+\alias{varExpl.default}
+\alias{varExpl.cca}
+\alias{varExpl.prcurve}
+
+\title{
+  Variance explained by ordination axes
+}
+\description{
+  Extracts information about the variance explained by ordination axes
+  and expresses it in a variety of ways.
+}
+\usage{
+varExpl(object, \dots)
+
+\method{varExpl}{cca}(object, axes = 1L, cumulative = FALSE,
+        pcent = FALSE, \dots)
+
+\method{varExpl}{prcurve}(object, pcent = FALSE, \dots)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{object}{an R object of an appropriate type. Currently only for
+    objects that inherit from classes \code{"cca"} or \code{"prcurve"}.}
+  \item{axes}{numeric vector indicating which axes to compute variance
+    explained for.}
+  \item{cumulative}{logical; should the variance be explained as a
+    cumulative sum over the axes?}
+  \item{pcent}{logical; should the variance explained be expressed as a
+    percentage of the total variance.}
+  \item{\dots}{additional arguments passed to other methods. Currently
+    not used.}
+}
+%\details{
+%
+%}
+\value{
+  A numeric vector variance explained by each axis.
+}
+%\references{
+%
+%}
+\author{
+  Gavin L. Simpson
+}
+
+%\note{
+%
+%}
+
+\seealso{
+  See \code{\link{cca}} and \code{\link{prcurve}} for functions that
+  produce objects that \code{varExpl()} can work with.
+}
+\examples{
+
+data(abernethy)
+
+## Remove the Depth and Age variables
+abernethy2 <- abernethy[, -(37:38)]
+
+## Fit PCA
+aber.pca <- rda(abernethy2)
+
+## Distance along the first PCA axis
+varExpl(aber.pca)
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{multivariate}
+\keyword{utility}



More information about the Analogue-commits mailing list