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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 20 16:54:50 CEST 2009


Author: jarioksa
Date: 2009-09-20 16:54:50 +0200 (Sun, 20 Sep 2009)
New Revision: 1015

Added:
   pkg/vegan/R/calibrate.R
   pkg/vegan/R/calibrate.ordisurf.R
Modified:
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/ordisurf.Rd
   pkg/vegan/man/predict.cca.Rd
Log:
calibrate is now generic with a new method calibrate.ordisurf

Added: pkg/vegan/R/calibrate.R
===================================================================
--- pkg/vegan/R/calibrate.R	                        (rev 0)
+++ pkg/vegan/R/calibrate.R	2009-09-20 14:54:50 UTC (rev 1015)
@@ -0,0 +1,5 @@
+`calibrate` <- 
+    function(object, ...)
+{
+    UseMethod("calibrate")
+}

Added: pkg/vegan/R/calibrate.ordisurf.R
===================================================================
--- pkg/vegan/R/calibrate.ordisurf.R	                        (rev 0)
+++ pkg/vegan/R/calibrate.ordisurf.R	2009-09-20 14:54:50 UTC (rev 1015)
@@ -0,0 +1,19 @@
+`calibrate.ordisurf` <-
+    function(object, newdata, ...)
+{
+    if (missing(newdata))
+        fit <- fitted(object)
+    else {
+        ## Got only a vector of two coordinates
+        if (is.vector(newdata) && length(newdata) == 2) 
+            newdata = data.frame(x1 = newdata[1], x2 = newdata[2])
+        ## Got a matrix or a data frme
+        else{
+            if (NCOL(newdata) < 2) 
+                stop("needs a matrix or a data frame with two columns")
+            newdata <- data.frame(x1 = newdata[,1], x2 = newdata[,2])
+        }
+        fit <- predict(object, newdata = newdata, ...)
+    }
+    fit
+}

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-09-20 11:34:07 UTC (rev 1014)
+++ pkg/vegan/inst/ChangeLog	2009-09-20 14:54:50 UTC (rev 1015)
@@ -4,6 +4,9 @@
 
 Version 1.16-30 (opened September 18, 2009) 
 
+	* calibrate: is now a a generic function and has a new method for
+	the 'ordisurf' object in addition to the old 'cca' method.
+
 	* FIXED BUG in cca, rda & capscale interpretation of
 	formulae. This was introduced in rev 972 (Sep 1, 2009), and fixed
 	in rev 1011 (Sep 18, 2009). Basically, all evaluation of 'subset'

Modified: pkg/vegan/man/ordisurf.Rd
===================================================================
--- pkg/vegan/man/ordisurf.Rd	2009-09-20 11:34:07 UTC (rev 1014)
+++ pkg/vegan/man/ordisurf.Rd	2009-09-20 14:54:50 UTC (rev 1015)
@@ -1,5 +1,6 @@
 \name{ordisurf}
 \alias{ordisurf}
+\alias{calibrate.ordisurf}
 
 \title{ Fit and Plot Smooth Surfaces of Variables on Ordination. }
 \description{
@@ -11,6 +12,7 @@
      thinplate = TRUE, add = FALSE, display = "sites",
      w = weights(x), main, nlevels = 10, levels, labcex = 0.6,
      bubble = FALSE, cex = 1, ...)
+\method{calibrate}{ordisurf}(object, newdata, ...)
 }
 
 \arguments{
@@ -45,6 +47,8 @@
     the maximum. The minimum size will always be \code{cex = 0.4}.  The
     option only has an effect if \code{add = FALSE}.}
   \item{cex}{Character expansion of plotting symbols.}
+  \item{object}{An \code{ordisurf} result object.}
+  \item{newdata}{Coordinates in two-dimensional ordination for new points.}
   \item{\dots}{ Other graphical parameters. }
 }
 \details{
@@ -66,6 +70,12 @@
   behaviour is consistent with \code{\link{envfit}}. For complete
   accordance with constrained \code{\link{cca}}, you should set
   \code{display = "lc"} (and possibly \code{scaling = 2}).
+
+  Function \code{calibrate} returns the fitted values of the response
+  variable. The \code{newdata} must be coordinates of points for which
+  the fitted values are desired. The function is based on
+  \code{\link[mgcv]{predict.gam}} and will pass extra arguments to
+  that function.
 }
 
 \value{
@@ -102,7 +112,9 @@
 vare.mds <- isoMDS(vare.dist)
 with(varechem, ordisurf(vare.mds, Baresoil, bubble = 5))
 ## Cover of Cladina arbuscula
-with(varespec, ordisurf(vare.mds, Cla.arb, family=quasipoisson)) 
+fit <- with(varespec, ordisurf(vare.mds, Cla.arb, family=quasipoisson)) 
+## Get fitted values
+calibrate(fit)
 }
 \keyword{ multivariate }
 \keyword{ aplot }

Modified: pkg/vegan/man/predict.cca.Rd
===================================================================
--- pkg/vegan/man/predict.cca.Rd	2009-09-20 11:34:07 UTC (rev 1014)
+++ pkg/vegan/man/predict.cca.Rd	2009-09-20 14:54:50 UTC (rev 1015)
@@ -10,6 +10,7 @@
 \alias{coef.cca}
 \alias{coef.rda}
 \alias{calibrate.cca}
+\alias{calibrate}
 
 \title{Prediction Tools for [Constrained] Ordination (CCA,
   RDA, DCA, CA, PCA) }
@@ -25,7 +26,7 @@
 \method{residuals}{cca}(object, ...)
 \method{predict}{cca}(object, newdata, type = c("response", "wa", "sp", "lc"),
     rank = "full", model = c("CCA", "CA"), scaling = FALSE, ...)
-calibrate.cca(object, newdata, rank = "full", ...)
+\method{calibrate}{cca}(object, newdata, rank = "full", ...)
 \method{coef}{cca}(object, ...)
 \method{predict}{decorana}(object, newdata, type = c("response", "sites", "species"),
     rank = 4, ...)
@@ -166,7 +167,7 @@
 predict(mod, type="lc", new=data.frame(A1 = 3, Management="NM", Moisture="2"), scal=2)
 # Calibration and residual plot
 mod <- cca(dune ~ A1 + Moisture, dune.env)
-pred <- calibrate.cca(mod)
+pred <- calibrate(mod)
 pred
 with(dune.env, plot(A1, pred[,"A1"] - A1, ylab="Prediction Error"))
 abline(h=0)



More information about the Vegan-commits mailing list