| conversion {flexclust} | R Documentation |
These functions can be used to convert the results from cluster
functions like
kmeans or pam to objects
of class "kcca" and vice versa
as.kcca(object, ...) ## S3 method for class 'hclust' as.kcca(object, data, k, family=NULL, save.data=FALSE, ...) ## S3 method for class 'kmeans' as.kcca(object, data, save.data=FALSE, ...) ## S3 method for class 'partition' as.kcca(object, data=NULL, save.data=FALSE, ...) ## S3 method for class 'skmeans' as.kcca(object, data, save.data=FALSE, ...) ## S4 method for signature 'kccasimple,kmeans' coerce(from, to="kmeans", strict=TRUE)
object |
fitted object. |
data |
data which were used to obtain the clustering. For
|
save.data |
Save a copy of the data in the return object? |
k |
number of clusters. |
family |
object of class |
... |
currently not used. |
from, to, strict |
usual arguments for |
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.
Friedrich Leisch
data(Nclus)
cl1 <- kmeans(Nclus, 4)
cl1
cl1a <- as.kcca(cl1, Nclus)
cl1a
cl1b <- as(cl1a, "kmeans")
library("cluster")
cl2 <- pam(Nclus, 4)
cl2
cl2a <- as.kcca(cl2)
cl2a
## the same
cl2b = as.kcca(cl2, Nclus)
cl2b
## 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))