[Adephylo-commits] r84 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 5 15:11:14 CET 2008


Author: jombart
Date: 2008-12-05 15:11:14 +0100 (Fri, 05 Dec 2008)
New Revision: 84

Added:
   pkg/R/abouheif.R
   pkg/R/zzz.R
   pkg/man/abouheif.Rd
Removed:
   pkg/R/gearymoran.R
   pkg/man/gearymoran.Rd
Modified:
   pkg/DESCRIPTION
   pkg/TODO
Log:
finished abouheif.moran.


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2008-12-04 21:58:34 UTC (rev 83)
+++ pkg/DESCRIPTION	2008-12-05 14:11:14 UTC (rev 84)
@@ -9,4 +9,4 @@
 Description: Multivariate tools to analyze comparative data, i.e. a phylogeny and some traits measured for each taxa.
 License: GPL (>=2)
 LazyLoad: yes
-Collate: utils.R partition.R s.phylo4d.R distances.R proximities.R orthobasis.R ppca.R orthogram.R gearymoran.R
\ No newline at end of file
+Collate: utils.R partition.R s.phylo4d.R distances.R proximities.R orthobasis.R ppca.R orthogram.R abouheif.R zzz.R
\ No newline at end of file

Added: pkg/R/abouheif.R
===================================================================
--- pkg/R/abouheif.R	                        (rev 0)
+++ pkg/R/abouheif.R	2008-12-05 14:11:14 UTC (rev 84)
@@ -0,0 +1,49 @@
+abouheif.moran <- function (x, W=NULL, method=c("oriAbouheif","patristic","nNodes","Abouheif","sumDD"),
+                            a=1, nrepet=999,alter=c("greater", "less", "two-sided")) {
+
+    ## some checks
+    if(!require(ade4)) stop("The ade4 package is not installed.")
+    alter <- match.arg(alter)
+    method <- match.arg(method)
+
+    ## handles W
+    if(!is.null(W)){ # W is provided
+        if (any(W<0)) stop ("term <0 found in 'W'")
+        if (nrow(W) != ncol(W)) stop ("'W' is not squared")
+        W <- as.matrix(W)
+    } else { # otherwise computed from x, a phylo4d object
+        if(!inherits(x, "phylo4d")) stop("if W is not provided, x has to be a phylo4d object")
+        if (is.character(chk <- check_phylo4(x))) stop("bad phylo4d object: ",chk)
+        if (is.character(chk <- check_data(x))) stop("bad phylo4d object: ",chk)
+        W <- proxTips(x, method=method, a=a, normalize="row", symmetric=TRUE)
+    }
+
+    nobs <- ncol(W)
+    ## W has to be symmetric
+    W <- (W + t(W))/2
+
+    ## take data from x if it is a phylo4d
+    if(inherits(x, "phylo4d")){
+        if (is.character(chk <- check_phylo4(x))) stop("bad phylo4d object: ",chk)
+        if (is.character(chk <- check_data(x))) stop("bad phylo4d object: ",chk)
+        x <- tdata(x)
+    }
+
+    ## main computations
+    test.names <- names(x)
+    x <- data.matrix(x)
+    if (nrow(x) != nobs) stop ("non convenient dimension")
+    nvar <- ncol(x)
+    res <- .C("gearymoran",
+        param = as.integer(c(nobs,nvar,nrepet)),
+        data = as.double(x),
+        W = as.double(W),
+        obs = double(nvar),
+        result = double (nrepet*nvar),
+        obstot = double(1),
+        restot = double (nrepet),
+        PACKAGE="adephylo"
+    )
+    res <- as.krandtest(obs=res$obs,sim=matrix(res$result,ncol=nvar, byr=TRUE),names=test.names,alter=alter)
+    return(res)
+} # end abouheif.moran

Deleted: pkg/R/gearymoran.R
===================================================================
--- pkg/R/gearymoran.R	2008-12-04 21:58:34 UTC (rev 83)
+++ pkg/R/gearymoran.R	2008-12-05 14:11:14 UTC (rev 84)
@@ -1,33 +0,0 @@
-gearymoran <- function (x, W, nrepet=999,alter=c("greater", "less", "two-sided")) {
-
-    ## some checks
-    if(!require(ade4)) stop("The ade4 package is not installed.")
-    alter <- match.arg(alter)
-
-    ## checks for W
-    if (any(W<0)) stop ("term <0 found in 'W'")
-    if (nrow(W) != nobs) stop ("'W' is not squared")
-    W <- as.matrix(W)
-    nobs <- ncol(W)
-
-    ## W has to be symmetric
-    W <- (W + t(W))/2
-
-    ## main computations
-    test.names <- names(x)
-    x <- data.matrix(x)
-    if (nrow(x) != nobs) stop ("non convenient dimension")
-    nvar <- ncol(x)
-    res <- .C("gearymoran",
-        param = as.integer(c(nobs,nvar,nrepet)),
-        data = as.double(x),
-        W = as.double(W),
-        obs = double(nvar),
-        result = double (nrepet*nvar),
-        obstot = double(1),
-        restot = double (nrepet),
-        PACKAGE="adephylo"
-    )
-    res <- as.krandtest(obs=res$obs,sim=matrix(res$result,ncol=nvar, byr=TRUE),names=test.names,alter=alter)
-    return(res)
-} # end gearymoran

