Skip to content
Learn Plant Science

Learn Plant Science

Explore the the green world with us

  • Home
  • Statistics – Experimental Design & Data Analysis Using R
  • Hierarchical Cluster Analysis in R studio
web, network, programming-3706551.jpg

Hierarchical Cluster Analysis in R studio

Posted on March 18, 2023March 18, 2023 By Janith Piumal No Comments on Hierarchical Cluster Analysis in R studio
Statistics – Experimental Design & Data Analysis Using R

####Load the packages#########
install.packages("factoextra")
library(factoextra)

install.packages("cluster")
library(cluster)

########load data#############
df <- USArrests

############remove missing values##############
df <- na.omit(df)

##################scale each variable to have a mean of 0 and sd of 1##########
df <- scale(df)

#############view first six rows of dataset###############
head(df)

############view first six rows of dataset###############

Output:

> head(df)
               Murder   Assault   UrbanPop         Rape
Alabama    1.24256408 0.7828393 -0.5209066 -0.003416473
Alaska     0.50786248 1.1068225 -1.2117642  2.484202941
Arizona    0.07163341 1.4788032  0.9989801  1.042878388
Arkansas   0.23234938 0.2308680 -1.0735927 -0.184916602
California 0.27826823 1.2628144  1.7589234  2.067820292
Colorado   0.02571456 0.3988593  0.8608085  1.864967207
############define linkage methods#######################
m <- c( "average", "single", "complete", "ward")
names(m) <- c( "average", "single", "complete", "ward")

##############function to compute agglomerative coefficient
ac <- function(x) {
  agnes(df, method = x)$ac
}

#########calculate agglomerative coefficient for each clustering linkage method##
sapply(m, ac)

Output:

> sapply(m, ac)
  average    single  complete      ward 
0.7379371 0.6276128 0.8531583 0.9346210 
#######perform hierarchical clustering by Ward's minimum variance#######
clust <- agnes(df, method = "ward")

###################produce dendrogram###################
pltree(clust, cex = 0.6, hang = -1, main = "Dendrogram") 

Post navigation

❮ Previous Post: Principal component analysis (PCA) in R studio
Next Post: Recombinant DNA Technology ❯

You may also like

statistics, graph, chart-3411473.jpg
Statistics – Experimental Design & Data Analysis Using R
Introduction to experiment design
January 17, 2023
code, coding, web-944499.jpg
Statistics – Experimental Design & Data Analysis Using R
Z – test & T – Test in R
January 27, 2023
analytics, seo, analysis-1907993.jpg
Statistics – Experimental Design & Data Analysis Using R
Multivariate Analysis
March 18, 2023
coding, programming, working-924920.jpg
Statistics – Experimental Design & Data Analysis Using R
Linear Regression Analysis Using R
January 27, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Blog
  • Environment science
  • Horticulture
  • Microbiology
  • Molecular Biology
  • Phylogenetic
  • Plant Breeding
  • Statistics – Experimental Design & Data Analysis Using R
  • Uncategorized

Recent Posts

  • R for Phylogenetic
  • Character based approach of phylogenetic analysis
  • Distance based approach of phylogenetic analysis
  • Phylogenetic Analysis data
  • Applications of the phylogenetic Analysis.

Services

  • Study nature
  • Nature is a gift
  • A second spring
  • Smiles of nature
  • Just let it rain

Contact

Proin gravida nibh auctor aliquet amet anean sollicitudin, lorem quis.

  • 12 Avenue, New York, NY 10160
  • +1 910-626-85255
  • contact@nature.com
  • Home
  • Statistics
  • Phylogenetics
  • Microbiology
  • Plant Breeding
  • Horticulture
  • Molecular Biology
  • Environment science

Copyright © 2026 Learn Plant Science.

Theme: Oceanly Green by ScriptsTown