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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jul 4 19:46:22 CEST 2010


Author: gsimpson
Date: 2010-07-04 19:46:22 +0200 (Sun, 04 Jul 2010)
New Revision: 189

Added:
   pkg/R/fitted.timetrack.R
   pkg/R/initCurve.R
   pkg/R/plot.prcurve.R
   pkg/R/plot.timetrack.R
   pkg/R/prcurve.R
   pkg/R/smoothSpline.R
   pkg/R/timetrack.R
   pkg/man/plot.prcurve.Rd
   pkg/man/prcurve.Rd
   pkg/man/timetrack.Rd
Modified:
   pkg/DESCRIPTION
   pkg/inst/ChangeLog
Log:
add prcurve and timetrack plus associated functions. bump to 0.7-0 to prepare for release.

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-07-04 12:30:26 UTC (rev 188)
+++ pkg/DESCRIPTION	2010-07-04 17:46:22 UTC (rev 189)
@@ -1,9 +1,9 @@
 Package: analogue
 Type: Package
 Title: Analogue and weighted averaging methods for palaeoecology
-Version: 0.6-26
+Version: 0.7-0
 Date: $Date$
-Depends: R (>= 2.5.0), stats, graphics, vegan, lattice, grid, MASS
+Depends: R (>= 2.5.0), stats, graphics, vegan, lattice, grid, MASS, princurve
 Author: Gavin L. Simpson, Jari Oksanen
 Maintainer: Gavin L. Simpson <gavin.simpson at ucl.ac.uk>
 Description: Fits Modern Analogue Technique and Weighted Averaging transfer 

Added: pkg/R/fitted.timetrack.R
===================================================================
--- pkg/R/fitted.timetrack.R	                        (rev 0)
+++ pkg/R/fitted.timetrack.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,17 @@
+`fitted.timetrack` <-
+    function(object, type = c("passive", "ordination"),
+             model = NULL, ...)
+{
+    if(missing(type))
+        type <- "passive"
+    type <- match.arg(type)
+    model <- if(is.null(model)) {
+        if(is.null(object$ordination$CCA)) "CA" else "CCA"
+    }
+    if(isTRUE(all.equal(type, "passive"))) {
+        fit <- fitted(unclass(object), ...)
+    } else {
+        fit <- fitted(object$ordination, model = model, ...)
+    }
+    return(fit)
+}

Added: pkg/R/initCurve.R
===================================================================
--- pkg/R/initCurve.R	                        (rev 0)
+++ pkg/R/initCurve.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,36 @@
+## initCurve: initialise the PC from one of several starting
+## configurations
+initCurve <- function(X, method = c("ca","pca","random"),
+                      rank = FALSE, axis = 1) {
+    ## X must be a matrix, attempt to coerce
+    if(!isTRUE(all.equal(class(X), "matrix")))
+        X <- data.matrix(X)
+    ## set/select default method for starting configuration
+    if(missing(method)) {
+        method <- "ca"
+    } else {
+        method <- match.arg(method)
+    }
+    ## compute initial configuration
+    switch(method,
+           ca = {m <- cca(X)
+                 lambda <- as.vector(scores(m, choices = axis,
+                                            display = "sites",
+                                            scaling = 0))
+             },
+           pca = {m <- rda(X, scale = FALSE)
+                  lambda <- as.vector(scores(m, choices = axis,
+                                             display = "sites",
+                                             scaling = 0))
+              },
+           random = {lambda <- sample.int(NROW(X))
+                 }
+           )
+    dist <- sum(diag(var(X))) * (NROW(X) - 1)
+    ## Ordering of obs. along PCur
+    tag <- order(lambda)
+    if(rank)
+        lambda <- rank(lambda)
+    config <- list(s = X, tag = tag, lambda = lambda, dist = dist)
+    structure(config, class = "principal.curve")
+}

