Learn R Programming

flexclust (version 1.4-1)

conversion: Conversion Between S3 Partition Objects and KCCA

Description

These functions can be used to convert the results from cluster functions like kmeans or pam to objects of class "kcca" and vice versa.

Usage

as.kcca(object, ...)

# S3 method for hclust as.kcca(object, data, k, family=NULL, save.data=FALSE, ...) # S3 method for kmeans as.kcca(object, data, save.data=FALSE, ...) # S3 method for partition as.kcca(object, data=NULL, save.data=FALSE, ...) # S3 method for skmeans as.kcca(object, data, save.data=FALSE, ...) # S4 method for kccasimple,kmeans coerce(from, to="kmeans", strict=TRUE)

Cutree(tree, k=NULL, h=NULL)

Arguments

object

Fitted object.

data

Data which were used to obtain the clustering. For "partition" objects created by functions from package cluster this is optional, if object contains the data.

save.data

Save a copy of the data in the return object?

k

Number of clusters.

family

Object of class "kccaFamily", can be omitted for some known distances.

Currently not used.

from, to, strict

Usual arguments for coerce

tree

A tree as produced by hclust.

h

Numeric scalar or vector with heights where the tree should be cut.

Details

The standard cutree function orders clusters such that observation one is in cluster one, the first observation (as ordered in the data set) not in cluster one is in cluster two, etc. Cutree orders clusters as shown in the dendrogram from left to right such that similar clusters have similar numbers. The latter is used when converting to kcca.

For hierarchical clustering the cluster memberships of the converted object can be different from the result of Cutree, because one KCCA-iteration has to be performed in order to obtain a valid kcca object. In this case a warning is issued.

Examples

Run this code
# NOT RUN {
data(Nclus)

cl1 <- kmeans(Nclus, 4)
cl1
cl1a <- as.kcca(cl1, Nclus)
cl1a
cl1b <- as(cl1a, "kmeans")

# }
# NOT RUN {
library("cluster")
cl2 <- pam(Nclus, 4)
cl2
cl2a <- as.kcca(cl2)
cl2a
## the same
cl2b <- as.kcca(cl2, Nclus)
cl2b

# }
# NOT RUN {
## hierarchical clustering
hc <- hclust(dist(USArrests))
plot(hc)
rect.hclust(hc, k=3)
c3 <- Cutree(hc, k=3)
k3 <- as.kcca(hc, USArrests, k=3)
barchart(k3)
table(c3, clusters(k3))
# }

Run the code above in your browser using DataLab