labels-methods {apcluster}R Documentation

Generate label vector from clustering result

Description

Generate a label vector from an clustering result

Usage

## S4 method for signature 'ExClust'
labels(object, type="names")

Arguments

object

object of class APResult or ExClust

type

specifies which kind of label vector should be created, see details below

Details

The function labels creates a label vector from a clustering result. Which kind of labels are produced is controlled by the argument type:

“names”

(default) returns the name of the exemplar to which each data sample belongs to; if no names are available, the function stops with an error;

“enum”

returns the index of the cluster to which each data sample belongs to, where clusters are enumerated consecutively from 1 to the number of clusters (analogous to other clustering methods like kmeans);

“exemplars”

returns the index of the exemplar to which each data sample belongs to, where indices of exemplars are within the original data, which is nothing else but the slot object@idx with attributes removed.

Value

returns a label vector as long as the number of samples in the original data set

Author(s)

Ulrich Bodenhofer and Andreas Kothmeier

References

https://github.com/UBod/apcluster

Bodenhofer, U., Kothmeier, A., and Hochreiter, S. (2011) APCluster: an R package for affinity propagation clustering. Bioinformatics 27, 2463-2464. DOI: doi:10.1093/bioinformatics/btr406.

See Also

APResult, ExClust, cutree

Examples

## create two simple clusters
x <- c(1, 2, 3, 7, 8, 9)
names(x) <- c("a", "b", "c", "d", "e", "f")

## compute similarity matrix (negative squared distance)
sim <- negDistMat(x, r=2)

## run affinity propagation
apres <- apcluster(sim)

## show details of clustering results
show(apres)

## label vector (names of exemplars)
labels(apres)

## label vector (consecutive index of exemplars)
labels(apres, type="enum")

## label vector (index of exemplars within original data set)
labels(apres, type="exemplars")

## now with agglomerative clustering
aggres <- aggExCluster(sim)

## label (names of exemplars)
labels(cutree(aggres, 2))

[Package apcluster version 1.4.13 Index]