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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 17 17:50:15 CEST 2009


Author: gblanchet
Date: 2009-07-17 17:50:14 +0200 (Fri, 17 Jul 2009)
New Revision: 901

Modified:
   pkg/vegan/R/mantel.correlog.R
   pkg/vegan/R/plot.mantel.correlog.R
   pkg/vegan/R/print.mantel.correlog.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/mantel.correlog.Rd
Log:
mantel.correlog: small corrections in code and documentation. Implementation of automatic correction for multiple tests

Modified: pkg/vegan/R/mantel.correlog.R
===================================================================
--- pkg/vegan/R/mantel.correlog.R	2009-07-16 12:43:21 UTC (rev 900)
+++ pkg/vegan/R/mantel.correlog.R	2009-07-17 15:50:14 UTC (rev 901)
@@ -1,8 +1,11 @@
 'mantel.correlog' <- 
-	function(D.eco, D.geo=NULL, XY=NULL, n.class=0, break.pts=NULL, cutoff=TRUE, r.type="pearson", nperm=999)
+	function(D.eco, D.geo=NULL, XY=NULL, n.class=0, break.pts=NULL, cutoff=TRUE, r.type="pearson", nperm=999, mult="holm", progressive=TRUE)
 {
 require(vegan)
 
+r.type <- match.arg(r.type, c("pearson", "spearman", "kendall"))
+mult   <- match.arg(mult, c("sidak", p.adjust.methods))
+
 epsilon <- .Machine$double.eps
 D.eco = as.matrix(D.eco)
 
@@ -79,7 +82,7 @@
 		# check.sums[k,1] = length(which(row.sums == 0))
 		if((cutoff==FALSE) | !(cutoff==TRUE & k>half.cl & any(row.sums == 0))) {
 			temp = mantel(mat.D2, D.eco, method=r.type, permutations=nperm)
-			mantel.r = c(mantel.r, temp$statistic)
+			mantel.r = c(mantel.r, -temp$statistic)
 			temp.p = temp$signif
 			if(temp$statistic >= 0) {
 				temp.p = ((temp.p*nperm)+1)/(nperm+1)
@@ -95,12 +98,42 @@
 	}
 
 mantel.res = cbind(class.index, n.dist, mantel.r, mantel.p)
-mantel.res=mantel.res[-1,]
-rownames(mantel.res) = rownames(mantel.res,do.NULL = FALSE, prefix = "D.class.")
-colnames(mantel.res) = c("class.index", "n.dist", "Mantel.r", "Pr(Mantel)")
+mantel.res = mantel.res[-1,]
 
+## Note: vector 'mantel.p' starts with a NA value
+mantel.p = mantel.p[-1]
+n.tests = length(which(mantel.p != "NA"))
+
+if(mult=="none") {
+	colnames(mantel.res) = c("class.index", "n.dist", "Mantel.r", "Pr(Mantel)")
+	} else {	
+	## Correct P-values for multiple testing
+		if(progressive) {
+			p.corr = mantel.p[1]
+	        if(mult == "sidak") {
+	            for(j in 2:n.tests) { p.corr = c(p.corr, 1-(1-mantel.p[j])^j) }
+	        	} else {
+	        	for(j in 2:n.tests) {
+	        		temp = p.adjust(mantel.p[1:j], method=mult)
+	            	p.corr = c(p.corr, temp[j])
+	            	}
+	        	}
+			} else {
+			## Correct all p-values for 'n.tests' simultaneous tests
+	        if(mult == "sidak") {
+	            p.corr = 1-(1-mantel.p[1:n.tests])^n.tests
+	        	} else {
+	            p.corr = p.adjust(mantel.p[1:n.tests], method=mult)
+	        	}
+	    	}
+	temp = c(p.corr, rep(NA,(n.class-n.tests)))
+	mantel.res = cbind(mantel.res, temp)
+	colnames(mantel.res) = c("class.index", "n.dist", "Mantel.r", "Pr(Mantel)", "Pr(corrected)")
+	}
+rownames(mantel.res) = rownames(mantel.res,do.NULL = FALSE, prefix = "D.cl.")
+
 # Output the results
-res = list(mantel.res=mantel.res, n.class=n.class, break.pts=break.pts, call=match.call() )
+res = list(mantel.res=mantel.res, n.class=n.class, break.pts=break.pts, mult=mult, n.tests=n.tests, call=match.call() )
 class(res) = "mantel.correlog"
 res
-}
+}
\ No newline at end of file

