Every R point: Hierarchical Cluster Analysis instance combat-dist, Hclust, heatmap, etc.

Source: Internet
Author: User

Cluster Analysis: An analytical method for classifying samples or indicators, based on the known characteristics of samples and indicators. This section focuses on hierarchical clustering, which consists of 3 sections, each of which includes a practical example.

1. General Clustering Process:


First, using the dist () function to calculate the distance between variables
DIST.R = dist (data, method= "")
The method includes 6 methods that represent different distance measures: "Euclidean", "Maximum", "Manhattan", "Canberra", "binary" or "Minkowski". The corresponding meaning of self-search.

Second, using Hclust () for clustering
HC.R = Hclust (DIST.R, method = "")
The method includes 7 methods that represent clustering methods: "Ward", "single", "Complete", "average", "mcquitty", "median" or "centroid". The corresponding meaning of self-search.

Three, drawing
Plot (HC.R, hang = -1,labels=null) or plot (HC.R, hang = 0.1,labels=f)
Hang equals the value, indicating the distance between the label and the End branch,
A negative number indicates that the end branch length is 0, which is the label alignment.
The labels represents the label, which is null by default and represents the original name of the variable. Labels=f: Indicates that the label is not displayed.

Example Introduction:

Special case USAGE:

When clustering with a known distance matrix, the distance between the variables has been calculated, just want to use
A known distance matrix is clustered. At this point, you need to turn the distance matrix into the dist type.
Then perform hclust () clustering and plot () drawing.

#MyData as a distance matrix and a square matrixMydata<-matrix (1:25,ncol=5);class(MyData);#Turn the MyData into a dist typemydist<-as.dist (MyData);class(mydist); [1]"Dist"MYHC<-hclust (mydist,method=" Complete"); myhc; Call:hclust (d= Mydist, method =" Complete") Cluster Method:completenumber of objects:5Plot (Myhc,hang=0.1)

2, Heat map clustering process:


First, using the dist () function to calculate the distance between variables
DIST.R = dist (data, method= "")

Second, using Heatmap () function for heat map clustering
For specific parameters in Heatmap, there is no introduction here, so you can find instructions in the Help documentation. In addition to this heatmap function, the HEATMAP.2 () function in the Gplots package can also be used as a hotspot map cluster.


Where parameters are not described too much. If there is a need, please share and reply: HEATMAP.2

You can get the answer.

Practical Examples:

require (graphics);d IST.R<-dist (usarrests,method="Euclidean"# method: Euclidean distance  # clustering and drawing heatmap (As.matrix (DIST.R))

3, multi-dimensional scale and clustering results


The MDs method is used to reduce the dimension of the distance matrix and to represent the results of clustering with different colors.
Another clustering effect is shown.

Example:

Transferred from: http://mp.weixin.qq.com/s?__biz=MzA3NDUxMjYzMA==&mid=209248280&idx=2&sn= C0ec5d9a9b060654ffdaad3d6911a812#rd

Every R point: Hierarchical Cluster Analysis instances actual combat-dist, Hclust, heatmap, etc. (Turn)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.