Added: pkg/R/plot.prcurve.R
===================================================================
--- pkg/R/plot.prcurve.R	                        (rev 0)
+++ pkg/R/plot.prcurve.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,21 @@
+## plot a principle curve in PCA space
+plot.prcurve <- function(x, data, axes = 1:2,
+                         seg = TRUE,
+                         col.seg = "forestgreen",
+                         col.curve = "red",
+                         lwd.curve = 2, ...) {
+    scl <- 0
+    ordi <- rda(data)
+    pred <- predict(ordi, x$s, type = "wa", scaling = scl)[,axes]
+    scrs <- scores(ordi, display = "sites", scaling = scl,
+                   choices = axes)
+    xlim <- range(scrs[,1], pred[,1])
+    ylim <- range(scrs[,2], pred[,2])
+    plot(ordi, display = "sites", scaling = scl, type = "n",
+         xlim = xlim, ylim = ylim, choices = axes, ...)
+    points(scrs, ...)
+    if(seg)
+        segments(scrs[,1], scrs[,2], pred[,1], pred[,2],
+                 col = col.seg)
+    lines(pred[x$tag, 1:2], lwd = lwd.curve, col = col.curve)
+}

Added: pkg/R/plot.timetrack.R
===================================================================
--- pkg/R/plot.timetrack.R	                        (rev 0)
+++ pkg/R/plot.timetrack.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,10 @@
+`plot.timetrack` <- function(x, choices = 1:2,
+                             pch = c(1,2),
+                             col = c("black","red"),
+                             ...) {
+    plt <- plot(x$ord, choices = choices, scaling = x$scaling,
+                type = "p", display = "sites", ...,
+                pch = pch[1], col = col[1])
+    ##points(fitted(x)[, choices])
+    lines(fitted(x)[, choices], pch = pch[2], col = col[2])
+}