Modified: pkg/vegan/R/plot.mantel.correlog.R
===================================================================
--- pkg/vegan/R/plot.mantel.correlog.R	2009-07-16 12:43:21 UTC (rev 900)
+++ pkg/vegan/R/plot.mantel.correlog.R	2009-07-17 15:50:14 UTC (rev 901)
@@ -1,10 +1,13 @@
 'plot.mantel.correlog' <- function(x, ...)
 {
-how.many.classes = which(x$mantel.res[,3] != "NA")
-lim = max(how.many.classes)
+lim = max(x$n.tests)
 plot(x$mantel.res[1:lim,1],x$mantel.res[1:lim,3], xlab="Distance class index", ylab="Mantel r", pch=22)
-not.signif = which((x$mantel.res[1:lim,4] <= 0.05))
-points(x$mantel.res[not.signif,1], x$mantel.res[not.signif,3], pch=22, bg="black")
+if(x$mult=="none") {
+	signif = which((x$mantel.res[1:lim,4] <= 0.05))
+	} else {
+	signif = which((x$mantel.res[1:lim,5] <= 0.05))
+	}
+points(x$mantel.res[signif,1], x$mantel.res[signif,3], pch=22, bg="black")
 abline(a=0, b=0, col="red") 
 invisible()
-}
+}
\ No newline at end of file

Modified: pkg/vegan/R/print.mantel.correlog.R
===================================================================
--- pkg/vegan/R/print.mantel.correlog.R	2009-07-16 12:43:21 UTC (rev 900)
+++ pkg/vegan/R/print.mantel.correlog.R	2009-07-17 15:50:14 UTC (rev 901)
@@ -6,4 +6,4 @@
     cat('\n')
 	printCoefmat(x$mantel.res, P.values=TRUE, signif.stars=TRUE, Pvalues = TRUE)
     invisible(x) 
-}
+}
\ No newline at end of file

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-07-16 12:43:21 UTC (rev 900)
+++ pkg/vegan/inst/ChangeLog	2009-07-17 15:50:14 UTC (rev 901)
@@ -11,7 +11,7 @@
 	new functions to construct multivariate mantel correlograms --- 
 	use in ecology: to describe the spatial structure of species
 	assemblages. See Legendre and Legendre, Numerical ecology; 1998,
-	section 13.13.1.5. Written by Pierre Legendre.
+	section 13.1.5. Written by Pierre Legendre.
 
 Version 1.16-21 (opened July 4, 2009)
 

Modified: pkg/vegan/man/mantel.correlog.Rd
===================================================================
--- pkg/vegan/man/mantel.correlog.Rd	2009-07-16 12:43:21 UTC (rev 900)
+++ pkg/vegan/man/mantel.correlog.Rd	2009-07-17 15:50:14 UTC (rev 901)
@@ -4,13 +4,13 @@
 \alias{plot.mantel.correlog}
 \title{ Mantel correlogram }
 \description{
-Function \code{mantel.correlog} computes a multivariate Mantel correlogram. 
+Function \code{mantel.correlog} computes a multivariate Mantel correlogram. Proposed by Sokal (1986) and Oden and Sokal (1986), the method is also described in Legendre and Legendre (1998, pp. 736-738).
 }
 \usage{
 mantel.correlog(D.eco, D.geo=NULL, XY=NULL, n.class=0, break.pts=NULL, 
-cutoff=TRUE, r.type="pearson", nperm=999)
+cutoff=TRUE, r.type="pearson", nperm=999, mult="holm", progressive=TRUE)
 
