Multiple Factor Analysis (MFA) using FactoMineR

The video demonstrates how to perform Multiple Factor Analysis (MFA) using the FactoMineR package in R, applied to a wine sensory dataset comprising 21 wines described by 31 variables (2 qualitative, 29 quantitative) organized into five active groups (smell, visual, taste, smell after swirling, tasting appreciation) and two supplementary groups (wine origin, overall preference). The presenter walks through loading the dataset, configuring the MFA function (defining variable groups, types, number of dimensions, group names, and supplementary groups), and interpreting the summary output (eigenvalues, inertia, coordinates, contributions, cosine squared, and v.test for qualitative categories). The tutorial then reviews the default graphical outputs (group plot, individuals plot, variables correlation circle, partial points, category plot, partial axes) and provides extensive guidance on customizing these plots: adjusting label size and placement, using transparency, selecting individuals or variables based on cosine squared or contributions, coloring by qualitative variables, changing axes, adding shadows, and handling overlapping labels. It also shows how to rebuild partial axes plots with fewer dimensions and how to use the dimdesc function to automatically describe factor dimensions. Throughout, the focus is on improving readability and interpretability of MFA visualizations for presentation purposes.
Chapters
The aim of this video is to show you how to do multiple factor analysis, that is MFA, with FactoMineR, and how to improve the default output graphs in FactoMineR. We are going to use the following dataset in which 21 wines were described by a panel of experts using sensory descriptors. 2 qualitative variables, the origin of the wines and the soil type, were also recorded. We have therefore 21 rows of wines and 31 columns of variables: 2 qualitative and 29 quantitative, which can be grouped into 5 groups of variables: one group of smells, one group of visual perceptions, one group on taste variables, one group on smell after swirling, and a group on tasting appreciation. The groups for smell, visuals, tasting, and smell after swirling are considered as active groups, while the groups for the wine's origin and for tasting appreciation are considered as supplementary groups. So now we can go and use R. We first open the instructions file on the wine dataset, which has all of the code to run the exercise. We will work through the instructions as we go. So let's run the first command and load the FactoMineR library. We will actually use the wine dataset, which is the example dataset for the MFA function. We can see the example associated with the MFA function by typing ?MFA, and at the very bottom of the help file, we can see the lines of code associated with this wine example. So to begin, we load the wine dataset. And then, we can move on to explaining the lines of code for the MFA. The MFA function takes as input the wine dataset, and then it is necessary to define the groups of variables. The MFA will balance out the influence of each of these groups in the construction of the dimensions. The first group of variables consists of the first 2 variables. The second group contains the following 5. Then the 3rd the next 3, the 4th the next 10, and the 5th the next 9, and the last group contains the last 2 variables. The nature of the variables in a group is specified by the type option. We specify the type of each group of variables with c for continuous or quantitative, s for continuous or quantitative but with scaled variables, N for groups of nominal or qualitative variables, and F for frequency tables. Thus, in the example, the first group is composed of qualitative variables while all subsequent groups contain quantitative variables with an S which here means that we will standardize the variables in each group. The option NCP=5 means that the results on the first 5 dimensions are provided. It is possible to name the groups of variables using name.group: a group for the origin of the wines including label and soil type variables, a group for smell description variables, a group of visual variables, a group for smell after swirling, a group on tasting, and a group of overall preference. Then, we specify that the groups of variables number 1 and 6, that is, the group for the origin and the group of the overall preference, are supplementary groups which do not participate in the construction of the dimensions. Once the MFA has been parameterized and run, several plots are provided, and we will return to these later. The set of results is stored in the res object. It is possible to have a summary of the main results by typing summary. Try to enlarge the window a bit to show all the results. summary will first show the line of code that was run. Then, we have a table with the eigenvalues and the percentages of inertia associated with each dimension. The first dimension recovers 49% of the information that is 49% of the inertia, and the 2nd dimension 19%. Next, we have results on the groups of variables. So the active groups, first with the coordinates of the groups, the contributions of each of the groups to the construction of the 1st dimension, and their representation quality on the 1st dimension. Then, the same results on the 2nd dimension, Coordinates, contributions, and cosine squared, then the third dimension. By default, the summary function provides the results on the first three dimensions, but you can choose to see the results you want, for example, on the first two or the first four dimensions, using the NCP argument. Next, we have the results on the supplementary groups, giving the coordinates and the cosine squared. There are no contributions here since these are groups that did not contribute to the construction of the dimensions. The following table provides the results on the individuals, by default the first 10 individuals. If we want the results on all the individuals, we use the argument nb_elements equal inf for infinity. That is, we will get the results for everything. All the individuals, all the variables, and so on. Here again, we get the coordinates, the contributions, and the cosine squared, first on the first dimension, then on the second, then on the third. Next up, we have the results for the active quantitative variables, that is, the results for the first 10 variables, again with coordinates, contributions, and cosine squared. For the supplementary quantitative variables, we have just the coordinates and the cosine squared. Here again, these are variables that did not contribute to the construction of the dimensions. There are no qualitative variables that are active here, so we have results only for the supplementary qualitative variables, and more specifically for the categories of the supplementary qualitative variables. So we have the coordinates, the cosine squared, no contributions of course, and a test value denoted v.test. The test value indicates whether a category's coordinate value is significantly different to 0 or not. More precisely, the test value corresponds to the transformation of a p-value into a quantile of the normal distribution. If the p-value is less than 5%, then the absolute value of the test value will be greater than 1.96. The sign of the test value indicates whether the coordinate value of the category is lower or greater than 0. For example, the NV4 category has a coordinate value significantly different to 0 on the 2nd dimension. And greater than 0 on this second dimension. So, that's it for the main outputs obtained from an MFA. After this, several graphs appear by default. The number of graphs and the ones that appear depend on the presence or absence of groups of quantitative variables and groups of qualitative variables. Let's now look at, one by one, the graphs obtained in our example. We will always get the plot showing the groups of variables, with solid triangles for the active groups and empty triangles for the supplementary groups. The colors of each of the groups in this plot will be reused in the other ones. If a group has a large coordinate value on a certain dimension, then that dimension is also present in the group of variables. In other words, this group divides the individuals like the MFA does with this dimension. If 2 groups have large and close-together coordinates on several dimensions, then they induce similar structures on the individuals. We then have a plot showing only the mean individuals, that is the individuals as seen by all the groups of active variables. For example, Wines T1 and T2 have very similar sensory profiles when all sensory points of view— visual, smell, taste, etc.— are taken into account. As in our analysis, some groups are made up of quantitative variables, we also get a variables plot with the correlation circle. In this plot, the variables are colored according to the group they are in. So, one color for each group. This variables plot can be interpreted simultaneously with the individuals plot like in PCA. Thus, for example, the wines to the right of the individuals plot are intense wines in terms of aroma and taste, and the wines at the top of the plot are spicy. On the individuals plot, we can represent the partial points for some individuals. By default, the plot provided shows the partial points of 4 individuals: the 2 individuals with the largest within-inertia and the 2 individuals with the smallest within-inertia. We will see how to show the partial points of all individuals further on. In our analysis, we also have qualitative variables, and it's because of this that we get a graph showing the supplementary categories and the active categories. Here, there are no active categories, so only the supplementary ones are shown. For each category, the mean point and its partial points are shown. Mean and partial points can be interpreted here like for the individuals plot. We can say, for example, that the wines grown on the reference soil type and those on the NV4 soil type are visually perceived in the same way, but are very different in terms of smell and taste. Lastly, we get the graph showing the partial axes. For each group of variables, one analysis was carried out: for the quantitative variables, a PCA; for the qualitative variables, an MCA; and the dimensions of these PCA and MCA were projected as supplementary information onto the dimensions of the MFA. So, for example, for the visual group, the first dimension is closely related to the first dimension of the MFA, while the second dimension is somewhat less related to the second dimension of the MFA. For the origin group of qualitative variables, the dimensions of the MCA are projected. Let's now go back to some of the plots and see how to modify or improve them. Let's redraw the individuals plot with the command plot. We obtain the plot with the active individuals and the categories of the supplementary variables. It is possible to make the categories invisible. We can also improve the readability of the graph by better placing the individuals' labels. For this, we can decrease the size of the font a bit using the option cex= 0.8, for example. The points are a little bit better separated and the plot is more readable. I can add partial points, for example for the wines One Vau and Per One. By default, partial points are given the colors used in the groups plot. For the One Vau wine, the red point represents how it is seen in terms of smell variables only, and the green point shows how it is seen in relation to the visual variables only. Here is a little trick if you want to represent the partial points of only one group. Simply change the color palette and use a transparent color for groups we don't want to see. For example, if we want to show only the partial points of the 3rd active group, that is to say the smell after swirling group, we can use this. The first color black corresponds to the color of the mean points, and then the colors of each group are defined, with groups 1 and 2 as transparent, the 3rd group in blue, and the 4th group also transparent. And we can show the partial points for the set of points by adding partial equals all. It is possible not to draw all the points and to just select certain individuals. We can for example select only the ones that are well projected on the plane, those which have a cosine squared greater than 0.4. In black, with a label, we have individuals with a cosine squared greater than 0.4, and gray for those with a cosine squared less than 0.4. We can also color individuals according to a variable, as for instance variable 1, which is qualitative. The Saumur wines are in red, Bourgueil in green, and Chinon in blue, thanks to the command habillage=1. We could have used the soil variable instead. We can either put the number of the variables, or the name of the variable, So here, the wines are colored according to the soil variable. We have still highlighted those with cosine squared greater than 0.4. We can also make selections according to contributions and show only the 5 individuals who have contributed the most to the construction of the dimensions. So here, only the individuals who have contributed most to the construction of the plane of colored points. We can play around with transparent points using the unselect option. By setting unselect= 0, there is no transparency at all, the points are all the same color whether they contributed strongly or not. But we see that there are no labels for points that have contributed little. And on the contrary, we can use total transparency That is, the points disappear for the individuals who are not part of the 5 who contributed the most to the construction of the dimensions. There may sometimes be a small problem with transparency because these graphs here cannot be used in PowerPoint since transparency is not managed well. So therefore, we advise you to use the color gray, for example gray 70. The unlabeled points are thus gray here so that you can use the plot in PowerPoint and, for example, be able to move the labels. By default, the 1-2 plane is provided, but the 3-4 plane can be also constructed by specifying axis=3,4. Here is the plot with dimensions 3 and 4 with the individuals who have contributed the most to the construction of these dimensions. When selecting individuals to show, we can also specify their names and visualize, for example, the wines 1VAU and PER1. We can also create the variables plot using choice=var to specify that we are drawing the variables plot. The default plot is the one where the variables are colored according to their group. You can see that, here, many labels are overlapping. In fact, the labels are quite long and can't be easily placed on the plot. The plot can be further improved by adding shadows under the labels using shadow=True. Note that the correlation circle is no longer drawn when a label goes over it. The graph is prettier, But on the one— on the other hand, the shadow is a white square that can be tricky to manage if you use the plot in something like PowerPoint. If you want to move the labels later, it's better not to add shadows. But if you want to use the plot as is, including shadows will improve readability. As with the individuals, variables can be selected according to their contribution For example, by keeping the 5 variables that contributed most to the construction of the dimensions. The 5 variables that contributed the most will get a label, and the other variables' labels will be shown but partially transparent. We can see which group they belong to and where they are projected. This makes it possible to have plots with labels that overlap less. Which means more readable plots when there are many variables. Often, it's interesting to highlight only a few of them because the variables close to the center of the circle, that is those with very short arrows, are not of great interest to us because they are poorly projected. We will often focus on the best projected variables, which therefore have large-valued coordinates, or have strongly contributed to the construction of the dimensions. It is the same thing. We can do the same for the 3-4 plane and therefore have the variables that have most contributed to the construction of this plane. We can also redo the plot of the partial axes whilst avoiding having too many dimensions for each separate analysis. To do this, it's best restart the MFA, specifying ncp=2 or ncp=3, in order to retain, for instance, only 2 or 3 dimensions for each PCA or MCA. We can then rebuild the partial axes plot. So that's it for the main graphical outputs. We can also use the dimdesc function, which provides an automatic description of the factor dimensions exactly as it does with PCA and MCA results. The first dimension is therefore characterized by the most closely related, that is positively and negatively correlated, active and supplementary quantitative variables with the first dimension of the MFA, and then by the qualitative variables and the most related categories. By default, the first 3 dimensions are described. You have now seen the main plots and main indices for MFA. The k-MFA functions that we have used were MFA, summary.mfa, and plot.mfa.
More from Yamossoun

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









