[Adephylo-commits] r81 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 3 14:50:48 CET 2008


Author: jombart
Date: 2008-12-03 14:50:47 +0100 (Wed, 03 Dec 2008)
New Revision: 81

Added:
   pkg/R/gearymoran.R
   pkg/man/gearymoran.Rd
Log:
Added gearymoran, started modifications.


Added: pkg/R/gearymoran.R
===================================================================
--- pkg/R/gearymoran.R	                        (rev 0)
+++ pkg/R/gearymoran.R	2008-12-03 13:50:47 UTC (rev 81)
@@ -0,0 +1,28 @@
+"gearymoran" <- function (bilis, X, nrepet=999,alter=c("greater", "less", "two-sided")) {
+    alter <- match.arg(alter)
+    ## bilis doit être une matrice
+    bilis <- as.matrix(bilis)
+    nobs <- ncol(bilis)
+    # bilis doit être carrée
+    if (nrow(bilis) != nobs) stop ("'bilis' is not squared")
+    # bilis doit être symétrique
+    bilis <- (bilis + t(bilis))/2
+    # bilis doit être à termes positifs (voisinages)
+    if (any(bilis<0)) stop ("term <0 found in 'bilis'")
+    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),
+        bilis = as.double(bilis),
+        obs = double(nvar),
+        result = double (nrepet*nvar),
+        obstot = double(1),
+        restot = double (nrepet),
+        PACKAGE="ade4"
+    )
+    res <- as.krandtest(obs=res$obs,sim=matrix(res$result,ncol=nvar, byr=TRUE),names=test.names,alter=alter)
+    return(res)
+}

Added: pkg/man/gearymoran.Rd
===================================================================
--- pkg/man/gearymoran.Rd	                        (rev 0)
+++ pkg/man/gearymoran.Rd	2008-12-03 13:50:47 UTC (rev 81)
@@ -0,0 +1,61 @@
+\encoding{latin1}
+\name{gearymoran}
+\alias{gearymoran}
+\title{Moran's I and Geary'c randomization tests for spatial and phylogenetic autocorrelation}
+\description{
+This function performs Moran's I test using phylogenetic and spatial link matrix (binary or general). It uses neighbouring weights so Moran's I and Geary's c randomization tests are equivalent.
+}
+\usage{
+gearymoran(x, bilis, nrepet = 999, alter=c("greater", "less", "two-sided"))
+}
+\arguments{
+  \item{x}{a data frame with continuous variables}
+  \item{bilis}{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{bilis} is a squared symmetric matrix which terms are all positive or null. 
+
+\code{bilis} is firstly transformed in frequency matrix A by dividing it by the total sum of data matrix :  
+\deqn{a_{ij} = \frac{bilis_{ij}}{\sum_{i=1}^{n}\sum_{j=1}^{n}bilis_{ij}}}{a_ij = bilis_ij / (sum_i sum_j bilis_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}bilis_{ij}}{d_i = sum_j bilis_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)))
+bilis0 <- neig2mat(mafragh$neig)
+gm0 <- gearymoran(bilis0, 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