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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 8 20:34:56 CET 2012


Author: psolymos
Date: 2012-02-08 20:34:55 +0100 (Wed, 08 Feb 2012)
New Revision: 2071

Modified:
   pkg/vegan/R/indpower.R
   pkg/vegan/man/indpower.Rd
Log:
dimname fix and extended example for indpower after user request

Modified: pkg/vegan/R/indpower.R
===================================================================
--- pkg/vegan/R/indpower.R	2012-02-08 09:12:19 UTC (rev 2070)
+++ pkg/vegan/R/indpower.R	2012-02-08 19:34:55 UTC (rev 2071)
@@ -11,12 +11,15 @@
     j <- t(x) %*% x
     ip1 <- sweep(j, 1, diag(j), "/")
     ip2 <- 1 - sweep(-sweep(j, 2, diag(j), "-"), 1, n - diag(j), "/")
-    ip <- sqrt(ip1 * ip2)
     out <- switch(as.character(type),
-        "0" = ip,
+        "0" = sqrt(ip1 * ip2),
         "1" = ip1,
         "2" = ip2)
-    colnames(out) <- paste("t", colnames(out), sep=".")
-    rownames(out) <- paste("i", rownames(out), sep=".")
+    cn <- if (is.null(colnames(out)))
+        1:ncol(out) else colnames(out)
+    rn <- if (is.null(rownames(out)))
+        1:ncol(out) else rownames(out)
+    colnames(out) <- paste("t", cn, sep=".")
+    rownames(out) <- paste("i", rn, sep=".")
     out
 }

Modified: pkg/vegan/man/indpower.Rd
===================================================================
--- pkg/vegan/man/indpower.Rd	2012-02-08 09:12:19 UTC (rev 2070)
+++ pkg/vegan/man/indpower.Rd	2012-02-08 19:34:55 UTC (rev 2071)
@@ -31,7 +31,7 @@
   Total indicator power (TIP) of an indicator species is the column mean
   (without its own value, see examples).  
   Halme et al. (2009) explain how to calculate confidence
-  intervals for these statistics.
+  intervals for these statistics, see Examples.
 }
 \value{
   A matrix with indicator species as rows and
@@ -56,7 +56,27 @@
 ip <- indpower(dune)
 ## and TIP values
 diag(ip) <- NA
-rowMeans(ip, na.rm=TRUE)
+(TIP <- rowMeans(ip, na.rm=TRUE))
+
+## p value calculation for a species
+## from Halme et al. 2009
+## i is ID for the species
+fun <- function(x, i) indpower(x)[i,-i]
+## 'c0' randomizes species occurrences
+os <- oecosimu(dune, fun, "c0", i=1, nsimul=99)
+## get z values from oecosimu output
+z <- os$oecosimu$z
+## p-value
+(p <- sum(z) / sqrt(length(z)))
+## 'heterogeneity' measure
+(chi2 <- sum((z - mean(z))^2))
+pchisq(chi2, df=length(z)-1)
+## Halme et al.'s suggested output
+out <- c(TIP=TIP[1], 
+    significance=p,
+    heterogeneity=chi2,
+    minIP=min(fun(dune, i=1)),
+    varIP=sd(fun(dune, i=1)^2))
 }
 \keyword{ multivariate }
 



More information about the Vegan-commits mailing list