3 ## Minimum Spanning Tree
5 ## Copyright 2002-2006 Yvonnick Noel, Julien Claude, and Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
12 if (class(X) == "dist") X <- as.matrix(X)
16 large.value <- max(X) + 1
17 diag(X) <- large.value
20 for (i in 1:(n - 1)) {
21 tree <- c(tree, index.i)
22 m <- apply(as.matrix(X[, tree]), 2, min) #calcul les minimum par colonne
23 a <- sortIndex(X[, tree])[1, ]
28 N[index.i, index.j] <- 1
29 N[index.j, index.i] <- 1
32 X[index.i, j] <- large.value
33 X[j, index.i] <- large.value
36 dimnames(N) <- dimnames(X)
41 ### Function returning an index matrix for an increasing sort
42 sortIndex <- function(X)
44 if(length(X) == 1) return(1) # sorting a scalar?
45 if(!is.matrix(X)) X <- as.matrix(X) # force vector into matrix
47 apply(X, 2, function(v) order(rank(v))) # find the permutation
50 plot.mst <- function(x, graph = "circle", x1 = NULL, x2 = NULL, ...)
53 if (is.null(x1) || is.null(x2)) {
54 if (graph == "circle") {
55 ang <- seq(0, 2 * pi, length = n + 1)
58 plot(x1, x2, type = "n", xlab = "", ylab = "",
59 xaxt = "n", yaxt = "n", bty = "n", ...)
61 if (graph == "nsca") {
65 plot(XY, type = "n", xlab = "\"nsca\" -- axis 1",
66 ylab = "\"nsca\" -- axis 2", ...)
68 } else plot(x1, x2, type = "n", xlab = deparse(substitute(x1)),
69 ylab = deparse(substitute(x2)), ...)
71 w1 <- which(x[i, ] == 1)
72 segments(x1[i], x2[i], x1[w1], x2[w1])
74 points(x1, x2, pch = 21, col = "black", bg = "white", cex = 3)
75 text(x1, x2, 1:n, cex = 0.8)
80 Dr <- apply(A, 1, sum)
81 Dc <- apply(A, 2, sum)
83 eig.res <- eigen(diag(1 / sqrt(Dr)) %*% A %*% diag(1 / sqrt(Dc)))
84 r <- diag(1 / Dr) %*% (eig.res$vectors)[, 2:4]
85 ## The next line has been changed by EP (20-02-2003), since
86 ## it does not work if 'r' has no dimnames already defined
87 ## dimnames(r)[[1]] <- dimnames(A)[[1]]
88 rownames(r) <- rownames(A)