Added: pkg/R/prcurve.R
===================================================================
--- pkg/R/prcurve.R	                        (rev 0)
+++ pkg/R/prcurve.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,121 @@
+## Fit a Principal Curve to matrix X
+## Wrapper to principal.curve() in package princurve
+## We use the original code plus our wrappers as pcurve()
+## in package pcurve is too complex for our needs
+
+## prcurve (named after prcomp): fits a principal curve to matrix X
+prcurve <- function(X, method = c("ca","pca","random"),
+                    smoother = smoothSpline,
+                    complexity, vary = FALSE, maxComp,
+                    finalCV = FALSE,
+                    axis = 1, rank = FALSE, stretch = 2,
+                    maxit = 10, trace = FALSE, thresh = 0.001,
+                    plotit = FALSE, ...) {
+    ## X should be a matrix, attempt to coerce
+    if(!isTRUE(all.equal(class(X), "matrix")))
+        X <- data.matrix(X)
+    ## set/select default method for starting configuration
+    if(missing(method))
+        method <- "ca"
+    else
+        method <- match.arg(method)
+    ## data stats
+    n <- NROW(X) ## number of observations
+    m <- NCOL(X) ## number of variables
+    ## starting configuration
+    config <- startConfig <- initCurve(X, method = method,
+                                       rank = rank,
+                                       axis = axis)
+    ## Need to sort out auto DF choices after pcurve::pcurve
+    ## Vary degrees of freedom per variable?
+    if(missing(complexity)) {
+        complexity <- numeric(length = m)
+        for(j in seq_along(complexity)) {
+            complexity[j] <- smoother(config$lambda, X[, j],
+                                      choose = TRUE, ...)$complexity
+        }
+        if(!vary) {
+            complexity <- rep(median(complexity), m)
+        }
+    } else {
+        if((len <- length(complexity)) == 1) {
+            complexity <- rep(complexity, m)
+        } else if(len != m) {
+            stop("Ambiguous 'complexity'; should be length 1 or NCOL(X)")
+        }
+    }
+    if(missing(maxComp))
+        maxComp <- 5 * log10(n)
+    ## fix-upreset complexity > maxComp to maxComp
+    complexity[complexity > maxComp] <- maxComp
+    ##
+    iter <- 0L
+    if(trace)
+        writeLines(sprintf("Initial curve: d.sq: %.4f", config$dist))
+    ##dist.raw <- sum(diag(var(X))) * (NROW(X) - 1)
+    dist.old <- sum(diag(var(X)))
+    s <- matrix(NA, nrow = n, ncol = m)
+    converged <- (abs((dist.old - config$dist)/dist.old) <=
+                  thresh)
+    ## Start iterations ----------------------------------------------
+    while (!converged && iter < maxit) {
+        iter <- iter + 1L
+        for(j in seq_len(m)) {
+            s[, j] <- fitted(smoother(config$lambda, X[, j],
+                                      complexity = complexity[j],
+                                      choose = FALSE, ...))
+        }
+        dist.old <- config$dist
+        config <- get.lam(X, s = s, stretch = stretch)
+        class(config) <- "prcurve"
+        ## Converged?
+        converged <- (abs((dist.old - config$dist)/dist.old) <=
+                      thresh)
+        if(plotit)
+            plot(config, X, sub = paste("Iteration:", iter))
+        if (trace)
+            writeLines(sprintf(paste("Iteration %",
+                                     max(3, nchar(maxit)),
+                                     "i: d.sq: %.4f", sep = ""),
+                               iter, config$dist))
+    }
+    ## End iterations ------------------------------------------------
+    ## if we want a final CV spline fit?
+    if(finalCV) {
+        iter <- iter + 1L
+        for(j in seq_len(n)) {
+            sFit <- smoother(config$lambda, X[, j],
+                             cv = TRUE, choose = TRUE, ...)
+            s[, j] <- if(sFit$complexity > maxComp) {
+                ## too complex, turn of CV and refit with max df allowed
+                fitted(smoother(config$lambda, X[, j], cv = FALSE,
+                                choose = FALSE,
+                                complexity = maxComp,
+                                ...))
+            } else {
+                fitted(sFit)
+            }
+        }
+        config <- get.lam(X, s = config$s, stretch = stretch)
+        class(config) <- "prcurve"
+        if(plotit) {
+            ## plot the iteration
+            plot(config, X)
+        }
+        if (trace)
+            writeLines(sprintf(paste("Iteration %",
+                                     max(3, nchar(maxit)),
+                                     "s: d.sq: %.4f", sep = ""),
+                               "CV", config$dist))
+    }
+    names(config$tag) <- names(config$lambda) <-
+        rownames(config$s) <- rownames(X)
+    colnames(config$s) <- names(complexity) <- colnames(X)
+    config$converged <- converged
+    config$iter <- iter
+    config$totalDist <- startConfig$dist
+    config$complexity <- complexity
+    config$call <- match.call()
+    class(config) <- c("prcurve")
+    return(config)
+}

Added: pkg/R/smoothSpline.R
===================================================================
--- pkg/R/smoothSpline.R	                        (rev 0)
+++ pkg/R/smoothSpline.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,30 @@
+## smoothSpline: smootherFcn supplied to principal.curve
+## again a wrapper but allow us to specify De'ath's recommended
+## smoother strategy
+smoothSpline <- function(lambda, x, choose = TRUE,
+                         complexity, ..., penalty = 1,
+                         cv = FALSE, keep.data = FALSE,
+                         control.spar = list(low = 0)) {
+    ## complexity is the 'df' argument
+    ## choose selects whether to use fixed complexity or allow
+    ## underlying fitting function to return complexity
+    ord <- order(lambda)
+    lambda <- lambda[ord]
+    x <- x[ord]
+    if(choose) { ## choose complexity
+        f <- smooth.spline(lambda, x, ...,
+                           penalty = penalty,
+                           keep.data = keep.data, cv = cv,
+                           control.spar = control.spar)
+    } else { ## use specified complexity
+        f <- smooth.spline(lambda, x, ..., df = complexity,
+                           penalty = penalty, cv = cv,
+                           keep.data = keep.data,
+                           control.spar = control.spar)
+    }
+    p <- predict(f, x=lambda)$y
+    res <- list(lambda = lambda, x = x, fitted.values = p,
+                complexity = f$df)
+    class(res) <- "prcurveSmoother"
+    return(res)
+}

