medoids: Compute 'pam'-consistent Medoids from Clustering

View source: R/medoids.R

medoidsR Documentation

Compute pam-consistent Medoids from Clustering

Description

Given a data matrix or dissimilarity x for say n observational units and a clustering, compute the pam()-consistent medoids.

Usage

medoids(x, clustering, diss = inherits(x, "dist"), USE.NAMES = FALSE, ...)

Arguments

x

Either a data matrix or data frame, or dissimilarity matrix or object, see also pam.

clustering

an integer vector of length n, the number of observations, giving for each observation the number ('id') of the cluster to which it belongs. In other words, clustering has values from 1:k where k is the number of clusters, see also partition.object and cutree(), for examples where such clustering vectors are computed.

diss

see also pam.

USE.NAMES

a logical, typical false, passed to the vapply() call computing the medoids.

...

optional further argument passed to pam(xj, k=1, ...), notably metric, or variant="f_5" to use a faster algorithm, or trace.lev = k.

Value

a numeric vector of length

Author(s)

Martin Maechler, after being asked how pam() could be used instead of kmeans(), starting from a previous clustering.

See Also

pam, kmeans. Further, cutree() and agnes (or hclust).

Examples

## From example(agnes):
data(votes.repub)
agn1 <- agnes(votes.repub, metric = "manhattan", stand = TRUE)
agn2 <- agnes(daisy(votes.repub), diss = TRUE, method = "complete")
agnS <- agnes(votes.repub, method = "flexible", par.meth = 0.625)

for(k in 2:11) {
  print(table(cl.k <- cutree(agnS, k=k)))
  stopifnot(length(cl.k) == nrow(votes.repub), 1 <= cl.k, cl.k <= k, table(cl.k) >= 2)
  m.k <- medoids(votes.repub, cl.k)
  cat("k =", k,"; sort(medoids) = "); dput(sort(m.k), control={})
}


cluster documentation built on Aug. 22, 2022, 5:07 p.m.

Related to medoids in cluster...