hclust() 层次聚类
(2016-04-29 10:32:07)| 标签: r语言hclust()层次聚类聚类分析 | 分类: R语言学习 | 
| hclust {stats} | R Documentation | 
Hierarchical Clustering
Description
层次聚类分析
Usage
hclust(d, method = "complete", members = NULL)
## S3 method for class 'hclust'
plot(x, labels = NULL, hang = 0.1, check = TRUE,
     axes = TRUE, frame.plot = FALSE, ann = TRUE,
     main = "Cluster Dendrogram",
     sub = NULL, xlab = NULL, ylab = "Height", ...)
Arguments
| d | a dissimilarity
structure as produced by  | 
| method | 类间距离计算方法 | 
| members | 
 | 
| x | an object of the
type produced by  | 
| hang | The fraction of the plot height by which labels should hang below the rest of the plot. A negative value will cause the labels to hang down from 0. | 
| check | logical indicating
if the  | 
| labels | A character vector
of labels for the leaves of the tree. By default the row names or
row numbers of the original data are used. If  | 
| axes,
frame.plot, ann | logical flags as
in  | 
| main,
sub, xlab, ylab | character strings
for  | 
| ... | Further graphical
arguments. E.g.,  | 
Value
An object of class 
| merge | an  | 
| height | a set of  | 
| order | a vector giving the
permutation of the original observations suitable for plotting, in
the sense that a cluster plot using this ordering and
matrix  | 
| labels | labels for each of the objects being clustered. | 
| call | the call which produced the result. | 
| method | the cluster method that has been used. | 
| dist.method | the distance that
has been used to create  | 
There are print, plot identify identify.hclust)
methods and therect.hclust() hclust 
See Also
identify.hclust, rect.hclust, cutree, dendrogram, kmeans.
For the Lance–Williams formula and methods that apply it generally,
see agnes 
Examples
require(graphics)
### Example 1: Violent crime rates by US state
hc <- hclust(dist(USArrests), "ave")
plot(hc)
plot(hc, hang = -1)
## Do the same with centroid clustering and *squared* Euclidean distance,
## cut the tree into ten clusters and reconstruct the upper part of the
## tree from the cluster centers.
hc <- hclust(dist(USArrests)^2, "cen")
memb <- cutree(hc, k = 10)
cent <- NULL
for(k in 1:10){
  cent <- rbind(cent, colMeans(USArrests[memb == k, , drop = FALSE]))
}
hc1 <- hclust(dist(cent)^2, method = "cen", members = table(memb))
opar <- par(mfrow = c(1, 2))
plot(hc,  labels = FALSE, hang = -1, main = "Original Tree")
plot(hc1, labels = FALSE, hang = -1, main = "Re-start from 10 clusters")
par(opar)
### Example 2: Straight-line distances among 10 US cities
##  Compare the results of algorithms "ward.D" and "ward.D2"
data(UScitiesD)
mds2 <- -cmdscale(UScitiesD)
plot(mds2, type="n", axes=FALSE, ann=FALSE)
text(mds2, labels=rownames(mds2), xpd = NA)
hcity.D  <- hclust(UScitiesD, "ward.D") # "wrong"
hcity.D2 <- hclust(UScitiesD, "ward.D2")
opar <- par(mfrow = c(1, 2))
plot(hcity.D,  hang=-1)
plot(hcity.D2, hang=-1)
par(opar)

 加载中…
加载中…