order.optimal(dist, merge)
dist
.hclust
). An objective measure of a leaf ordering is the sum of the distances
along the path connecting the leaves in the given order. An ordering
with a minimal path length is defined to be an optimal ordering.
This function provides an interface to the optimal leaf ordering
algorithm (see references) for tree representations that are used by
hierarchical cluster algorithms such as hclust
.
Note that non-finite distance values are not allowed.
hclust
for hierarchical clustering and
order.length
for computing the objective value of a
leaf ordering.d <- dist(matrix(runif(30), ncol=2))
hc <- hclust(d)
co <- order.optimal(d, hc$merge)
### compare dendrograms
ho <- hc
ho$merge <- co$merge
ho$order <- co$order
op <- par(mfrow=c(2,2), pty="s")
plot(hc, main="hclust")
plot(ho, main="optimal")
# compare images
image(d[[hc$order]])
image(d[[co$order]])
par(op)
### compare lengths
order.length(d, hc$order)
order.length(d, co$order)
cat("compare: ",co$length,"")
Run the code above in your browser using DataLab