
The video tutorial walks through hierarchical clustering using the FactoMineR R package, emphasizing that clustering must follow a dimensionality‑reduction step appropriate to the data type (PCA for continuous, MCA for categorical, MFA for groups of variables, CA for contingency tables). The instructor demonstrates the workflow on the "temperature" dataset from the book Exploratory Multivariate Analysis by Example Using R. The dataset contains monthly mean temperatures for European towns, supplemented by annual mean, amplitude, latitude, longitude (continuous) and a regional area factor (categorical). After performing PCA (with active and supplementary variables defined), the speaker runs HCPC (Hierarchical Clustering on Principal Components), discusses selecting the number of principal components, interpreting the inertia gain plot to decide on a cut (choosing three clusters), and visualizes the clusters on the PCA map. The tutorial then details cluster interpretation: chi‑square tests link clusters to the categorical area variable, v‑tests and correlation ratios link clusters to continuous variables (e.g., mean annual temperature, latitude), and dimensions (principal components) are also examined. Exemplars (parangons) such as Rome and Oslo are identified as the towns closest to each cluster’s centroid, and farthest towns (e.g., Athens, Reykjavík) are highlighted to illustrate cluster distinctiveness. Finally, the instructor shows how HCPC can optionally consolidate clusters with a k‑means step for greater homogeneity, and contrasts this with a pure hierarchical cut without consolidation.
Chapters
The purpose of this video is to show how to perform a hierarchical clustering with FactoMineR. So with FactoMineR, it is necessary to perform a principal component method before the clustering. So if you have continuous variables, you need to perform a principal component analysis, and then you perform the hierarchical clustering on the results of the principal component analysis. So on the principal components of the analysis. If you have categorical variables, it is necessary to perform a multiple correspondence analysis and then you can perform the clustering on the principal components. If you have groups of variables, you can perform a multiple factor analysis and then once again you perform the clustering on the principal components obtained with the multiple factor analysis. So in this case, the influence of each group of variables is balanced. Before the clustering. And if you have a contingency table, you can perform clustering after a correspondence analysis. So you can perform the clustering on the rows or on the columns. So I will show an example of the clustering with a principal component analysis. So I will take an example that is available in the book Exploratory Multivariate Analysis by Example Using R. So you can go on the website and then I will use the dataset temperature. So I will take the first 3 lines of code, I copy and then I paste these 3 lines. So I load the package FactoMineR, then The dataset is in the website. The names of the columns is available. The separator for the columns is this one. And I say that the names of the individuals is available in the first column. Then I perform the principal component analysis on the dataset. I will first show the dataset. So on this dataset, you have the 12 months and you have for each town the mean of the temperature in January, then in February, and so on. So these 12 variables are active information. You have also 4 supplementary continuous variables, so the mean temperature during the year, amplitude, and then the latitude of the town and the longitude. And you have also a qualitative variable which is the area, so the town is in east, north, south, or west of Europe. So I perform the principal component analysis on the dataset. The first 23 individuals are towns which correspond to capitals. And then the individuals from 24 to 35 correspond to big towns but not capitals. So I will consider the first individuals, the 23 individuals, as active information and the others as supplementary information. Then I consider that the 4 variables corresponding to annual amplitude, latitude, and longitude correspond to supplementary information. Supplementary continuous variables. And then the last variable, which is the area, corresponds to qualitative supplementary information. So the principal component analysis is performed. We have some graphs. So I do not explain this graph because I focus on the hierarchical clustering. And then I will perform a clustering. So first, If I perform hierarchical clustering, I will perform the clustering on the principal components of the principal component analysis. By default, with PCA, the number of principal components is 5. So I can change this number of principal components, and for example, I can use all the principal components. So if I do that, I will perform the clustering on the row dataset with all the information. But I can also not use all the information but use the information which is on the first principal components. So for example, on the 5 or on the 8, on the first 8 principal components. So it can be interesting because on the first principal component, it is the information, and on the last component, we have only noise. So it can be interesting to delete the noise because the clustering is more robust. So I perform the principal component and I keep the first 8 principal components. So now I can perform the clustering. Here is my object and I do the hierarchical clustering with HCPC on the object res. So first I have hierarchical tree and a diagram which can be interesting to know if I want to cut the tree how many clusters I can do. This first bar corresponds to the inertia gain when I go from 1 cluster to 2 clusters. So it is interesting to cut the dataset from 1 cluster to 2 clusters, but it is also interesting to cut from 2 clusters to 3 clusters, and then it is not very interesting. So it can be interesting to just cut this tree in 3 clusters. So here is a level that is proposed to cut the tree, and you can cut the tree where you want. So if I click here, I will cut the tree in 2 clusters, but I will click with 3 clusters, which is the proposed. And then the tree is cut and I have the results of the principal components analysis with the individuals, so the towns, which are colored according to their clusters. Here is the hierarchical tree on the principal components map. So you have the towns which are on the principal components map here and there is a hierarchical tree in 3 dimensions. So we have 3 kinds of information: information with principal component analysis, the information with the hierarchical tree, and the information with the clusters, which can be done— the colors of the individuals give the clusters. And here is the trees and the 3 clusters. So the individuals here are sorted according to their coordinate on the first principal component. So now I can see the output of the function. So first we have the object data_clusters. So it is just the dataset with another variable corresponding to the cluster. So we have a number which corresponds corresponds to the cluster from which the individual belongs. Then we have a description of the clusters using the variables. We have descriptions of the clusters with the categorical variables and with the continuous variables. So first with the categorical variables, we can see the link between the variables corresponding to the clusters and categorical variables. So with the categorical variable area, for example. We can perform a chi-square test and in this case the test is significant so there is a link between the clusters and the area. So more in detail, we can see if there is a link between one specific cluster and some categories of the categorical variables. So for example, the first cluster, cluster 1, is linked to the category South and it is significant. And we can explain this information. So 80% of the towns in the South belong in cluster 1 and 100% of the towns in cluster 1 are towns from the south. So these 2 information show that the towns in the south are overrepresented in cluster 1. There is no category that describes cluster 2 and no category that describes cluster 3. So we can now describe the clusters according to continuous variables. So first, we can see the link between a continuous variable and the categorical variable corresponding to the cluster. So a lot of continuous variables are linked. We can see if a variable is linked according to the correlation ratio used in a one-way analysis of variance. So the variable the most linked is the mean temperature, the annual variable. We can now describe each cluster. So if we want to describe cluster 1, we see that the variable which describes the most cluster 1 is the variable annual, which takes high values for the towns in this cluster. For towns in cluster 1, the mean of all the towns in this cluster is 15, about 15, and in all the towns, the mean is 9. So there is a difference, and this difference is significant. So we can say that it is significant because there is a p-value which is less than 5%. And for example, the latitude is different for town in cluster 1 than for the other towns, but the latitude is smaller for the town in cluster 1. We can say that it is smaller because the sign is negative for this v-test. And we can compare the mean of the category, the mean of the cluster, and the mean of all the individuals. So we can see the characterization of cluster 2 and the characterization of cluster 3. I can also describe the clusters according to the dimensions. So a dimension, a principal component, is a continuous variable. So I can exactly perform the same analysis as before and calculate the correlation ratio. So there is a link between dimension 1 and the cluster, and there is a link, a smaller but a link, a significant link between dimension 3 and the clusters. And more in detail, the towns in cluster 1 have higher values than 0, so they have coordinates that are significantly greater than 0 on dimension 1. And for cluster 2, the coordinates are less, significantly less than 0. And for cluster 3, the towns of cluster 3 have coordinates that are less than 0 on the 3rd dimension. So I can now describe the cluster according to the individuals. So here is the parangon. So the parangon is the individual which is the closest to the center of gravity of the cluster. So in cluster 1, the town which is the closest to the center of gravity of cluster 1 is Rome. And we can see the distance between Rome and the center of gravity of cluster 1. And then the second town is Lisbon, and then Madrid and Athens. And for cluster 2, the town which is the closest to the center of gravity— so it can be interesting to interpret the center of gravity with a real town because the center of gravity is a fictive town and it can be easier to interpret with a real town. So a real town which is close to the center of gravity of cluster 2 is Oslo. And we can also describe the clusters with the town which is the most far from the other clusters. So Athens is a town which is very far from cluster 2 and from cluster 3. And then from this point of view, Athènes is very specific for cluster 1 because far from the other clusters. Reykjavík is far from cluster 1 and far from cluster 3, so it is a specific town for cluster 2. I will just come back from a graph. So this graph with the, the tree on 3 dimensions So you can see that, for example, there are 2 individuals here, one is in red and one is in green. So these individuals should be in green if you consider the clusters done when you cut the tree. But when we perform the clustering, we consolidate the clusters obtained by cutting the tree. So we consolidate the clusters using a K-means method, so the clusters are more homogeneous than when we just cut the tree. But it can be problematic if you want to see the clusters and the tree. So I do the analysis again and I do not consolidate the tree. So I cut the tree and there is no consolidation after cutting the tree, and you can see that now the points are in green here. So there is more link between the hierarchical tree and the clustering. But if you want to have clusters that are very homogeneous, it can be— it is interesting to perform the K-means method.
More from Yamossoun

Algorithme de calcule de la racine carrée par dichotomie #dichotomy #squareroot #algorithm









