R语言中利用hclust实现层次聚类

news/2024/5/20 9:22:50 标签: r语言, 聚类, 开发语言

介绍

hclust()函数是stats包中的函数,可以根据距离矩阵实现层次聚类

hclust()使用介绍

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", ...)

参数介绍

  • d
    a dissimilarity structure as produced by dist.

  • method
    the agglomeration method to be used. This should be (an unambiguous abbreviation of) one of “ward.D”, “ward.D2”, “single”, “complete”, “average” (= UPGMA), “mcquitty” (= WPGMA), “median” (= WPGMC) or “centroid” (= UPGMC).

  • members
    NULL or a vector with length size of d. See the ‘Details’ section.

  • x
    an object of the type produced by hclust.

  • 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 x object should be checked for validity. This check is not necessary when x is known to be valid such as when it is the direct result of hclust(). The default is check=TRUE, as invalid inputs may crash R due to memory violation in the internal C plotting code.

  • 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 labels = FALSE no labels at all are plotted.

  • axes, frame.plot, ann
    logical flags as in plot.default.

  • main, sub, xlab, ylab
    character strings for title. sub and xlab have a non-NULL default when there’s a tree$call.


  • Further graphical arguments. E.g., cex controls the size of the labels (if plotted) in the same way as text.

输出值

An object of class hclust which describes the tree produced by the clustering process. The object is a list with components:

  • merge
    an n-1 by 2 matrix. Row i of merge describes the merging of clusters at step i of the clustering. If an element j in the row is negative, then observation -j was merged at this stage. If j is positive then the merge was with the cluster formed at the (earlier) stage j of the algorithm. Thus negative entries in merge indicate agglomerations of singletons, and positive entries indicate agglomerations of non-singletons.

  • height
    a set of n-1 real values (non-decreasing for ultrametric trees). The clustering height: that is, the value of the criterion associated with the clustering method for the particular agglomeration.

  • 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 merge will not have crossings of the branches.

  • 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 d (only returned if the distance object has a “method” attribute).

实例


require(graphics)

### Example 1: Violent crime rates by US state

hc <- hclust(dist(USArrests), "ave")
plot(hc)

在这里插入图片描述


plot(hc, hang = -1)

在这里插入图片描述


http://www.niftyadmin.cn/n/1565526.html

相关文章

Atl对象多线程访问

ATL对象多线程访问临界锁的实现 CComCriticalSection和CComAutoCriticalSection类只是将Windows临界区封装了一下。 CComCriticalSection类封装了一个临界区&#xff0c;提供对该临界区的初始化、锁定、解锁和释放操作。CComAutoCriticalSection是CComCriticalSection的一个子类…

前端屏幕尺寸和分辨率_屏幕尺寸、分辨率、倍率到底是什么鬼

目前我们做移动端项目几乎不需要考虑为什么要这样写样式&#xff0c;为什么设计稿上100px我们直接写成1rem&#xff0c;移动端的屏幕尺寸那么多变&#xff0c;为什么能轻松兼容&#xff1f;那我们得从移动端的屏幕尺寸来探索一下其中的原理&#xff0c;首先就得了解这些费解的概…

R语言中绘制条形图的多种方法

简介 条形图或柱状图的用处非常广泛&#xff0c;直方图&#xff0c;频数图都是条形图的一种&#xff0c;在R语言有很多函数可以等价地实现同样的效果。 基础作图中的实现 x(1:5)^2 barplot(x)ggplot2包的实现 利用geom_col&#xff08;&#xff09;实现 library(ggplot2) …

CSS命名规范参考及书写注意事项(上)

CSS书写顺序*{displaypositionfloatclearcursor…marginpaddingwidthheightvertical-alignwhite-spacetext-decorationtext-align…colorfontcontentborderbackground}下表顺序为从上到下&#xff0c;从左到右&#xff1a;display || visibilitylist-style : list-style-type |…

R语言中的函数14:corssprod()和tcrossprod()

介绍 R语言中有两个矩阵乘积函数corssprod(x,y))(t(x)%*%x)和tcorssprod(x,y)(x%*%t(x)),这两个函数在向量之间的乘法应用中会很方便。 应用 ac(1,2,3) bc(2,5,4) crossprod(a,b) # [,1] # [1,] 24 t(a)%*%b # [,1] # [1,] 24tcrossprod(a,b) # [,1]…

rabbitmq多个消费者监听一个队列_RabbitMQ工作模式

人这一辈子,有所为,有所不为,什么事情能做,什么事情不能做,内心一定要有所权衡。无论到了什么年纪,都应当遵守做人做事的底线,如此,才能活得踏实,才能活出自己想要的样子。 美好一天从“踏实”开始! RabbitMQ如何工作 让我们首先熟悉RabbitMQ的一些重要概念: •生产…

CentOS5.1 L.M.A.P环境配置全图解之一——系统安装

CentOS5.1 L.M.A.P环境配置全图解之一——系统安装从光驱引导后&#xff0c;第一个界面&#xff1a; 直接回车就可以&#xff01;是否检查安装媒体&#xff1a;我们这里选择Skip跳过下面引导程序将检测硬件&#xff0c;然后自动引导进入系统&#xff0c;这时候你的鼠标就可以用…

android开发 自我优势_2019年Android开发者常见面试题(一)

大部分开发者进入公司&#xff0c;一个必备的环节就是面试&#xff0c;只有通过面试&#xff0c;才能知道求职者是否符合公司的要求&#xff0c;也只有通过面试&#xff0c;求职者才能有幸进入到企业里工作&#xff0c;那么怎么才能提高面试的成功率呢&#xff1f;对于开发者而…