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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 2 15:25:13 CET 2010


Author: jarioksa
Date: 2010-11-02 15:25:12 +0100 (Tue, 02 Nov 2010)
New Revision: 1343

Modified:
   pkg/vegan/R/plot.prc.R
   pkg/vegan/R/summary.prc.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/prc.Rd
Log:
Cajo's futher fixes to prc

Modified: pkg/vegan/R/plot.prc.R
===================================================================
--- pkg/vegan/R/plot.prc.R	2010-11-01 16:11:58 UTC (rev 1342)
+++ pkg/vegan/R/plot.prc.R	2010-11-02 14:25:12 UTC (rev 1343)
@@ -1,7 +1,7 @@
-"plot.prc" <-
-    function (x, species = TRUE, select, scaling = 2, axis = 1, type = "l", 
-              xlab, ylab, ylim, lty = 1:5, col = 1:6, pch, legpos, cex = 0.8, 
-              ...) 
+`plot.prc` <-
+    function (x, species = TRUE, select, scaling = 3, axis = 1, type = "l",
+              xlab, ylab, ylim, lty = 1:5, col = 1:6, pch, legpos, cex = 0.8,
+              ...)
 {
     x <- summary(x, scaling = scaling, axis = axis)
     oldpar <- par(no.readonly = TRUE)
@@ -10,46 +10,46 @@
     xax <- rownames(b)
     if (missing(xlab)) 
         xlab <- x$names[1]
-    if (missing(ylab)) 
+    if (missing(ylab))
         ylab <- "Effect"
-    if (!missing(select)) 
+    if (!missing(select))
         x$sp <- x$sp[select]
-    if (missing(ylim)) 
-        ylim <- if (species) 
+    if (missing(ylim))
+        ylim <- if (species)
             range(b, x$sp, na.rm = TRUE)
         else range(b, na.rm = TRUE)
     if (species) {
         op <- par("mai")
-        mrg <- max(strwidth(names(x$sp), cex = cex, units = "in")) + 
+        mrg <- max(strwidth(names(x$sp), cex = cex, units = "in")) +
             strwidth("mmm", cex = cex, units = "in")
         par(mai = c(op[1:3], max(op[4], mrg)))
     }
-    if (missing(pch)) 
+    if (missing(pch))
         pch <- as.character(1:nrow(b))
-    matplot(xax, b, type = type, xlab = xlab, ylab = ylab, ylim = ylim, 
+    matplot(xax, b, type = type, xlab = xlab, ylab = ylab, ylim = ylim,
             cex = cex, lty = lty, col = col, pch = pch, ...)
     abline(h = 0, col = "gray")
     if (species) {
-        linestack(x$sp, at = par("usr")[2], add = TRUE, hoff = 1, 
+        linestack(x$sp, at = par("usr")[2], add = TRUE, hoff = 1,
                   cex = cex, ...)
         rug(x$sp, side = 4)
     }
     if (missing(legpos)) {
         holes <- abs(par("usr")[3:4] - range(b, na.rm = TRUE))
-        if (holes[1] > holes[2]) 
+        if (holes[1] > holes[2])
             legpos <- "bottomleft"
         else legpos <- "topleft"
     }
     if (!is.na(legpos)) {
-        levs <- rownames(coef(x))
+        levs <- object$terminfo$xlev[[2]]
         nl <- length(levs)
         pp <- type %in% c("b", "p")
         pl <- type %in% c("b", "l")
-        if (length(lty) == 1) 
-            lty <- rep(lty, nl)
-        legend(legpos, legend = levs, col = col, lty = if (pl) 
-               lty[1:nl], pch = if (pp) 
-               pch, cex = cex, title = x$names[2])
+        if (length(lty) == 1)
+            lty <- rep(lty, nl-1)
+        legend(legpos, legend = levs, col = c("gray", col),
+               lty = if (pl) lty[c(1,1:(nl-1))],
+               pch = if (pp) pch, cex = cex, title = x$names[2])
     }
     invisible()
 }

Modified: pkg/vegan/R/summary.prc.R
===================================================================
--- pkg/vegan/R/summary.prc.R	2010-11-01 16:11:58 UTC (rev 1342)
+++ pkg/vegan/R/summary.prc.R	2010-11-02 14:25:12 UTC (rev 1343)
@@ -1,8 +1,12 @@
 `summary.prc` <-
-    function (object, axis = 1, scaling = 2, digits = 4, ...)
+    function (object, axis = 1, scaling = 3, digits = 4, ...) 
 {
-    species <- drop(scores(object, scaling = scaling, display="sp", choices=axis))
-    b <- coef(object)[, axis]
+    species <- drop(scores(object, scaling = scaling, display="sp",
+                           choices=axis, ...))
+    sites <- drop(scores(object, scaling = scaling, display="lc",
+                         choices=axis, ... )) 
+    ## coef for scaled sites (coef(object) gives for orthonormal)
+    b <- qr.coef(object$CCA$QR, sites)
     prnk <- object$pCCA$rank
     lentreat <- length(object$terminfo$xlev[[2]])
     lenb <- length(b)
@@ -12,8 +16,8 @@
     b <- cbind(bx, matrix(by, nrow = lentreat - 1, byrow = TRUE))
     rownames(b) <- (object$terminfo$xlev[[2]])[-1]
     colnames(b) <- object$terminfo$xlev[[1]]
-    out <- list(sp = species, coefficients = b, names = names(object$terminfo$xlev),
-                corner = (object$terminfo$xlev[[2]])[1], call = object$call,
+    out <- list(sp = species, coefficients = b, names = names(object$terminfo$xlev), 
+                corner = (object$terminfo$xlev[[2]])[1], call = object$call, 
                 digits = digits)
     class(out) <- "summary.prc"
     out

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-11-01 16:11:58 UTC (rev 1342)
+++ pkg/vegan/inst/ChangeLog	2010-11-02 14:25:12 UTC (rev 1343)
@@ -14,7 +14,10 @@
 	and 'const'.
 
 	* prc: coefficients folded in a wrong way. Diagnosed, reported and
-	fixed by Cajo ter Braak.
+	fixed by Cajo ter Braak. CtB also fixed the scaling of species
+	scores and coefficients to be more consistent with Canoco and
+	common standards. Cajo ter Braak is now recognized as a co-author
+	of the function.
 
 	* nestednodf: breaks ties in column and row totals by row sums and
 	column sums in quantitative data ('weighted = TRUE'). Version

Modified: pkg/vegan/man/prc.Rd
===================================================================
--- pkg/vegan/man/prc.Rd	2010-11-01 16:11:58 UTC (rev 1342)
+++ pkg/vegan/man/prc.Rd	2010-11-02 14:25:12 UTC (rev 1343)
@@ -5,13 +5,17 @@
 \alias{plot.prc}
 
 \title{Principal Response Curves for Treatments with Repeated Observations }
-\description{
-  Principal Response Curves (PRC) are a special case of Redundancy Analysis
-  (\code{\link{rda}}) for multivariate responses in
+
+\description{ Principal Response Curves (PRC) are a special case of
+  Redundancy Analysis (\code{\link{rda}}) for multivariate responses in
   repeated observation design. They were originally suggested for
   ecological communities. They should be easier to interpret than
-  traditional constrained ordination. 
+  traditional constrained ordination. They can also be used to study how
+  the effects of a factor \code{A} depend on the levels of a factor
+  \code{B}, that is \code{A + A:B}, in a multivariate response
+  experiment.
 }
+
 \usage{
 prc(response, treatment, time, ...)
 \method{summary}{prc}(object, axis = 1, scaling = 2, digits = 4, ...)
@@ -47,38 +51,37 @@
   \item{cex}{Character expansion for symbols and species labels.}
   \item{\dots}{ Other parameters passed to functions. }
 }
-\details{
-  PRC is a special case of \code{\link{rda}} with a single factor for
-  \code{treatment} and a single factor for \code{time} points in repeated
-  observations. In \pkg{vegan}, the corresponding \code{\link{rda}}
-  model is defined as 
-  \code{rda(response ~ treatment * time + Condition(time))}. Since
-  the \code{time} appears twice in the model formula, its main effects
-  will be aliased, and only interaction terms are available, and will be
+
+\details{ PRC is a special case of \code{\link{rda}} with a single
+  factor for \code{treatment} and a single factor for \code{time} points
+  in repeated observations. In \pkg{vegan}, the corresponding
+  \code{\link{rda}} model is defined as \code{rda(response ~ treatment *
+  time + Condition(time))}. Since the \code{time} appears twice in the
+  model formula, its main effects will be aliased, and only the main
+  effect of treatment and interaction terms are available, and will be
   used in PRC. Instead of usual multivariate ordination diagrams, PRC
   uses canonical (regression) coefficients and species scores for a
   single axis. All that the current functions do is to provide a special
-  \code{summary}  and \code{plot} methods that display the
-  \code{\link{rda}} results in the PRC fashion. With default contrasts
-  (\code{\link{contr.treatment}}) the coefficients are 
-  contrasts against the first level, and the levels must be arranged so
-  that the first level is the control.
+  \code{summary} and \code{plot} methods that display the
+  \code{\link{rda}} results in the PRC fashion. The current version only
+  works with default contrasts (\code{\link{contr.treatment}}) in which
+  the coefficients are contrasts against the first level, and the levels
+  must be arranged so that the first level is the control (or a baseline).
 
   Function \code{summary} prints the species scores and the
   coefficients. Function \code{plot} plots coefficients against
-  \code{time}
-  using \code{\link{matplot}}, and has similar
-  defaults.  The graph (and PRC) is meaningful only if the first
-  \code{treatment} level is the control, as the results are contrasts
-  to the first level when unordered factors are used. The plot also
-  displays species scores on the right vertical axis using function
+  \code{time} using \code{\link{matplot}}, and has similar defaults.
+  The graph (and PRC) is meaningful only if the first \code{treatment}
+  level is the control, as the results are contrasts to the first level
+  when unordered factors are used. The plot also displays species scores
+  on the right vertical axis using function
   \code{\link{linestack}}. Typically the number of species is so high
   that not all can be displayed with the default settings, but users can
   reduce character size or padding (\code{air}) in
   \code{\link{linestack}}, or \code{select} only a subset of the
   species. A legend will be displayed unless suppressed with
   \code{legpos = NA}, and the functions tries to guess where to put the
-  legend if \code{legpos} is not supplied.  
+  legend if \code{legpos} is not supplied.
   
 }
 \value{
@@ -93,17 +96,15 @@
   biological community to stress. Environmental Toxicology and
   Chemistry, 18, 138--148.
 }
-\author{ Jari Oksanen }
+\author{ Jari Oksanen and Cajo ter Braak}
 
-\section{Warning }{
-  The first level of \code{treatment} must be the control, and the
-  treatment contrasts must be used (see \code{\link{contr.treatment}}),
-  so that results are expressed as contrasts to the control.
-  The function works with other contrast types also, but then the user
-  must take care that the resulting coefficients are meaningful.
-  The
-  \code{time} must be an unordered factor.  
-} 
+\section{Warning }{The first level of \code{treatment} must be the
+  control, and the treatment contrasts must be used (see
+  \code{\link{contr.treatment}}), so that results are expressed as
+  contrasts to the control.  The function works with other contrast
+  types also, but then the user must take care that the resulting
+  coefficients are meaningful the resulting coefficient may be
+  meaningless.  The \code{time} must be an unordered factor.  }
 
 \seealso{\code{\link{rda}}, \code{\link{anova.cca}}.}
 \examples{



More information about the Vegan-commits mailing list