R: Orders clustered objects using hierarchical clustering

order.clusters {gclus} | R Documentation

## Orders clustered objects using hierarchical clustering

### Description

Reorders objects so that similar (or high-merit) object pairs are adjacent. The clusters argument specifies (possibly ordered) groups, and objects within a group are kept together.

### Usage

    order.clusters(merit,clusters,within.order = order.single,
        between.order= order.single,...)

### Arguments

`merit` | is either a symmetric matrix of merit or similarity score, or a `dist`.
`clusters` | specifies a partial grouping. It should either be a list whose ith element contains the indices of the objects in the ith cluster, or a vector of integers whose ith element gives the cluster membership of the ith object. Either representation may be used to specify grouping, the first is preferrable to specify adjacencies.
`within.order` | is a function used to order the objects within each cluster.
`between.order` | is a function used to order the clusters.
`...` | arguments are passed to `within.order`.

### Details

`within.order` may be NULL, in which case objects within a cluster are assumed to be in order. Otherwise, `within.order` should be one of the ordering functions `order.single`,`order.endlink` or `order.hclust`.

`between.order` may be NULL, in which case cluster order is preserved. Otherwise, `betweem.order` should be one of the ordering functions that uses a partial ordering, `order.single` or `order.endlink`.

### Value

A permutation of the objects represented by `merit` is returned.

### Author(s)

Catherine B. Hurley

### See Also

order.single,order.endlink,order.hclust.

### Examples

    data(state)
    state.d <- dist(state.x77)

    # Order the states, keeping states in a division together.
    state.o <- order.clusters(-state.d, as.numeric(state.division))
    cmat <- dmat.color(as.matrix(state.d), rev(cm.colors(5)))

    op <- par(mar=c(1,6,1,1))
    rlabels <- state.name[state.o]
    plotcolors(cmat[state.o,state.o], rlabels=rlabels)
    par(op)

    # Alternatively, use kmeans to place the  states into 6 clusters
    state.km <- kmeans(state.d,6)$cluster

    # An ordering obtained from the kmeans clustering...
    state.o <- unlist(memship2clus(state.km))

    layout(matrix(1:2,nrow=1,ncol=2),widths=c(0.1,1))
    op <- par(mar=c(1,1,1,.2))
    state.colors <- cbind(state.km,state.km)
    plotcolors(state.colors[state.o,])

    par(mar=c(1,6,1,1))
    rlabels <- state.name[state.o]
    plotcolors(cmat[state.o,state.o], rlabels=rlabels)

    par(op)
    layout(matrix(1,1))

    # In the ordering above, the ordering of clusters and the
    # ordering of objects within the clusters is arbitrary.
    # order.clusters gives an improved order but preserves the kmeans clusters.

    state.o <- order.clusters(-state.d, state.km)

    # and replot
    layout(matrix(1:2,nrow=1,ncol=2),widths=c(0.1,1))
    op <- par(mar=c(1,1,1,.2))
    state.colors <- cbind(state.km,state.km)
    plotcolors(state.colors[state.o,])

    par(mar=c(1,6,1,1))
    rlabels <- state.name[state.o]
    plotcolors(cmat[state.o,state.o], rlabels=rlabels)

    par(op)
    layout(matrix(1,1))

[Package gclus version 1.3.1 Index]