-\method{plot}{mantel.correlog}(x,...)
+\method{plot}{mantel.correlog}(x, ...)
 }
 
 \arguments{
@@ -22,30 +22,37 @@
   \item{cutoff}{ For the second half of the distance classes, \code{cutoff = TRUE} limits the correlogram to the distance classes that include all points. If \code{cutoff = FALSE}, the correlogram includes all distance classes. }
   \item{r.type}{ Type of correlation in calculation of the Mantel statistic. Default: \code{r.type="pearson"}.  Other choices are \code{r.type="spearman"} and \code{r.type="kendall"}, as in functions \code{\link{cor}} and \code{\link{mantel}}. }
   \item{nperm}{ Number of permutations for the tests of significance. Default: \code{nperm=999}. For large data files, permutation tests are rather slow. } 
+  \item{mult}{ Correct P-values for multiple testing. The correction methods are \code{"holm"} (default), \code{"hochberg"}, \code{"sidak"}, and other methods available in the \code{\link{p.adjust}} function: \code{"bonferroni"} (best known, but not recommended because it is overly conservative), \code{"hommel"}, \code{"BH"}, \code{"BY"}, \code{"fdr"}, and \code{"none"}. }  
+  \item{progressive}{ Default: \code{progressive=TRUE} for progressive correction of multiple-testing, as described in Legendre and Legendre (1998, p. 721). Test of the first distance class: no correction; second distance class: correct for 2 simultaneous tests; distance class k: correct for k simultaneous tests. \code{progressive=FALSE}: correct all tests for \code{n.class} simultaneous tests. }
   \item{x}{ Output of \code{mantel.correlog}. }
-  \item{...}{ Parameters passed to other functions. }
+  \item{...}{ Other parameters passed from other functions. }
 }
 
 \details{
-The Mantel tests are done by \code{vegan}'s function \code{\link{mantel}}. Function \code{\link[ape]{mantel.test}} of the \code{ape} package could also have been used. 
+The Mantel tests are computed by \code{vegan}'s function \code{\link{mantel}}. 
 
+When a correction for multiple testing is applied, more permutations are necessary than in the no-correction case, to obtain significant p-values in the higher correlogram classes.
+
 The \code{print.mantel.correlog} function prints out the correlogram. See example.
 }
 
 \value{ 
 
-  \item{mantel.res }{A table with the distance classes as rows and the class indices, number of distances per class, Mantel statistics, and p-values as columns. }
+  \item{mantel.res }{A table with the distance classes as rows and the class indices, number of distances per class, Mantel statistics, and p-values as columns. A positive Mantel statistic indicates positive spatial correlation. }
   \item{n.class }{The number of distance classes. }  
   \item{break.pts }{The break points provided by the user or computed by the program. }  
+  \item{mult }{The name of the correction for multiple testing. No correction: \code{mult="none"}. }  
+#  \item{progressive }{A logical (\code{TRUE}, \code{FALSE}) value indicating whether or not a progressive correction for multiple testing was requested. }  
+  \item{n.tests }{The number of distance classes for which Mantel tests have been computed and tested for significance. }  
   \item{call }{The function call. }     
 }
 
 \author{ Pierre Legendre, Universite de Montreal }
 
 \references{ 
-Legendre, P. & L. Legendre. 1998. Numerical ecology, 2nd English edition. Elsevier Science BV, Amsterdam.
+Legendre, P. and L. Legendre. 1998. Numerical ecology, 2nd English edition. Elsevier Science BV, Amsterdam.
 
-Oden, N. L. & R. R. Sokal. 1986. Directional autocorrelation: an extension of spatial correlograms to two dimensions. Syst. Zool. 35: 608-617.
+Oden, N. L. and R. R. Sokal. 1986. Directional autocorrelation: an extension of spatial correlograms to two dimensions. Syst. Zool. 35: 608-617.
 
 Sokal, R. R. 1986. Spatial data analysis and historical processes. 29-43 in: E. Diday et al. [eds.] Data analysis and informatics, IV. North-Holland, Amsterdam.
 }
@@ -59,7 +66,9 @@
 
 mite.correlog = mantel.correlog(mite.hel.D, XY=mite.xy, nperm=99)
 summary(mite.correlog)
-mite.correlog
+mite.correlog   
+# or: print(mite.correlog)
+# or: print.mantel.correlog(mite.correlog)
 plot(mite.correlog)
 
 mite.correlog2 = mantel.correlog(mite.hel.D, XY=mite.xy, cutoff=FALSE, 
@@ -70,4 +79,4 @@
 
 }
 
-\keyword{ multivariate }
+\keyword{ multivariate }
\ No newline at end of file



More information about the Vegan-commits mailing list