[Vegan-commits] r2295 - in pkg/vegan: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 24 20:14:04 CEST 2012
Author: jarioksa
Date: 2012-09-24 20:14:04 +0200 (Mon, 24 Sep 2012)
New Revision: 2295
Modified:
pkg/vegan/NAMESPACE
pkg/vegan/R/AIC.radfit.R
pkg/vegan/R/lines.radline.R
pkg/vegan/R/plot.radfit.R
pkg/vegan/R/points.radline.R
pkg/vegan/R/radfit.R
pkg/vegan/R/radfit.data.frame.R
pkg/vegan/R/radlattice.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/radfit.Rd
Log:
more consistent UI for radlattice and radfit methods with several new functions to fill the gaps
Modified: pkg/vegan/NAMESPACE
===================================================================
--- pkg/vegan/NAMESPACE 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/NAMESPACE 2012-09-24 18:14:04 UTC (rev 2295)
@@ -74,6 +74,7 @@
S3method(adipart, formula)
# AIC: stats
S3method(AIC, radfit)
+S3method(AIC, radfit.frame)
# RsquareAdj: vegan
S3method(RsquareAdj, cca)
S3method(RsquareAdj, default)
@@ -145,6 +146,8 @@
# deviance: stats
S3method(deviance, cca)
S3method(deviance, rda)
+S3method(deviance, radfit)
+S3method(deviance, radfit.frame)
# drop1: stats
S3method(drop1, cca)
# eigenvals: vegan
@@ -194,7 +197,11 @@
S3method(lines, prestonfit)
S3method(lines, procrustes)
S3method(lines, radline)
+S3method(lines, radfit)
S3method(lines, spantree)
+## logLik: stats
+S3method(logLik, radfit)
+S3method(logLik, radfit.frame)
# model.frame, model.matrix: stats
S3method(model.frame, cca)
S3method(model.matrix, cca)
@@ -275,6 +282,7 @@
S3method(points, orditkplot)
S3method(points, procrustes)
S3method(points, radline)
+S3method(points, radfit)
# predict: stats
S3method(predict, cca)
S3method(predict, decorana)
@@ -354,6 +362,7 @@
# radfit: vegan
S3method(radfit, data.frame)
S3method(radfit, default)
+S3method(radfit, matrix)
# rda: vegan
S3method(rda, default)
S3method(rda, formula)
Modified: pkg/vegan/R/AIC.radfit.R
===================================================================
--- pkg/vegan/R/AIC.radfit.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/AIC.radfit.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -1,6 +1,41 @@
-"AIC.radfit" <-
- function (object, k = 2, ...)
+### these functions are defined _ex machina_ for radline objects which
+### inherit from glm. Here we define them for radfit objects where
+### object$models is a list of radline objects
+
+`AIC.radfit` <-
+ function (object, AIC = TRUE, k = 2, ...)
{
- mods <- object$models
- unlist(lapply(mods, AIC, k = k))
+ sapply(object$models, AIC, k = k, ...)
}
+
+`deviance.radfit` <-
+ function(object, ...)
+{
+ sapply(object$models, deviance, ...)
+}
+
+`logLik.radfit` <-
+ function(object, ...)
+{
+ sapply(object$models, logLik, ...)
+}
+
+### Define also for radfit.frames which are lists of radfit objects
+
+`AIC.radfit.frame` <-
+ function(object, AIC = TRUE, k = 2, ...)
+{
+ sapply(object, AIC, k = k, ...)
+}
+
+`deviance.radfit.frame` <-
+ function(object, ...)
+{
+ sapply(object, deviance, ...)
+}
+
+`logLik.radfit.frame` <-
+ function(object, ...)
+{
+ sapply(object, logLik, ...)
+}
Modified: pkg/vegan/R/lines.radline.R
===================================================================
--- pkg/vegan/R/lines.radline.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/lines.radline.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -1,4 +1,4 @@
-"lines.radline" <-
+`lines.radline` <-
function (x, ...)
{
lin <- fitted(x)
@@ -6,3 +6,9 @@
lines(rnk, lin, ...)
invisible()
}
+
+`lines.radfit` <-
+ function(x, ...)
+{
+ matlines(fitted(x), ...)
+}
Modified: pkg/vegan/R/plot.radfit.R
===================================================================
--- pkg/vegan/R/plot.radfit.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/plot.radfit.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -1,8 +1,13 @@
-"plot.radfit" <-
+`plot.radfit` <-
function (x, BIC = FALSE, legend = TRUE, ...)
{
if (length(x$y) == 0)
stop("No species, nothing to plot")
+ ## if 'type = "n"', do not add legend (other types are not
+ ## supported)
+ type <- match.call(expand.dots = FALSE)$...$type
+ if (is.null(type))
+ type <- ""
out <- plot(x$y, ...)
if (length(x$y) == 1)
return(invisible(out))
@@ -14,7 +19,7 @@
lwd <- rep(1, ncol(fv))
lwd[emph] <- 3
matlines(fv, lty = 1, lwd = lwd, ...)
- if (legend) {
+ if (legend && type != "n") {
nm <- names(x$models)
legend("topright", legend = nm, lty = 1, lwd = lwd, col = 1:6)
}
Modified: pkg/vegan/R/points.radline.R
===================================================================
--- pkg/vegan/R/points.radline.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/points.radline.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -1,4 +1,4 @@
-"points.radline" <-
+`points.radline` <-
function (x, ...)
{
poi <- x$y
@@ -8,3 +8,9 @@
class(out) <- "ordiplot"
invisible(out)
}
+
+`points.radfit` <-
+ function(x, ...)
+{
+ points.radline(x, ...)
+}
Modified: pkg/vegan/R/radfit.R
===================================================================
--- pkg/vegan/R/radfit.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/radfit.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -1,5 +1,5 @@
-"radfit" <-
- function (...)
+`radfit` <-
+ function (x, ...)
{
UseMethod("radfit")
}
Modified: pkg/vegan/R/radfit.data.frame.R
===================================================================
--- pkg/vegan/R/radfit.data.frame.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/radfit.data.frame.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -1,9 +1,9 @@
-"radfit.data.frame" <-
- function(df, ...)
+`radfit.data.frame` <-
+ function(x, ...)
{
- ## df *must* have rownames
- rownames(df) <- rownames(df, do.NULL = TRUE)
- out <- apply(df, 1, radfit, ...)
+ ## x *must* have rownames
+ rownames(x) <- rownames(x, do.NULL = TRUE)
+ out <- apply(x, 1, radfit, ...)
if (length(out) == 1)
out <- out[[1]]
else {
@@ -12,3 +12,9 @@
}
out
}
+
+`radfit.matrix` <-
+ function(x, ...)
+{
+ radfit(as.data.frame(x), ...)
+}
Modified: pkg/vegan/R/radlattice.R
===================================================================
--- pkg/vegan/R/radlattice.R 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/R/radlattice.R 2012-09-24 18:14:04 UTC (rev 2295)
@@ -10,7 +10,7 @@
Abundance <- rep(y, p)
Rank <- rep(1:n, p)
Model <- factor(rep(mods, each=n), levels = mods)
- aic <- AIC(x, BIC = BIC)
+ aic <- AIC(x, AIC = BIC)
col <- trellis.par.get("superpose.line")$col
if (length(col) > 1)
col <- col[2]
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/inst/ChangeLog 2012-09-24 18:14:04 UTC (rev 2295)
@@ -16,10 +16,14 @@
search order: stats function C() is found instead of variable 'C'
and this gives an error message "object is not a matrix".
- * radfit: added fitted() method for radfit.frame objects similar
- to predict. The predict() method gained new argument to change the
- expected 'total' size of communities. The fitted() returns now
- named vectors or matrices.
+ * radfit: The single radline methods (rad.null() etc.) and
+ radfit() for single sites and data frames are more consistent and
+ usually have the same methods. The common methods to all include
+ now AIC(), deviance(), logLik(), predict() and fitted(). The
+ radfit() objects gained points() and lines() methods. The data
+ frame method also works with matrices. The predict() method
+ gained new argument to change the expected 'total' size of
+ communities. The fitted() returns now named vectors or matrices.
Version 2.1-19 (closed September 16, 2012)
Modified: pkg/vegan/man/radfit.Rd
===================================================================
--- pkg/vegan/man/radfit.Rd 2012-09-20 20:04:07 UTC (rev 2294)
+++ pkg/vegan/man/radfit.Rd 2012-09-24 18:14:04 UTC (rev 2295)
@@ -31,10 +31,9 @@
Zipf and Zipf-Mandelbrot models of species abundance.
}
\usage{
-\method{radfit}{data.frame}(df, ...)
+\method{radfit}{default}(x, ...)
\method{plot}{radfit.frame}(x, order.by, BIC = FALSE, model, legend = TRUE,
as.table = TRUE, ...)
-\method{radfit}{default}(x, ...)
\method{plot}{radfit}(x, BIC = FALSE, legend = TRUE, ...)
radlattice(x, BIC = FALSE, ...)
rad.null(x, family=poisson, ...)
@@ -50,8 +49,7 @@
}
\arguments{
- \item{df}{Data frame where sites are rows and species are columns.}
- \item{x}{A vector giving species abundances in a site, or an object to
+ \item{x}{Data frame, matrix or a vector giving species abundances, or an object to
be plotted.}
\item{order.by}{A vector used for ordering sites in plots.}
\item{BIC}{Use Bayesian Information Criterion, BIC, instead of
More information about the Vegan-commits
mailing list