[Analogue-commits] r116 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Apr 26 11:12:55 CEST 2009
Author: gsimpson
Date: 2009-04-26 11:12:54 +0200 (Sun, 26 Apr 2009)
New Revision: 116
Added:
pkg/R/densityplot.residLen.R
pkg/R/hist.residLen.R
pkg/R/histogram.residLen.R
pkg/R/plot.residLen.R
pkg/man/densityplot.residLen.Rd
pkg/man/hist.residLen.Rd
pkg/man/histogram.residLen.Rd
pkg/man/plot.residLen.Rd
Modified:
pkg/R/print.residLen.R
pkg/R/residLen.R
pkg/man/residLen.Rd
Log:
residLen, no longer generic,
internal functions in residLen exposed externally and documented;
new plot methods for residLen objects.
Added: pkg/R/densityplot.residLen.R
===================================================================
--- pkg/R/densityplot.residLen.R (rev 0)
+++ pkg/R/densityplot.residLen.R 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,24 @@
+`densityplot.residLen` <- function(x, ..., xlab = NULL,
+ ylab = NULL) {
+ ## produce the data object
+ n.train <- length(x$train)
+ n.pass <- length(x$passive)
+ dat <- data.frame(lengths = c(x$train, x$passive),
+ type = rep(c("Training Set", "Passive"),
+ times = c(n.train, n.pass)))
+ ## labels
+ if(is.null(xlab)) {
+ if(attr(x, "method") == "cca") {
+ xlab <- expression(paste(Squared ~ chi^2 ~
+ residual ~ distance))
+ } else {
+ xlab <- "Squared Euclidean residual distance"
+ }
+ }
+ if(is.null(ylab)) {
+ ylab <- "Density"
+ }
+ ## plotting
+ densityplot(~ lengths | type, data = dat, layout = c(1,2),
+ n = 100, xlab = xlab, from = 0, ...)
+}
Added: pkg/R/hist.residLen.R
===================================================================
--- pkg/R/hist.residLen.R (rev 0)
+++ pkg/R/hist.residLen.R 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,68 @@
+`hist.residLen` <- function(x, breaks = "Sturges",
+ freq = TRUE,
+ probs = c(0.9, 0.95, 0.99),
+ ncol = 1, lcol = "red",
+ llty = "dashed",
+ xlab = NULL, ylab = NULL,
+ main = "Residual distances",
+ rug = TRUE,
+ ...) {
+ ## quantiles of resid distance
+ q.train <- with(x, quantile(train, probs = probs))
+ ## labels
+ if(is.null(xlab)) {
+ if(attr(x, "method") == "cca") {
+ xlab <- expression(paste(Squared ~ chi^2 ~
+ residual ~ distance))
+ } else {
+ xlab <- "Squared Euclidean residual distance"
+ }
+ }
+ if(is.null(ylab)) {
+ if(freq) {
+ ylab <- "Frequency"
+ } else {
+ ylab <- "Density"
+ }
+ }
+ ## plotting
+ op <- par(oma = c(4,0,5,0), las = 1, no.readonly = TRUE,
+ mar = c(1.5,4,1,2) + 0.1)
+ on.exit(par(op))
+ layout(matrix(1:2, ncol = ncol))
+ h.train <- hist(x$train, breaks = breaks, plot = FALSE, ...)
+ h.passive <- hist(x$passive, breaks = h.train$breaks,
+ plot = FALSE, ...)
+ y <- if (freq)
+ c(h.train$counts, h.passive$counts)
+ else {
+ y <- c(h.train$density, h.passive$density)
+ if (is.null(y))
+ c(h.train$intensities, h.passive$intensities)
+ else y
+ }
+ y.lim <- range(0, y)
+ plot(h.train, main = "", xlim = range(h.train$breaks),
+ ylab = ylab, freq = freq, ylim = y.lim)
+ abline(v = q.train, col = lcol, lty = llty)
+ with(x, rug(train, side = 1))
+ axis(1)
+ axis(2)
+ axis(3, at = q.train,
+ labels = paste(round(probs*100), "%"),
+ las = 2)
+ box()
+ title(ylab = ylab)
+ plot(h.passive, main = "", xlim = range(h.train$breaks),
+ ylab = ylab, freq = freq, ylim = y.lim)
+ abline(v = q.train, col = lcol, lty = llty)
+ with(x, rug(passive, side = 1))
+ axis(1)
+ axis(2)
+ box()
+ title(ylab = ylab)
+ title(xlab = xlab, outer = TRUE, line = 2)
+ title(main = main, outer = TRUE, line = 3)
+ layout(1)
+ invisible(list(train = h.train, passive = h.passive))
+}
Added: pkg/R/histogram.residLen.R
===================================================================
--- pkg/R/histogram.residLen.R (rev 0)
+++ pkg/R/histogram.residLen.R 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,28 @@
+`histogram.residLen` <- function(x, ..., xlab = NULL, ylab = NULL,
+ type = c("percent","count","density")) {
+ ## produce the data object
+ n.train <- length(x$train)
+ n.pass <- length(x$passive)
+ dat <- data.frame(lengths = c(x$train, x$passive),
+ type = rep(c("Training Set", "Passive"),
+ times = c(n.train, n.pass)))
+ ## labels
+ if(is.null(xlab)) {
+ if(attr(x, "method") == "cca") {
+ xlab <- expression(paste(Squared ~ chi^2 ~
+ residual ~ distance))
+ } else {
+ xlab <- "Squared Euclidean residual distance"
+ }
+ }
+ if(missing(type))
+ type <- "count"
+ type <- match.arg(type)
+ ylab <- switch(type,
+ count = "Frequency",
+ percent = "%",
+ density = "Density")
+ ## plotting
+ histogram(~ lengths | type, data = dat, layout = c(1,2),
+ xlab = xlab, ylab = ylab, ...)
+}
Added: pkg/R/plot.residLen.R
===================================================================
--- pkg/R/plot.residLen.R (rev 0)
+++ pkg/R/plot.residLen.R 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,60 @@
+## plot method for "residLen"
+`plot.residLen` <- function(x, probs = c(0.9, 0.95, 0.99),
+ ncol = 1, lcol = "red",
+ llty = "dashed",
+ xlab = NULL, ylab = NULL,
+ main = "Residual distances",
+ rug = TRUE,
+ ...) {
+ ## compute densities
+ d.train <- with(x, density(train, from = 0))
+ d.passive <- with(x, density(passive, from = 0))
+ y.lim <- range(0, d.train$y, d.passive$y)
+ x.lim <- range(0, x$train)
+ ## quantiles of resid distance
+ q.train <- with(x, quantile(train, probs = probs))
+ ## labels
+ if(is.null(xlab)) {
+ if(attr(x, "method") == "cca") {
+ xlab <- expression(paste(Squared ~ chi^2 ~
+ residual ~ distance))
+ } else {
+ xlab <- "Squared Euclidean residual distance"
+ }
+ }
+ if(is.null(ylab)) {
+ ylab <- "Density"
+ }
+ ## plotting
+ op <- par(oma = c(4,0,5,0), las = 1, no.readonly = TRUE,
+ mar = c(1.5,4,1,2) + 0.1)
+ on.exit(par(op))
+ layout(matrix(1:2, ncol = ncol))
+ plot(d.train, type = "n", ann = FALSE, axes = FALSE,
+ xlim = x.lim, ylim = y.lim)
+ abline(h = 0, col = "lightgrey")
+ abline(v = q.train, col = lcol, lty = llty)
+ with(x, rug(train, side = 1))
+ lines(d.train)
+ axis(1)
+ axis(2)
+ axis(3, at = q.train,
+ labels = paste(round(probs*100), "%"),
+ las = 2)
+ box()
+ title(ylab = ylab)
+ plot(d.passive, type = "n", ann = FALSE, axes = FALSE,
+ xlim = x.lim, ylim = y.lim)
+ abline(h = 0, col = "lightgrey")
+ abline(v = q.train, col = lcol, lty = llty)
+ with(x, rug(passive, side = 1))
+ lines(d.passive)
+ axis(1)
+ axis(2)
+ box()
+ title(ylab = ylab)
+ title(xlab = xlab, outer = TRUE, line = 2)
+ title(main = main, outer = TRUE, line = 3)
+ layout(1)
+ invisible(list(train = d.train, passive = d.passive))
+}
Modified: pkg/R/print.residLen.R
===================================================================
--- pkg/R/print.residLen.R 2009-04-25 11:39:07 UTC (rev 115)
+++ pkg/R/print.residLen.R 2009-04-26 09:12:54 UTC (rev 116)
@@ -1,15 +1,27 @@
## print method
`print.residLen` <- function(x,
- digits = min(3, getOption("digits") - 4),
+ digits = min(4, getOption("digits") - 4),
probs = c(0.5, 0.75, 0.9, 0.95, 0.99), ...) {
cat("\n")
writeLines(strwrap("Squared residual lengths",
prefix = "\t"))
- cat("\nCall:\n")
- cat(paste(deparse(x$call), "\n\n"))
- cat("Quantiles of training set lengths:\n")
- print(with(x, quantile(train, probs = probs)), digits = digits)
- cat("\nQuantiles of passive sample lengths:\n")
- print(with(x, quantile(passive, probs = probs)), digits = digits)
cat("\n")
+ writeLines(strwrap(pasteCall(x$call)))
+ cat("\n")
+ writeLines(strwrap(paste("Ordination Method:",
+ attr(x, "method"))))
+ cat("\nQuantiles of residual lengths:\n\n")
+ quant <- with(x,
+ data.frame(rbind(quantile(train,
+ probs = probs),
+ quantile(passive,
+ probs = probs)
+ )
+ )
+ )
+ names(quant) <- as.character(paste(probs * 100, "%",
+ sep = ""))
+ rownames(quant) <- c("Training Set:", "Passive:")
+ print(quant, digits = digits)
+ invisible(x)
}
Modified: pkg/R/residLen.R
===================================================================
--- pkg/R/residLen.R 2009-04-25 11:39:07 UTC (rev 115)
+++ pkg/R/residLen.R 2009-04-26 09:12:54 UTC (rev 116)
@@ -1,82 +1,95 @@
## compute the squared residual length statistic for a constrained
## ordination given a single constraint
-`residLen` <- function(train, ...) {
- UseMethod("residLen")
-}
-
-`residLen.default` <- function(train, env, passive,
- method = c("cca", "rda"), ...) {
- ## inline functions
- ## fitted values for passive samples
- fittedSuppl <- function(ord, newdata, csum) {
- #########################################################
- ## Fitted values for passive samples
- ## Arguments:
- ## ord = vegan ordination object (CCA/RDA)
- ## newdata = matrix of passive species data with same
- ## columns as that used to fit ord
- ## csum = colum sums for the training data
- #########################################################
- ## species scores
- b <- predict(ord, type = "sp")
- ## site scores
- xi <- predict(ord, newdata = newdata, type = "wa")
- fik <- sweep(1 + (xi %*% t(b)), 2, csum / sum(csum),
- "*")
- ## fitted values
- fik <- sweep(fik, 1, rowSums(newdata), "*")
- }
- sqrl.uni <- function(X, colsum, fik) {
- #########################################################
- ## Squared residual length for unimodal methods
- ## Arguments:
- ## X = species data (training or passive) to which
- ## we want to find the residual length
- ## colsum = column sums for the training species data
- ## fik = fitted species data for either the training
- ## or passive samples
- #########################################################
- yip <- rowSums(X)
- ypk <- colsum
- ypp <- sum(ypk)
- A <- (sweep(X, 2, ypk, "/") - sweep(fik, 2, ypk, "/"))^2
- B <- sweep(A, 2, ypk, "*")
- C <- rowSums(B / ypp)
- res <- (1 / (yip / ypp))^2 * C
- return(res)
- }
- ## merge train and passive
- dat <- join(train, passive)
- train <- dat[[1]]
+`residLen` <- function(X, env, passive,
+ method = c("cca", "rda")) {
+ ## merge X and passive
+ dat <- join(X, passive)
+ X <- dat[[1]]
passive <- dat[[2]]
- ## check env is same length as nrow(train)
- if(!isTRUE(all.equal(length(env), nrow(train))))
- stop("'train' and 'env' imply different numbers of observations")
+ ## check env is same length as nrow(X)
+ if(!isTRUE(all.equal(length(env), nrow(X))))
+ stop("'X' and 'env' imply different numbers of observations")
## ordinate
if(missing(method))
method <- "cca"
method <- match.arg(method)
- ##if(method == "rda")
- ## .NotYetUsed("method = \"rda\" not currently implemented.")
FUN <- match.fun(method)
## ordinate
- ord <- FUN(X = train, Y = env)
+ ord <- FUN(X = X, Y = env)
## fitted values
fit <- fitted(ord, type = "response")
- ## colSums of train
- ypk <- colSums(train)
+ ## colSums of X
+ ypk <- colSums(X)
## predict locations for the passive
- pred <- fittedSuppl(ord, passive, ypk)
+ pred <- fittedY(ord, passive, ypk)
+ ## calc sqdists
+ if(method == "cca") {
+ train <- sqrlUnimodal(X, ypk, fit)
+ passive <- sqrlUnimodal(passive, ypk, pred)
+ } else {
+ train <- sqrlLinear(X, fit)
+ passive <- sqrlLinear(passive, pred)
+ }
## system.call
.call <- match.call()
.call[[1]] <- as.name("residLen")
- ## residual lengths for train
- res <- list(train = sqrl.uni(train, ypk, fit),
- passive = sqrl.uni(passive, ypk, pred),
- ordination = ord,
- call = .call)
+ ## residual lengths for X
+ res <- list(train = train, passive = passive,
+ ordination = ord, call = .call)
class(res) <- "residLen"
attr(res, "method") <- method
return(res)
}
+
+fittedY <- function(ord, newdata, colsum) {
+ ## Fitted values of response for samples
+ ## Arguments:
+ ## ord = vegan ordination object (CCA/RDA)
+ ## newdata = matrix of passive species data with same
+ ## columns as that used to fit ord
+ ## colsum = colum sums for the training
+ ## species scores
+ b <- predict(ord, type = "sp")
+ ## site scores
+ xi <- predict(ord, newdata = newdata, type = "wa")
+ ## predict fitted values
+ if(inherits(ord, "rda")) {
+ fik <- xi %*% t(b)
+ } else {
+ fik <- sweep(1 + (xi %*% t(b)), 2,
+ colsum / sum(colsum), "*")
+ fik <- sweep(fik, 1, rowSums(newdata), "*")
+ }
+ ## fitted values
+ return(fik)
+}
+
+sqrlUnimodal <- function(Y, colsum, fitted) {
+ ## Squared residual length for unimodal methods
+ ## Arguments:
+ ## Y = species data (training or passive) to which
+ ## we want to find the residual length
+ ## colsum = column sums for the training species data
+ ## fitted = fitted species data for either the training
+ ## or passive samples
+ yip <- rowSums(Y)
+ ypk <- colsum
+ ypp <- sum(ypk)
+ A <- (sweep(Y, 2, ypk, "/") - sweep(fitted, 2, ypk, "/"))^2
+ B <- sweep(A, 2, ypk, "*")
+ C <- rowSums(B / ypp)
+ res <- (1 / (yip / ypp))^2 * C
+ return(res)
+}
+
+sqrlLinear <- function(Y, fitted) {
+ ## Squared residual length for linear methods
+ ## Arguments:
+ ## Y = species data (training or passive) to which
+ ## we want to find the residual length
+ ## fitted = fitted species data for either the training
+ ## or passive samples
+ res <- rowSums((Y - fitted)^2) / ncol(Y)
+ return(res)
+}
Added: pkg/man/densityplot.residLen.Rd
===================================================================
--- pkg/man/densityplot.residLen.Rd (rev 0)
+++ pkg/man/densityplot.residLen.Rd 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,39 @@
+\name{densityplot.residLen}
+\alias{densityplot.residLen}
+\title{Lattice density plot for residual lengths}
+\description{
+ Lattice \code{\link[lattice]{densityplot}} method for
+ \code{\link{residLen}} objects.
+}
+\usage{
+\method{densityplot}{residLen}(x, ..., xlab = NULL, ylab = NULL)
+}
+\arguments{
+ \item{x}{Object of class \code{"residLen"}, the result of a call to
+ \code{\link{residLen}}.}
+ \item{xlab, ylab}{Axis labels. If not supplied, suitable defaults are
+ generated, depending on whether RDA or CCA was used as the
+ underlying ordination model.}
+ \item{\dots}{Additional arguments passed to
+ \code{\link[lattice]{densityplot}}.}
+}
+\value{
+ Returns an object of class \code{"trellis"}. See
+ \code{\link[lattice]{densityplot}} for details.
+}
+\author{Gavin L. Simpson}
+\seealso{\code{\link{residLen}}, \code{\link{plot.residLen}},
+ \code{\link{hist.residLen}}, \code{\link{histogram.residLen}}.}
+\examples{
+data(swapdiat, swappH, rlgh)
+
+## squared residual lengths for RLGH
+rlens <- residLen(swapdiat, swappH, rlgh)
+rlens
+
+## plot the density functions of the residual distances
+densityplot(rlens)
+
+}
+\keyword{hplot}
+\keyword{methods}
Added: pkg/man/hist.residLen.Rd
===================================================================
--- pkg/man/hist.residLen.Rd (rev 0)
+++ pkg/man/hist.residLen.Rd 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,58 @@
+\name{hist.residLen}
+\alias{hist.residLen}
+\title{Histogram plot for residual lengths}
+\description{
+ Base graphics histogram plot method for \code{\link{residLen}}
+ objects.
+}
+\usage{
+\method{hist}{residLen}(x, breaks = "Sturges", freq = TRUE,
+ probs = c(0.9, 0.95, 0.99), ncol = 1, lcol = "red",
+ llty = "dashed", xlab = NULL, ylab = NULL,
+ main = "Residual distances", rug = TRUE, ...)
+}
+\arguments{
+ \item{x}{Object of class \code{"residLen"}, the result of a call to
+ \code{\link{residLen}}.}
+ \item{breaks}{How breakpoints for the histogram are determined. See
+ \code{hist} for more details.}
+ \item{freq}{logical; if \code{TRUE}, the histogram graphic is a
+ representation of frequencies, the \code{counts} component of the
+ result; if \code{FALSE}, probability densities, component
+ \code{density}, are plotted (so that the histogram has a total area
+ of one). Defaults to \code{TRUE}}
+ \item{probs}{numeric; vector of probability quantiles to compute from
+ the sets of residual distances.}
+ \item{ncol}{numeric; number of columns for the plot layout. Choices
+ are \code{1} or \code{2}. Determines whether the histograms are
+ plotted above or beside each other.}
+ \item{lcol, llty}{colour and line-type for the quantiles.}
+ \item{xlab, ylab}{Axis labels. If not supplied, suitable defaults are
+ generated, depending on whether RDA or CCA was used as the
+ underlying ordination model.}
+ \item{main}{character; title for the plot.}
+ \item{rug}{logical; should rug plots of the actual distances be drawn?}
+ \item{\dots}{additional arguments passed to \code{hist}.}
+}
+\value{
+ A plot on the current device.
+
+ Returns a list with two components (\code{train} and \code{passive}),
+ each of which is an object returned by \code{hist}.
+}
+\author{Gavin L. Simpson}
+\seealso{\code{\link{residLen}}, \code{\link{plot.residLen}},
+ \code{\link{histogram.residLen}}, \code{\link{densityplot.residLen}}.}
+\examples{
+data(swapdiat, swappH, rlgh)
+
+## squared residual lengths for RLGH
+rlens <- residLen(swapdiat, swappH, rlgh)
+rlens
+
+## plot a histogram of the residual distances
+hist(rlens)
+
+}
+\keyword{hplot}
+\keyword{methods}
Added: pkg/man/histogram.residLen.Rd
===================================================================
--- pkg/man/histogram.residLen.Rd (rev 0)
+++ pkg/man/histogram.residLen.Rd 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,47 @@
+\name{histogram.residLen}
+\alias{histogram.residLen}
+\title{Lattice histogram plot for residual lengths}
+\description{
+ Lattice \code{\link[lattice]{histogram}} method for
+ \code{\link{residLen}} objects.
+}
+\usage{
+\method{histogram}{residLen}(x, ..., xlab = NULL, ylab = NULL,
+ type = c("percent", "count", "density"))
+}
+\arguments{
+ \item{x}{Object of class \code{"residLen"}, the result of a call to
+ \code{\link{residLen}}.}
+ \item{xlab, ylab}{Axis labels. If not supplied, suitable defaults are
+ generated, depending on whether RDA or CCA was used as the
+ underlying ordination model.}
+ \item{type}{Character string indicating type of histogram to be
+ drawn. \code{"percent"} and \code{"count"} give relative frequency
+ and frequency histograms, and can be misleading when breakpoints are
+ not equally spaced. \code{"density"} produces a density scale
+ histogram.
+
+ See \code{\link[lattice]{histogram}} for further details.}
+ \item{\dots}{Additional arguments passed to
+ \code{\link[lattice]{histogram}}.}
+}
+\value{
+ Returns an object of class \code{"trellis"}. See
+ \code{\link[lattice]{histogram}} for details.
+}
+\author{Gavin L. Simpson}
+\seealso{\code{\link{residLen}}, \code{\link{plot.residLen}},
+ \code{\link{hist.residLen}}, \code{\link{densityplot.residLen}}.}
+\examples{
+data(swapdiat, swappH, rlgh)
+
+## squared residual lengths for RLGH
+rlens <- residLen(swapdiat, swappH, rlgh)
+rlens
+
+## plot a histogram of the residual distances
+histogram(rlens)
+
+}
+\keyword{hplot}
+\keyword{methods}
Added: pkg/man/plot.residLen.Rd
===================================================================
--- pkg/man/plot.residLen.Rd (rev 0)
+++ pkg/man/plot.residLen.Rd 2009-04-26 09:12:54 UTC (rev 116)
@@ -0,0 +1,51 @@
+\name{plot.residLen}
+\alias{plot.residLen}
+\title{Plot method for residual lengths}
+\description{
+ Base graphics plot method for \code{\link{residLen}} objects.
+}
+\usage{
+\method{plot}{residLen}(x, probs = c(0.9, 0.95, 0.99), ncol = 1,
+ lcol = "red", llty = "dashed", xlab = NULL, ylab = NULL,
+ main = "Residual distances", rug = TRUE, ...)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{x}{Object of class \code{"residLen"}, the result of a call to
+ \code{\link{residLen}}.}
+ \item{probs}{numeric; vector of probability quantiles to compute from
+ the sets of residual distances.}
+ \item{ncol}{numeric; number of columns for the plot layout. Choices
+ are \code{1} or \code{2}. Determines whether the histograms are
+ plotted above or beside each other.}
+ \item{lcol, llty}{colour and line-type for the quantiles.}
+ \item{xlab, ylab}{Axis labels. If not supplied, suitable defaults are
+ generated, depending on whether RDA or CCA was used as the
+ underlying ordination model.}
+ \item{main}{character; title for the plot.}
+ \item{rug}{logical; should rug plots of the actual distances be drawn?}
+ \item{\dots}{additional arguments passed to \code{plot}.}
+}
+\value{
+ A plot on the current device.
+
+ Returns, invisibly, a list with two components (\code{train} and
+ \code{passive}), each and object of the type returned by
+ \code{density}.
+}
+\author{Gavin L. Simpson}
+\seealso{\code{\link{residLen}}, \code{\link{plot.residLen}},
+ \code{\link{histogram.residLen}}, \code{\link{densityplot.residLen}}.}
+\examples{
+data(swapdiat, swappH, rlgh)
+
+## squared residual lengths for RLGH
+rlens <- residLen(swapdiat, swappH, rlgh)
+rlens
+
+## plot a histogram of the residual distances
+plot(rlens)
+
+}
+\keyword{hplot}
+\keyword{methods}
Modified: pkg/man/residLen.Rd
===================================================================
--- pkg/man/residLen.Rd 2009-04-25 11:39:07 UTC (rev 115)
+++ pkg/man/residLen.Rd 2009-04-26 09:12:54 UTC (rev 116)
@@ -1,7 +1,9 @@
\name{residLen}
\alias{residLen}
-\alias{residLen.default}
\alias{print.residLen}
+\alias{fittedY}
+\alias{sqrlLinear}
+\alias{sqrlUnimodal}
\title{Squared residual length diagnostics}
\description{
The squared residual length between the fitted values of a constrained
@@ -9,19 +11,31 @@
transfer function models.
}
\usage{
-residLen(train, ...)
+residLen(X, env, passive, method = c("cca","rda"))
-\method{residLen}{default}(train, env, passive,
- method = c("cca","rda"), \dots)
+fittedY(ord, newdata, colsum)
+
+sqrlLinear(Y, fitted)
+
+sqrlUnimodal(Y, colsum, fitted)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
- \item{train}{data frame; the training set species data.}
+ \item{X}{data frame; the training set species data.}
\item{env}{vector; the training set environmental data.}
\item{passive}{data frame; the passive samples species data.}
- \item{method}{the ordination technique to use. Only \code{"cca"} is
- currently supported.}
- \item{\dots}{additional arguments passed to methods.}
+ \item{method}{the ordination technique to use. One of \code{"rda"} or
+ \code{"cca"}, with the latter the default.}
+ \item{ord}{an ordination object, the result of a call to
+ \code{\link[vegan]{cca}} or \code{\link[vegan]{rda}}.}
+ \item{newdata}{Species data matrix for passive samples. Must have same
+ columns as data used to fit \code{ord}.}
+ \item{colsum}{column (species) sums for training set data used to fit
+ \code{ord}.}
+ \item{Y}{Original species data matrix, the response for which squared
+ residual lengths are to be computed.}
+ \item{fitted}{The fitted values of the response derived from the
+ constrained ordination model.}
}
\details{
The squared residual lengths are computed for the training set samples
@@ -29,8 +43,23 @@
fitted in the transfer function model will have large squared residual
distances between the observed species data and the fitted values from
the constrained ordination.
+
+ \code{residLen} is the main user-interface function and can be called
+ with either the training data and passive samples.
+
+ \code{fittedY} returns the fitted approximation of the passive sample
+ response data (i.e. species data). \code{sqrlLinear} and
+ \code{sqrlUnimodal} return the squared residual distances between the
+ observed species data and the fitted values from the constrained
+ ordination model.
}
\value{
+ \code{fittedY} returns a matrix of fitted species abundances for
+ passive samples.
+
+ \code{sqrlLinear} and \code{sqrlUnimodal} return a vector of
+ residual distances.
+
\code{residLen} returns an object of class \code{"residLen"} with the
attribute \code{"method"} set to \code{"method"}. This object is a
list with the following components:
@@ -56,6 +85,9 @@
## squared residual lengths for RLGH
rlens <- residLen(swapdiat, swappH, rlgh)
rlens
+
+## as before but using linear RDA
+residLen(swapdiat, swappH, rlgh, method = "rda")
}
\keyword{methods}
\keyword{multivariate}
More information about the Analogue-commits
mailing list