www.crosshyou.info

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

OECD Non-Financial Corporations Debt to Surplus Ratio Analysis 6 - Hierarchical Clustering using R

UnsplashWolfgang Hasselmannが撮影した写真 

www.crosshyou.info

This post is following of the above post.
In this post, I will do hierarchical clustering using R. It is very easi with R.

Firstly, I make a matrix for hierarchical clustering.

Then, I use dist() function to calculate each observations distance.

Next, I use hclust() function to fo hierarchical clustering

All right, let's plot the results.

I see LUX is very different from others.

Now, let's divide 3 clusters, I mean like below.

I use cutree() function.

You see LUX is 3, JPN is 1 and KOR is 2.
So, 3 is blue, 1 is red and 2 is green.

Then, let's see scatter plot and check hierarchical clustering is good or bad.

Nice! We see hierarchical clustering worked well.

That's it. Thank you!

To read from the 1st post,

www.crosshyou.info