2016-08-13 37 views
0

私は存在/不在のデータセットがあり、欠損値のペアワイズ削除でOchiai距離行列を計算する必要があります。これを行う最も簡単な方法は何ですか?Ochiai距離行列の計算方法R

ビーガンパッケージのdesigndistを使用して行列を生成できますが、欠損値で何が行われているかはわかりません。それらが「?」としてコード化されている場合、結果を生成するが、 "NA"としてコード化された場合、すべてのNAの行列が生成される。 vegdistではペアワイズ削除を指定できますが、Ochiai係数は実装できません。他のパッケージの他の距離行列関数のどれも、私が知る限り、この組み合わせはありません。何か案は?

乾杯、

答えて

0

これはvegan::designdist()で実施することができる

ジェームズが、唯一のterms="minimum"のための現在の設計と。バイナリデータは、入力の0/1変換で直接Rまたはdecostand(..., "pa")を使用して処理する必要があります。次の変更は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)