0

I have a presence/absence dataset and need to calculate an Ochiai distance matrix with pairwise deletion of missing values. What is the simplest way to do this?

I can use designdist from the vegan package to generate a matrix, but not sure what it is doing with the missing values. If they are coded as "?" it produces a result, but if coded as "NA" then is produces a matrix of all NAs. In vegdist you can specify if you want pairwise deletion, but you can't implement the Ochiai coefficient. None of the other distance matrix functions in other packages have this combination as far as I can tell. Any ideas?

Cheers,

James

1 Answers1

0

This could be implemented in vegan::designdist(), but with the current design only for terms="minimum". Binary data should be handled with 0/1 transformation of the input either in straight R or using decostand(..., "pa"). The following changes would do this in vegan::designdist():

--- a/R/designdist.R
+++ b/R/designdist.R
@@ -1,7 +1,7 @@
 `designdist` <-
     function (x, method = "(A+B-2*J)/(A+B)",
               terms = c("binary", "quadratic", "minimum"),
-              abcd = FALSE, alphagamma = FALSE, name) 
+              abcd = FALSE, alphagamma = FALSE, name, na.rm = FALSE)
 {
     terms <- match.arg(terms)
     if ((abcd || alphagamma) && terms != "binary")
@@ -9,13 +9,16 @@
     x <- as.matrix(x)
     N <- nrow(x)
     P <- ncol(x)
+    ## check NA
+    if (na.rm && terms != "minimum" && any(is.na(x)))
+        stop("'na.rm = TRUE' can only be used with 'terms = \"minimum\"\' ")
     if (terms == "binary") 
         x <- ifelse(x > 0, 1, 0)
     if (terms == "binary" || terms == "quadratic") 
         x <- tcrossprod(x)
     if (terms == "minimum") {
-        r <- rowSums(x)
-        x <- dist(x, "manhattan")
+        r <- rowSums(x, na.rm = na.rm)
+        x <- vegdist(x, "manhattan", na.rm = na.rm)
         x <- (outer(r, r, "+") - as.matrix(x))/2
     }
     d <- diag(x)
Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15