[Vegan-commits] r253 - in pkg: R inst inst/doc man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 6 13:28:29 CET 2008


Author: jarioksa
Date: 2008-03-06 13:28:29 +0100 (Thu, 06 Mar 2008)
New Revision: 253

Modified:
   pkg/R/nestedtemp.R
   pkg/inst/ChangeLog
   pkg/inst/doc/decision-vegan.Rnw
   pkg/inst/doc/vegan.bib
   pkg/man/oecosimu.Rd
Log:
Discuss nestedtemp in the Design decisions vignette

Modified: pkg/R/nestedtemp.R
===================================================================
--- pkg/R/nestedtemp.R	2008-03-05 06:37:28 UTC (rev 252)
+++ pkg/R/nestedtemp.R	2008-03-06 12:28:29 UTC (rev 253)
@@ -67,8 +67,10 @@
     u <- u^2
     colnames(u) <- colnames(comm)
     rownames(u) <- rownames(comm)
+    names(r) <- rownames(comm)
+    names(c) <- colnames(comm)
     temp <- 100*sum(u)/prod(dim(comm))/0.04145
-    out <- list(comm = comm, u = u, r = r, c = c, 
+    out <- list(comm = comm, u = u, r = r, c = c, p = p,
                 fill=fill,  statistic = temp, smooth=smo)
     class(out) <- "nestedtemp"
     out

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2008-03-05 06:37:28 UTC (rev 252)
+++ pkg/inst/ChangeLog	2008-03-06 12:28:29 UTC (rev 253)
@@ -27,6 +27,9 @@
 	with these test results: Bajaball 6.33, Bajabl 14.43, Bajabn
 	5.98, Bajabo 11.18, Bajabs 10.13. Smaller change is that packing
 	is based on indices s and t directly instead of their ranks.
+
+	* vignettes: added discussion on nestedtemp() in "Design
+	decisions and implementation".
 	
 Version 1.12-1 (closed Mar 2, 2008)
 

Modified: pkg/inst/doc/decision-vegan.Rnw
===================================================================
--- pkg/inst/doc/decision-vegan.Rnw	2008-03-05 06:37:28 UTC (rev 252)
+++ pkg/inst/doc/decision-vegan.Rnw	2008-03-06 12:28:29 UTC (rev 253)
@@ -24,6 +24,10 @@
 \begin{document}
 \SweaveOpts{strip.white=TRUE}
 \setkeys{Gin}{width=0.55\linewidth}
+<<echo=false,results=hide>>=
+par(mar=c(3,3,1,1)+.1)
+require(vegan)
+@
 
 \maketitle
 
@@ -37,6 +41,109 @@
 
 \tableofcontents
 
+\section{Nestedness and Null models}
+
+Some indicators of nestedness and null models of communities are only
+described in general terms, and they could be implemented in various
+ways. Here I discuss the implementation in \texttt{vegan}.
+
+\subsection{Matrix temperature}
+
+The matrix temperature is intuitively simple
+(Fig. \ref{fig:nestedtemp}), but the the exact calculations were not
+explaind in the original publication \cite{AtmarPat93}.
+\begin{SCfigure}
+<<fig=true,echo=false,results=hide>>=
+data(sipoo)
+mod <- nestedtemp(sipoo)
+plot(mod, "i")
+x <- mod$c["Falcsubb"]
+y <- 1 - mod$r["1"]
+points(x,y, pch=16, cex=1.5)
+abline(x+y, -1, lty=2)
+f <- function(x, p) (1-(1-x)^p)^(1/p)
+cross <- function(x, a, p) f(x,p) - a + x
+r <- uniroot(cross, c(0,1), a = x+y, p = mod$p)$root
+arrows(x,y, r, f(r, mod$p), lwd=4)
+@
+\label{fig:nestedtemp}
+\caption{Matrix temperature for \emph{Falco subbuteo} on island 1
+  (dot; Sibbo Svartholmen). The curve is the fill line, and in a cold
+  matrix, all presences (red squares) should be in the upper left
+  corner behind the fill line. Dashed diagonal line of length $D$ goes
+  through the point, and an arrow of length $d$ connects the point to
+  the fill line. The ``surprise'' for this point is $u = (d/D)^2$ and
+  the matrix temperature is based on the sum of surprises: presences
+  outside the fill line or absences within the fill line.}
+\end{SCfigure}
+The function can be implemented in many ways following the general
+principles.  Rodr{\'i}guez-Girond{\'e}z and Santamaria \cite{RodGir06}
+have seen the original code and reveal more details of calculations,
+and their explanation is the basis of the implementation in
+\texttt{vegan}.  However, there are still some open issues, and
+probably \texttt{vegan} function \texttt{nestedtemp} will never
+exactly reproduce results from other programs, although it is based on
+the same general principles. I try to give main computation details in
+this documents --- all details can be seen in the source code of
+\texttt{nestedtemp}.
+
+\begin{enumerate}
+\item Species and sites are put into unit square \citep{RodGir06}. The
+  coordinates for $n$ item will be $(k-0.5)/n$ for $k=1 \ldots n$, so
+  that there are no points in the corners or the margins of the unit
+  square, and a diagonal line can be drawn through any point. I do not
+  know how the rows and columns are converted to the unit square in
+  other software, and this may be a considerable source of differences
+  among implementations.
+  \item Species and sites are ordered alternately using indices
+    \citep{RodGir06}:
+    \begin{equation}
+    \begin{split}
+      s_j &= \sum_{i|x_{ij} = 1} i^2 \\
+      t_j &= \sum_{i|x_{ij} = 0} (n-i+1)^2 
+    \end{split}
+    \end{equation}
+    Here $x$ is the data matrix, where $1$ is presence, and $0$ is
+    absence, $i$ and $j$ are row and column indices, and $n$ is the
+    number of rows. The equations give the indices for columns, but
+    the indices can be reversed for corresponding row indexing.
+    Ordering by $s$ packs presences to the topleft corner, and
+    ordering by $t$ pack zeros away from the topleft corner. The final
+    sorting should be ``a compromise'' \cite{RodGir06} between these
+    scores, and \texttt{vegan} uses $s+t$.  The result should be cool,
+    but the packing does not try to minimize the temperature
+    \citep{RodGir06}.  I do not know how the ``compromise'' is
+    defined, and this can cause some differences to other
+    implementations.
+  \item The following function is used to define the fill line:
+    \begin{equation}
+      y = (1-(1-x)^p)^{1/p}
+    \end{equation}
+    This is similar to the equation suggested by
+    \citet[eq. 4]{RodGir06}, but omits all terms dependent on the
+    numbers of species or sites, because I could not understand why
+    they were needed. The differences are visible only in small data
+    sets. The $y$ and $x$ are the coordinates in the unit square, and
+    the parameter $p$ is selected so that the curve covers the same
+    area as is the proportion of presences
+    (Fig. \ref{fig:nestedtemp}). The parameter $p$ is found
+    numerically using \textsf{R} functions \texttt{integrate} and
+    \texttt{uniroot}.  The fill line used in the original matrix
+    temperature software \cite{AtmarPat93} is supposed to be similar
+    \citep{RodGir06}. Small details in the fill line combined with
+    differences in scores used in the unit square (especially in the
+    corners) can cause large differences in the results.
+  \item A line with slope $-1$ is drawn through the point and the $x$
+    coordinate of the intersection of this line and the fill line is
+    found using function \texttt{uniroot}. The difference of this
+    intersection and the row coordinate gives the argument $d$ of matrix
+    temperature (Fig. \ref{fig:nestedtemp}).
+  \item In other software, ``duplicate'' species occurring on every
+    site are removed, as well as empty sites and species after
+    reordering \cite{RodGir06}. This is not done in \texttt{vegan}.
+\end{enumerate}
+
+
 \section{Scaling in redundancy analysis}
 
 This chapter discusses the scaling of scores (results) in redundancy

Modified: pkg/inst/doc/vegan.bib
===================================================================
--- pkg/inst/doc/vegan.bib	2008-03-05 06:37:28 UTC (rev 252)
+++ pkg/inst/doc/vegan.bib	2008-03-06 12:28:29 UTC (rev 253)
@@ -1,3 +1,24 @@
+
+
+ at Article{AtmarPat93,
+  author =	 {W. Atmar and B. D. Patterson},
+  title =	 {The measure of order and disorder in the
+                  distribution of species in fragmented habitat},
+  journal =	 {Oecologia},
+  year =	 1993,
+  volume =	 96,
+  pages =	 {373-382}
+}
+
+ at Article{RodGir06,
+  author =	 {M. A. Rodr{\'i}guez-Giron{\'e}s and L. Santamaria},
+  title =	 {A new algorithm to calculate the nestedness
+                  temperature of presence--absence matrices},
+  journal =	 {Journal of Biogeography},
+  year =	 2006,
+  volume =	 33,
+  pages =	 {921-935}}
+
 @article{Palmer93,
   author =	 {M. W. Palmer},
   title =	 {Putting things in even better order: The advantages

Modified: pkg/man/oecosimu.Rd
===================================================================
--- pkg/man/oecosimu.Rd	2008-03-05 06:37:28 UTC (rev 252)
+++ pkg/man/oecosimu.Rd	2008-03-06 12:28:29 UTC (rev 253)
@@ -78,7 +78,7 @@
   within proportion given by matrix fill are in the upper left corner of
   the matrix, and the surprise of the absence or presences is the
   diagonal distance from the fill line (Atmar & Patterson
-  1993). Function tries to pack species and sites to a minimal
+  1993). Function tries to pack species and sites to a low
   temperature (\enc{Rodríguez-Gironés}{Rodriguez-Girones} & Santamaria
   2006), but this is an iterative procedure, and the temperatures
   usually vary among runs.  Function \code{nestedtemp} also has a
@@ -88,7 +88,10 @@
   \enc{Rodríguez-Gironés}{Rodriguez-Girones} & Santamaria (2006) are
   more explicit and their description is used here. However, the results
   probably differ from other implementations, and users should be
-  cautious in interpreting the results.
+  cautious in interpreting the results. The details of calculations
+  are explained in the \code{\link{vignette}} \emph{Design decisions
+  and implementation} that you can read using functions
+  \code{\link{vignette}} or \code{\link{vegandocs}}. 
 
   In addition to these functions provided in \pkg{vegan}, any function
   can be used that takes \code{comm} as the first argument, and



More information about the Vegan-commits mailing list