MSTEdges {TreeTools}R Documentation

Edges of minimum spanning tree

Description

Calculate or plot the ends of each edge of the minimum spanning tree of a distance matrix.

Usage

MSTEdges(distances, plot = FALSE, x = NULL, y = NULL, ...)

Arguments

distances

Either a matrix that can be interpreted as a distance matrix, or an object of class dist.

plot

Logical specifying whether to add the minimum spanning tree to an existing plot.

x, y

Numeric vectors specifying the X and Y coordinates of each element in distances. Necessary only if plot = TRUE.

...

Additional parameters to send to [lines()].

Value

MSTEdges() returns a matrix in which each row corresponds to an edge of the minimum spanning tree, and each column lists the index of the entry in distances at which the line begins and ends.

Author(s)

Martin R. Smith (martin.smith@durham.ac.uk)

References

Gower JC, Ross GJS (1969). “Minimum spanning trees and single linkage cluster analysis.” Journal of the Royal Statistical Society. Series C (Applied Statistics), 18(1), 54–64. doi: 10.2307/2346439.

See Also

Calculate minimum spanning tree: ape::mst().

Examples

# Corners of an almost-regular octahedron
points <- matrix(c(0, 0, 2, 2, 1.1, 1,
                   0, 2, 0, 2, 1, 1.1,
                   0, 0, 0, 0, 1, -1), 6)
distances <- dist(points)
MSTEdges(distances)
plot(points[, 1:2], ann = FALSE, asp = 1)
MSTEdges(distances, TRUE, x = points[, 1], y = points[, 2], lwd = 2)

[Package TreeTools version 1.3.1 Index]