Added: pkg/R/timetrack.R
===================================================================
--- pkg/R/timetrack.R	                        (rev 0)
+++ pkg/R/timetrack.R	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,93 @@
+## produce an object that contains an ordination
+## and predict new locations for core samples
+`timetrack` <- function(X, passive, env,
+                        method = c("cca", "rda"),
+                        transform = "none",
+                        formula, ##type = c("wa","lc"),
+                        scaling = 3, rank = "full",
+                        model = c("CCA", "CA"), ...) {
+    namX <- deparse(substitute(X))
+    namP <- deparse(substitute(passive))
+    ## Apply a transformation - let tran deal with arg matching
+    if(!isTRUE(all.equal(transform, "none"))) {
+        X <- tran(X, method = transform, ...)
+        passive <- tran(passive, method = transform, ...)
+    }
+    ## merge X and passive
+    dat <- join(X, passive, type = "left")
+    X <- dat[[1]]
+    passive <- dat[[2]]
+    ## common set of species
+    tmp <- colSums(X > 0) > 0 ##& colSums(passive > 0) > 0
+    X <- X[, tmp]
+    passive <- passive[, tmp]
+    ## check what type of ordination is required
+    if(isTRUE(missing(method)))
+        method <- "cca"
+    method <- match.arg(method)
+    FUN <- match.fun(method)
+    ## if no env do unconstrained
+    if(isTRUE(missing(env))) {
+        namE <- NA
+        formula <- FALSE
+        ord <- FUN(X = X, ...)
+    } else {
+        namE <- deparse(substitute(env))
+        ## check env is same length as nrow(X)
+        if(!isTRUE(all.equal(NROW(env), nrow(X))))
+            stop("'X' and 'env' imply different numbers of observations")
+        ## check if a formula is present
+        if(isTRUE(missing(formula))) {
+            formula <- FALSE
+            ord <- FUN(X = X, Y = env, ...)
+        } else {
+            ord <- FUN(formula = formula, ...)
+        }
+    }
+    ## process predict args
+    ##if(isTRUE(missing(type)))
+    ##    type <- "wa"
+    ##type <- match.arg(type)
+    if(isTRUE(missing(model)))
+        model <- "CCA"
+    model <- match.arg(model)
+    ## fitted values for passive
+    pred <- predict(ord, newdata = passive, type = "wa",
+                    scaling = scaling, model = "CCA", rank = rank)
+    pred2 <- predict(ord, newdata = passive, type = "wa",
+                     scaling = scaling, model = "CA", rank = rank)
+    pred <- cbind(pred, pred2)
+    nams <- list(X = namX, passive = namP, env = namE)
+    ## return object
+    res <- list(ordination = ord, fitted.values = pred,
+                method = method, formula = formula, #type = type,
+                scaling = scaling, rank = rank, model = model,
+                labels = nams, call = match.call())
+    class(res) <- "timetrack"
+    return(res)
+}
+
+`print.timetrack` <- function(x, ...) {
+    cat("\n")
+    writeLines(strwrap("Timetrack Ordination", prefix = "\t"))
+    cat("\n")
+    writeLines(strwrap(pasteCall(x$call)))
+    cat("\n")
+    writeLines(strwrap("Ordination Output:"))
+    ##cat("\n")
+    print(x$ordination, ...)
+    invisible(x)
+}
+
+## TODO
+## scores methods - should extract the relevant scores from
+## the 'ordination'
+## plot methods
+
+## require(analogue)
+## data(rlgh, swapdiat)
+## mod <- timetrack(swapdiat, rlgh, transform = "hellinger",
+##                  method = "rda")
+## mod
+## plot(mod)
+

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-07-04 12:30:26 UTC (rev 188)
+++ pkg/inst/ChangeLog	2010-07-04 17:46:22 UTC (rev 189)
@@ -1,9 +1,25 @@
 analogue Change Log
 
