[Analogue-commits] r141 - in pkg: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 9 12:36:36 CEST 2009


Author: gsimpson
Date: 2009-08-09 12:36:32 +0200 (Sun, 09 Aug 2009)
New Revision: 141

Modified:
   pkg/DESCRIPTION
   pkg/R/tran.R
   pkg/inst/ChangeLog
   pkg/man/tran.Rd
Log:
new formula method for tran()

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2009-07-19 18:57:31 UTC (rev 140)
+++ pkg/DESCRIPTION	2009-08-09 10:36:32 UTC (rev 141)
@@ -1,7 +1,7 @@
 Package: analogue
 Type: Package
 Title: Analogue and weighted averaging methods for palaeoecology
-Version: 0.6-14
+Version: 0.6-15
 Date: $Date$
 Depends: R (>= 2.5.0), stats, graphics, vegan, lattice, MASS
 Author: Gavin L. Simpson, Jari Oksanen

Modified: pkg/R/tran.R
===================================================================
--- pkg/R/tran.R	2009-07-19 18:57:31 UTC (rev 140)
+++ pkg/R/tran.R	2009-08-09 10:36:32 UTC (rev 141)
@@ -1,4 +1,8 @@
-`tran` <- function(x, method, a = 1, b = 0, p = 2, base = exp(1),
+`tran` <- function(x, ...) {
+    UseMethod("tran")
+}
+
+`tran.default` <- function(x, method, a = 1, b = 0, p = 2, base = exp(1),
                    na.rm = FALSE, na.value = 0, ...) {
     wasDF <- is.data.frame(x)
     dim.nams <- dimnames(x)
@@ -47,3 +51,17 @@
     attr(x, "tran") <- method
     return(x)
 }
+
+`tran.formula` <- function(formula, data = NULL,
+                           subset = NULL,
+                           na.action = na.pass, ...) {
+    mf <- match.call()
+    mf[[1]] <- as.name("model.frame")
+    mt <- terms(formula, data = data, simplify = TRUE)
+    mf[[2]] <- formula(mt, data = data)
+    mf$na.action <- substitute(na.action)
+    dots <- list(...)
+    mf[[names(dots)]] <- NULL
+    mf <- eval(mf,parent.frame())
+    tran.default(mf, ...)
+}

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2009-07-19 18:57:31 UTC (rev 140)
+++ pkg/inst/ChangeLog	2009-08-09 10:36:32 UTC (rev 141)
@@ -1,8 +1,13 @@
 analogue Change Log
 
+Version 0.6-15
+
+	* tran: new 'formula' method allows simple selection or exclusion
+	of variables from the set to be 'tran'sformed.
+
 Version 0.6-14
 
-	* tran; new transformation and standardization methods for the power 
+	* tran: new transformation and standardization methods for the power 
 	and 4th root transformation, the log ratio transformation for 
 	compositional data, plus row (sample) centring. 
 

Modified: pkg/man/tran.Rd
===================================================================
--- pkg/man/tran.Rd	2009-07-19 18:57:31 UTC (rev 140)
+++ pkg/man/tran.Rd	2009-08-09 10:36:32 UTC (rev 141)
@@ -1,5 +1,7 @@
 \name{tran}
 \alias{tran}
+\alias{tran.default}
+\alias{tran.formula}
 \concept{transformation}
 \title{Common data transformations and standardizations}
 \description{
@@ -7,10 +9,17 @@
   palaeoecological data. The function acts as a wrapper to function
   \code{\link[vegan]{decostand}} in package vegan for several of the
   available options.
+
+  The \code{formula} method allows a convenient method for selecting or
+  excluding subsets of variables before applying the chosen
+  transformation.
 }
 \usage{
-tran(x, method, a = 1, b = 0, p = 2, base = exp(1), na.rm = FALSE,
-     na.value = 0, ...)
+\method{tran}{default}(x, method, a = 1, b = 0, p = 2, base = exp(1),
+     na.rm = FALSE, na.value = 0, \ldots)
+
+\method{tran}{formula}(formula, data = NULL, subset = NULL,
+     na.action = na.pass, \ldots)
 }
 \arguments{
   \item{x}{A matrix-like object.}
@@ -29,10 +38,18 @@
   \item{na.rm}{Should missing values be removed before some computations?}
   \item{na.value}{The value with which to replace missing values
     (\code{NA}).}
-  \item{\dots}{Arguments passed to \code{\link[vegan]{decostand}}.}
+  \item{\ldots}{Arguments passed to \code{\link[vegan]{decostand}}, or
+     other \code{tran} methods.}
+  \item{formula}{A model formula describing the variables to be
+     transformed. The formula should have only a right hand side,
+     e.g.~\code{~ foo + bar}.}
+   \item{data, subset, na.action}{See \code{\link{model.frame}} for
+     details on these arguments. \code{data} will generally be the
+     object or environment within which the variables in the forumla are
+     searched for.}
 }
 \details{
-  The function offers following tranformation and standardization
+  The function offers following transformation and standardization
   methods for community data:
   \itemize{
     \item \code{sqrt}: take the square roots of the observed values.
@@ -118,6 +135,15 @@
 
 ## apply Hellinger transformation
 spHell <- tran(swapdiat, "hellinger")
+
+## Dummy data to illustrate formula method
+d <- data.frame(A = runif(10), B = runif(10), C = runif(10))
+## simulate some missings
+d[sample(10,3), 1] <- NA
+## apply tran using formula
+tran(~ . - B, data = d, na.action = na.pass,
+     method = "missing", na.value = 0)
 }
 \keyword{ multivariate }
 \keyword{ manip }
+\keyword{ methods }



More information about the Analogue-commits mailing list