Added: pkg/R/zzz.R
===================================================================
--- pkg/R/zzz.R	                        (rev 0)
+++ pkg/R/zzz.R	2008-12-05 14:11:14 UTC (rev 84)
@@ -0,0 +1,3 @@
+.First.lib <- function (lib, pkg){
+  library.dynam("adephylo", pkg, lib)
+}

Modified: pkg/TODO
===================================================================
--- pkg/TODO	2008-12-04 21:58:34 UTC (rev 83)
+++ pkg/TODO	2008-12-05 14:11:14 UTC (rev 84)
@@ -56,8 +56,7 @@
 - tithonia.Rd -- done
 - ungulates.Rd -- done
 * build an orthobasis from treePart dummy variables
-* add a Moran's index and a test (is it needed, as we have morangeary ?)
-* move gearymoran inside adephylo
+o move gearymoran inside adephylo -- done, is now abouheif.moran. (TJ)
 
 
 

Added: pkg/man/abouheif.Rd
===================================================================
--- pkg/man/abouheif.Rd	                        (rev 0)
+++ pkg/man/abouheif.Rd	2008-12-05 14:11:14 UTC (rev 84)
@@ -0,0 +1,89 @@
+\encoding{latin1}
+\name{abouheif.moran}
+\alias{abouheif.moran}
+\title{Abouheif's test based on Moran's I}
+\description{
+  The test of Abouheif (1999) is designed to detect phylogenetic
+  autocorrelation in a quantitative trait. Pavoine \emph{et al.} (2008)
+  have shown that this tests is in fact a Moran's I test using a
+  particular phylogenetic proximity between tips (see details). The
+  function \code{abouheif.moran} performs basically Abouheif's test for
+  several traits at a time, but it can incorporate other phylogenetic
+  proximities as well.\cr
+
+  Note that the original Abouheif's proximity (Abouheif, 1999; Pavoine
+  \emph{et al.} 2008) unifies Moran's I and Geary'c tests (Thioulose \emph{et
+    al.} 1995).\cr
+
+  \code{abouheif.moran} can be used in two ways:\cr
+  - providing a data.frame of traits (\code{x}) and a matrix of
+  phylogenetic proximities (\code{W})\cr
+  - providing a \linkS4class{phylo4d} object (\code{x}) and specifying the type of proximity to be
+  used (\code{method}).
+  
+}
+\usage{
+abouheif.moran(x, W=NULL,
+  method=c("oriAbouheif","patristic","nNodes","Abouheif","sumDD"),
+           a=1, nrepet = 999, alter=c("greater", "less", "two-sided"))
+}
+\arguments{
+  \item{x}{a data frame with continuous variables, or a
+    \linkS4class{phylo4d} object (i.e. containing both a tree, and tip
+    data. In the latter case, \code{method} argument is used to determine
+    which proximity should be used.}
+  \item{W}{a \emph{n} by \emph{n} matrix (\emph{n} being the number rows
+    in x) of phylogenetic proximities, as produced by
+    \code{\link{proxTips}}.}
+  \item{method}{a character string (full or unambiguously abbreviated)
+    specifying the type of proximity to be used. By default, the
+    proximity used is that of the original Abouheif's test. See details
+    in \code{\link{proxTips}} for information about other methods.}
+  \item{a}{the exponent used to compute the proximity (see \code{\link{proxTips}}).}
+  \item{nrepet}{number of random permutations of data for the randomization test}
+  \item{alter}{a character string specifying the alternative hypothesis,
+    must be one of "greater" (default), "less" or "two-sided"}
+}
+\details{
+\code{W} is a squared symmetric matrix whose terms are all positive or null.\cr
+
+\code{W} is firstly transformed in frequency matrix A by dividing it by the total sum of data matrix :  
+\deqn{a_{ij} = \frac{W_{ij}}{\sum_{i=1}^{n}\sum_{j=1}^{n}W_{ij}}}{a_ij = W_ij / (sum_i sum_j W_ij)} 
+The neighbouring weights is defined by the matrix \eqn{D = diag(d_1,d_2, \ldots)} where \eqn{d_i = \sum_{j=1}^{n}W_{ij}}{d_i = sum_j W_ij}.
+For each vector x of the data frame x, the test is based on the Moran statistic \eqn{x^{t}Ax}{t(x)Ax} where x is D-centred.
+}
+\value{
+Returns an object of class \code{krandtest} (randomization tests from
+ade4), containing one Monte Carlo test for each trait.
+}
+\references{
+
+Thioulouse, J., Chessel, D. and Champely, S. (1995) Multivariate analysis of spatial patterns: a unified approach to local and global structures.
+\emph{Environmental and Ecological Statistics}, \bold{2}, 1--14.
+}
+\author{Original code from ade4 (gearymoran function) by Sébastien Ollier\cr
+  Adapted and maintained by Thibaut Jombart <jombart at biomserv.univ-lyon1.fr>.
+}
+\seealso{
+  - \code{\link[pkg:ade4]{gearymoran}} from the ade4 package\cr
+  - \code{\link[pkg:ape]{Moran.I}} from the ape package for the
+  classical Moran's I test. \cr
+}
+\examples{
+if(require(ade4)){
+## load data
+data(ungulates)
+tre <- read.tree(text=ungulates$tre)
+x <- phylo4d(tre, ungulates$tab)
+
+## Abouheif's tests for each trait
+myTests <- abouheif.moran(x)
+myTests
+plot(myTests)
+
+## a variant using another proximity
+plot(abouheif.moran(x, method="nNodes") )
+}
+}
+\keyword{spatial}
+\keyword{ts}

Deleted: pkg/man/gearymoran.Rd
===================================================================
--- pkg/man/gearymoran.Rd	2008-12-04 21:58:34 UTC (rev 83)
+++ pkg/man/gearymoran.Rd	2008-12-05 14:11:14 UTC (rev 84)
@@ -1,79 +0,0 @@
-\encoding{latin1}
-\docType{methods}
-\name{gearymoran}
-\alias{gearymoran}
-\alias{gearymoran-methods}
-\alias{gearymoran,ANY-method}
-\alias{gearymoran,phylo4d-method}
-\alias{gearymoran.phylo4d}
-\title{Moran's I / Geary'c randomization test for autocorrelation}
-\description{
-  \code{gearymoran} is a generic S4 function which computes
-  autocorrelation in a data object using a set of weights. Weights can
-  reflect phylogenetic, spatial, or temporal proximities between
-  observations, which allows \code{gearymoran} to measure
-  autocorrelation in all these cases.\cr
-
-  The name of the test reflects the fact that this test unifies both
-  Geary's \emph{c} and Moran's \emph{I}. This is achieved by using
-  non-uniform weights for observations: rather than weighting these by
-  1/n or 1/(n-1) (n being the number of observations), observations are
-  weighted according to their global proximity to all other
-  observations (like in Thioulouse et al. 1995). 'Central' observations
-  are thus given more weights than (phylogenetic, spatial, or temporal)
-  outliers.\cr
-}
-\usage{
-gearymoran(x, W, nrepet = 999, alter=c("greater", "less", "two-sided"))
-}
-\arguments{
-  \item{x}{a data frame with continuous variables}
-  \item{W}{a \emph{n} by \emph{n} link matrix where \emph{n} is the row number of x}
-  \item{nrepet}{number of random vectors for the randomization test}
-  \item{alter}{a character string specifying the alternative hypothesis,
-  must be one of "greater" (default), "less" or "two-sided"}
-}
-\details{
-\code{W} is a squared symmetric matrix which terms are all positive or null. 
-
-\code{W} is firstly transformed in frequency matrix A by dividing it by the total sum of data matrix :  
-\deqn{a_{ij} = \frac{W_{ij}}{\sum_{i=1}^{n}\sum_{j=1}^{n}W_{ij}}}{a_ij = W_ij / (sum_i sum_j W_ij)} 
-The neighbouring weights is defined by the matrix \eqn{D = diag(d_1,d_2, \ldots)} where \eqn{d_i = \sum_{j=1}^{n}W_{ij}}{d_i = sum_j W_ij}.
-For each vector x of the data frame x, the test is based on the Moran statistic \eqn{x^{t}Ax}{t(x)Ax} where x is D-centred. 
-}
-\value{
-Returns an object of class \code{krandtest} (randomization tests).
-}
-\references{
-Cliff, A. D. and Ord, J. K. (1973) \emph{Spatial autocorrelation}, Pion, London.
-
-Thioulouse, J., Chessel, D. and Champely, S. (1995) Multivariate analysis of spatial patterns: a unified approach to local and global structures. 
-\emph{Environmental and Ecological Statistics}, \bold{2}, 1--14.
-}
-\author{Sébastien Ollier \email{ollier at biomserv.univ-lyon1.fr} \cr
-Daniel Chessel 
-}
-\seealso{\code{\link[spdep]{moran.test}} and \code{\link[spdep]{geary.test}} for classical versions of Moran's test and Geary's one}
-\examples{
-# a spatial example
-data(mafragh)
-tab0 <- (as.data.frame(scalewt(mafragh$mil)))
-W0 <- neig2mat(mafragh$neig)
-gm0 <- gearymoran(W0, tab0, 999)
-gm0
-plot(gm0, nclass = 20)
-
-\dontrun{
-# a phylogenetic example
-data(mjrochet)
-mjr.phy <- newick2phylog(mjrochet$tre)
-mjr.tab <- log(mjrochet$tab)
-gearymoran(mjr.phy$Amat, mjr.tab)
-gearymoran(mjr.phy$Wmat, mjr.tab)
-par(mfrow = c(1,2))
-table.value(mjr.phy$Wmat, csi = 0.25, clabel.r = 0)
-table.value(mjr.phy$Amat, csi = 0.35, clabel.r = 0)
-par(mfrow = c(1,1))
-}}
-\keyword{spatial}
-\keyword{ts}



More information about the Adephylo-commits mailing list