+Version 0.7-0
+
+	* timetrack: new function to passively project sediment core
+	samples within an ordination of training or reference set
+	samples. Both unconstrained and constrained ordinations are
+	supported using the Vegan package. 'fitted' and 'plot' methods
+	are available.
+
+	* prcurve: new function to fit principal curves to sediment
+	core samples. A 'plot' method is also provided.
+
+	Several support functions are also provided; 'smoothSpline' is
+	a wrapper to 'smooth.spline' for fitting splines to individual
+	species in order to fit the principal curve. 'initCurve'
+	implements several methods for initialising the principal curve.
+
 Version 0.6-26
 
 	* abernethy: New data set containing the classic Abernethy Forest
-	data of Birks and Mathewes (1978).
+	data of Birks and Mathewes (1978)
 
 	* Stratiplot: Preserves the names component as far as is
 	possible, even to the extent of processing the names after the

Added: pkg/man/plot.prcurve.Rd
===================================================================
--- pkg/man/plot.prcurve.Rd	                        (rev 0)
+++ pkg/man/plot.prcurve.Rd	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,69 @@
+\name{plot.prcurve}
+\alias{plot.prcurve}
+\title{
+Plot a fitted principal curve in PCA space
+}
+\description{
+Projects the principal curve into PCA space and draws it and the
+underlying data in a biplot.
+}
+\usage{
+\method{plot}{prcurve}(x, data, axes = 1:2, seg = TRUE, col.seg = "forestgreen",
+     col.curve = "red", lwd.curve = 2, ...)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{x}{an object of class \code{"prcurve"}.}
+  \item{data}{The data the principal curve was fitted to.}
+  \item{axes}{numeric vector of length 2; this is passed to the
+    \code{choices} argument of the \code{\link[vegan]{scores}} function.}
+  \item{seg}{logical; should segments be drawn between the observed
+    points to the location on the principal curve on to which they
+    project.} 
+  \item{col.seg}{The colour to draw the segments in.}
+  \item{col.curve}{The colour to draw the principal curve in.}
+  \item{lwd.curve}{The line thickness used to draw the principal curve.}
+  \item{\dots}{additional arguments passed on to \code{points} when
+    drawing the observations in PCA space.}
+}
+%\details{
+%%  ~~ If necessary, more details than the description above ~~
+%}
+\value{
+A plot on the currently active device. The function does not return
+anything.
+}
+%\references{
+%% ~put references to the literature/web site here ~
+%}
+\author{
+Gavin L. Simpson
+}
+%\note{
+%%  ~~further notes~~
+%}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+\code{\link{prcurve}}; \code{\link{rda}} for the code used to perform
+the PCA.
+}
+\examples{
+## Load the Abernethy Forest data
+data(abernethy)
+
+## Remove the Depth and Age variables
+abernethy2 <- abernethy[, -(37:38)]
+
+## Fit the principal curve using varying complexity of smoothers
+## for each species
+aber.pc2 <- prcurve(abernethy2, method = "ca", trace = TRUE,
+                    vary = TRUE, penalty = 1.4)
+
+## Plot the curve
+plot(aber.pc2, abernethy2)
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{hplot}

Added: pkg/man/prcurve.Rd
===================================================================
--- pkg/man/prcurve.Rd	                        (rev 0)
+++ pkg/man/prcurve.Rd	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,160 @@
+\name{prcurve}
+\alias{prcurve}
+\alias{initCurve}
+\alias{smoothSpline}
+
+\title{
+Fits a principal curve to m-dimensional data
+}
+\description{
+  A principal curve is a non-parametric generalisation of the principal
+  component and is a curve that passes through the \emph{middle} of a
+  cloud of data points for a certain definition of `middle'.
+}
+\usage{
+prcurve(X, method = c("ca", "pca", "random"),
+        smoother = smoothSpline, complexity, vary = FALSE,
+        maxComp, finalCV = FALSE, axis = 1, rank = FALSE,
+        stretch = 2, maxit = 10, trace = FALSE, thresh = 0.001,
+        plotit = FALSE, \dots)
+
+initCurve(X, method = c("ca", "pca", "random"), rank = FALSE,
+          axis = 1)
+
+smoothSpline(lambda, x, choose = TRUE, complexity, ...,
+             penalty = 1, cv = FALSE, keep.data = FALSE,
+             control.spar = list(low = 0))
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{X}{a matrix-like object containing the variables to which the
+    principal curve is to be fitted.}
+  \item{method}{character; method to use when initialising the principal
+  curve. \code{"ca"} fits a correspondence analysis to \code{X} and uses
+  the \code{axis}-th axis scores as the initial curve. \code{"pca"} does
+  the same but fits a principal components analysis to
+  \code{X}. \code{"random"} produces a random ordering as the initial
+  curve.}
+  \item{smoother}{function; the choice of smoother used to fit the
+    principal curve. Currently, the only option is \code{smoothSpline}
+    which is a wrapper to \code{\link{smooth.spline}}.}
+  \item{complexity}{numeric; the complexity of the fitted smooth
+    functions.
+
+    The function passed as argument \code{smoother} should arrange for
+    this argument to be passed on to relevant aspect of the underlying
+    smoother. In the case of \code{smoothSpline}, complexity is the
+    \code{df} argument of \code{\link{smooth.spline}}.}
+  \item{vary}{logical; should the complexity of the smoother fitted to
+    each variable in \code{X} be allowed to vary (i.e. to allow a more or
+    less smooth function for a particular variable. If \code{FALSE} the
+    median complexity over all \emph{m} variables is chosen as the fixed
+    complexity for all \emph{m} smooths.}
+  \item{maxComp}{numeric; the upper limt on the allowed complexity.}
+  \item{finalCV}{logial; should a final fit of the smooth function be
+    performed using cross validation?}
+  \item{axis}{numeric; the ordinaion axis to use as the initial curve.}
+  \item{rank}{logical; should rank position on the gradient be used? Not
+    yet implemented.}
+  \item{stretch}{numeric; a factor by which the curve can be
+    extrapolated when points are projected.  Default is 2 (times the
+    last segment length).}
+  \item{maxit}{numeric; the maximum number of iterations.}
+  \item{trace}{logical; print progress on the iterations be printed to
+    the console?}
+  \item{thresh}{numeric; convergence threshold on shortest distances to
+    the curve. The algorithm is considered to have converged when the
+    latest iteration produces a total residual distance to the curve
+    that is within \code{thresh} of the value obtained during the
+    previous iteration.}
+  \item{plotit}{logical; should the fitting process be plotted? If
+    \code{TRUE}, then the fitted principal curve and observations in
+    \code{X} are plotted in principal component space.}
+  \item{\dots}{arguments passed on to lower functions. In the case of
+    \code{prcurve}, these additional arguments are passed solely on to
+    the function \code{smoother}.
+
+    In \code{smoothSpline}, \dots is passed on the the underlying
+    function \code{\link{smooth.spline}} and users should read that
+    function's help page for further details.
+  }
+  \item{lambda}{the current projection function; the position that each
+    sample projects to on the current principal curve. This is the
+    predictor variable or covariate in the smooth function.}
+  \item{x}{numeric vector; a column from \code{X} used as the response
+    variable in the smooth function. The principal curve algorithm fits
+    a separate scatterplot smoother (or similar smoother) to each
+    variable in \code{X} in turn as the response.}
+  \item{choose}{logical; should the underlying smoother function be
+    allowed to choose the degree of smooth complexity for each variable
+    in \code{X}?}
+  \item{penalty, cv, keep.data, control.spar}{arguments to
+    \code{\link{smooth.spline}}.}
+}
+%\details{
+%TODO
+%}
+\value{
+  An object of class \code{"prcurve"} with the following components:
+
+  \item{s}{a matrix corresponding to \code{X}, giving their projections
+    onto the curve.}
+  \item{tag}{an index, such that \code{s[tag, ]} is smooth.}
+  \item{lambda}{for each point, its arc-length from the beginning of the
+    curve.}
+  \item{dist}{the sum-of-squared distances from the points to their
+    projections.}
+  \item{converged}{logical; did the algorithm converge?}
+  \item{iter}{numeric; the number of iterations performed.}
+  \item{totalDist}{numeric; total sum-of-squared distances.}
+  \item{complexity}{numeric vector; the complexity of the smoother
+    fitted to each variable in \code{X}.}
+  \item{call}{the matched call.}
+}
+%\references{
+%% ~put references to the literature/web site here ~
+%}
+\author{
+  Gavin L. Simpson
+}
+\note{
+  The fitting function uses function \code{\link[princurve]{get.lam}} in
+    package \pkg{princurve} to find the projection of the data on to the
+    fitted curve. 
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+%\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+%}
+\examples{
+data(abernethy)
+
+## Plot the most common taxa
+Stratiplot(Age ~ . - Depth, data =
+           chooseTaxa(abernethy, max.abun = 15, n.occ = 10),
+           type = c("g","poly"), sort = "wa")
+
+## Remove the Depth and Age variables
+abernethy2 <- abernethy[, -(37:38)]
+
+## Fit PCA and CA
+aber.pca <- rda(abernethy2)
+aber.ca <- cca(abernethy2)
+
+## Fit the principal curve using the median complexity over
+## all species
+aber.pc <- prcurve(abernethy2, method = "ca", trace = TRUE,
+                   vary = FALSE, penalty = 1.4)
+
+## Fit the principal curve using varying complexity of smoothers
+## for each species
+aber.pc2 <- prcurve(abernethy2, method = "ca", trace = TRUE,
+                    vary = TRUE, penalty = 1.4)
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{multivariate}
+\keyword{nonparametric}
+\keyword{smooth}

Added: pkg/man/timetrack.Rd
===================================================================
--- pkg/man/timetrack.Rd	                        (rev 0)
+++ pkg/man/timetrack.Rd	2010-07-04 17:46:22 UTC (rev 189)
@@ -0,0 +1,152 @@
+\name{timetrack}
+\alias{timetrack}
+\alias{print.timetrack}
+\alias{plot.timetrack}
+\alias{fitted.timetrack}
+
+\title{Timetracks of change in species composition}
+
+\description{
+  Project passive (e.g. sediment core) samples into an ordination of a
+  set of training samples.
+}
+
+\usage{
+timetrack(X, passive, env, method = c("cca", "rda"),
+          transform = "none", formula, scaling = 3,
+          rank = "full", model = c("CCA", "CA"), \dots)
+
+\method{fitted}{timetrack}(object, type = c("passive", "ordination"),
+       model = NULL, \dots)
+
+\method{plot}{timetrack}(x, choices = 1:2, pch = c(1,2),
+     col = c("black","red"), \dots)
+}
+
+\arguments{
+  \item{X}{matrix-like object containing the training set or reference
+    samples.}
+  \item{passive}{matrix-like object containing the samples to be
+    projected into the ordination of \code{X}. Usually a set of sediment
+    core samples.}
+  \item{env}{optional vector or matrix of environmental or constraining
+    variables. If provided, a constrained ordination of \code{X} is
+    performed.}
+  \item{method}{character, resolving to an ordination function available
+    in \pkg{vegan}. Currently only \code{"cca"}, the default, and
+    \code{"rda"} are supported.}
+  \item{transform}{character; the name of the transformation to apply to
+    both \code{X} and \code{passive}. The transformations are performed
+    using \code{tran} and valid options are given by that function's
+    \code{method} argument.}
+  \item{formula}{a model formula; if provided, it defines the model
+    formula for the ordination function and is supplied as argument
+  \code{formula} to the ordination function.}
+  \item{scaling}{numeric; the ordination scaling to apply. Useful
+    options are likely to be \code{1} or \code{3} where the focus is on
+    the samples.}
+  \item{rank}{character; see argument of same name in function
+    \code{\link[vegan]{cca}} or \code{\link[vegan]{rda}}.}
+  \item{model}{character; see argument of same name in function
+    \code{\link[vegan]{cca}} or \code{\link[vegan]{rda}}.}
+  \item{object, x}{an object of class \code{"timetrack"}.}
+  \item{type}{character; which fitted values should be returned?}
+  \item{choices}{numeric; the length-2 vector of ordination axes to
+    plot.}
+  \item{pch}{The length-2 vector of plotting characters. The first
+    element is used for the ordination samples, the second for the
+    passive samples.}
+  \item{col}{The length-2 vector of plotting colours. The first
+    element is used for the ordination samples, the second for the
+    passive samples.}
+  \item{\dots}{arguments passed to other methods.
+    \code{timetrack} passes arguments on to \code{tran} and the
+    ordination function given in \code{method}. \code{fitted} passes
+    arguments on to other \code{fitted} methods as
+    appropriate. \code{plot} passes arguments on to the underlying
+    plotting functions.}
+}
+
+\details{
+  The timetrack is a way to visualise changes in species composition
+  from sediment core samples within an underlying reference ordination
+  or, usually, training set samples. This technique has been most often
+  applied in situations where the underlying ordination is a constrained
+  ordination and thence the timetrack of sediment core samples within
+  the ordination reflects both the change in species composition and the
+  indicative changes in the constraining variables.
+
+  The sediment core samples are projected passively into the underlying
+  ordination. By projected passively, the locations of the core samples
+  are predicted on the basis of the ordination species scores. A common
+  set of species (columns) is required to passively place the sediment
+  samples into the ordination. To achieve this, the left outer join of
+  the species compositions of the training set and passive set
+  is determined; the left outer join results in the passive data matrix
+  having the same set of species (variables; columns) as the training
+  set. Any training set species not in the passive set are added to
+  the passive set with abundance 0. Any passive species not in the
+  training set are removed from the passive set.
+}
+
+\value{
+  The \code{plot} method results in a plot on the currently active
+  device, whilst the \code{fitted} method returns the matrix of fitted
+  locations on the set of ordination axes.
+
+  \code{timetrack} returns an object of class \code{"timetrack"}, a list
+  with the following components:
+  \item{ordination }{the ordination object, the result of the call to
+    the function of the name \code{method}.}
+  \item{fitted.values }{the matrix of fitted locations for the passive
+    samples on the ordination axes.}
+  \item{method }{the ordination function used.}
+  \item{formula }{if supplied, the model formula used to define the
+    ordination model.}
+  \item{scaling }{the ordination scaling applied.}
+  \item{rank }{The rank or the number of axes used in the
+    approximation. The default is to use all axes (full rank) of the
+    \code{"model"}.} 
+  \item{model }{Show constrained (\code{"CCA"}) or unconstrained
+    (\code{"CA"}) results.}
+  \item{labels }{a list of names for the \code{X}, \code{passive}, and
+    \code{env} arguments.}
+  \item{call }{The matched function call.}
+}
+
+%\references{
+%% ~put references to the literature/web site here ~
+%}
+
+\author{
+Gavin L. Simpson
+}
+
+%\note{
+%%  ~~further notes~~
+%}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+  \code{\link[vegan]{cca}} and \code{\link[vegan]{rda}} for the
+  underlying ordination functions.
+}
+
+\examples{
+## load the RLGH and SWAP data sets
+data(rlgh, swapdiat)
+
+## Fit the timetrack ordination
+mod <- timetrack(swapdiat, rlgh, transform = "hellinger",
+                 method = "rda")
+mod
+
+## Plot the timetrack
+plot(mod)
+}
+
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{methods}
+\keyword{hplot}



More information about the Analogue-commits mailing list