Multiple Factor Analysis (MFA) with R using FactoMineR

The video demonstrates how to conduct a Multiple Factor Analysis (MFA) on the built‑in wine dataset using the FactoMineR package in R and focuses heavily on improving the resulting graphics for presentation. After loading FactoMineR, the presenter defines six groups of variables, specifying which are active (categorical or continuous) and which are supplementary, and sets scaling options. The MFA is run with five dimensions, and the resulting object is examined with summaryMFA, which provides eigenvalues, variance percentages, and detailed tables of coordinates, contributions, and squared cosines (cos2) for groups, individuals, and variables (both active and supplementary). The tutorial then walks through the various default plots produced by FactoMineR—group plots, partial axes, mean individuals, variable maps, individual maps with partial points, and category maps—explaining how to interpret them. A large portion of the video is devoted to customizing these plots: adjusting label size (cex), making labels invisible, adding or hiding partial points, coloring points by group or by categorical variables (e.g., origin, soil), using transparency or gray for low‑contributing points, selecting individuals or variables based on cos2 or contribution thresholds, and handling dimensions beyond the first two. The presenter also discusses practical issues such as exporting graphics as PDF/PNG/JPEG for PowerPoint, dealing with transparency limitations, and using shadows to improve readability. Throughout, the emphasis is on making MFA visualizations clear, informative, and ready for inclusion in reports or presentations.
Chapters
The purpose of this video is to show how to perform a multiple factor analysis with FactoMineR and especially how to improve the graphics that are obtained with FactoMineR. First, I load the package and I will perform a multiple factor analysis on the example dataset of MFI. So I'm gonna go to the help of the MFA function and at the bottom of the help I can use the example with the dataset wine. So I copy and paste this example. So I quickly explain the lines of code. First I load the dataset wine. Then I did the MFA on the dataset. And I create groups of variables. The MFA will balance the influence of each group of variables in the construction of the dimensions, especially in the construction of the first dimension. So I have 6 groups of variables. The first group is with the first 2 variables, then the second group uses the 5 next variables, then the third group use the 3 next variables, and then 10 variables, 9 variables, and the last group will use the 2 last variables. Then the nature of the group is given. The first group is a categorical group, so I'll use an N. Then the 5 last groups correspond to continuous variables, so I'll use an S to say that I want to scale the variables. The number of components for the outputs is 5. Then I can name the groups of variables. So there is a group with the origin of the wine, a variable with the label and with the soil, then a group with olfactive variables, then visual variables, then a group with olfactive variables after shaking, then a taste group of variables, and then groups with overall liking variables. And finally, the states of the group 1 and 6 correspond to supplementary groups of variables. So these groups will not participate to the construction of the dimensions. So once MFA is performed, the results are in the object named res, and I can first summary the results. So I use the function summary. I will extend the window to have all the results. So I use the function summaryMFA, and in this function, as an output, I have first the lines of code that is used to perform the multiple factor analysis. Then we have a table with the eigenvalues and the percentage of variance explained by each dimension. So for the first dimension, 49% of inertia, 49% of variance is explained by the first dimension, and then 19% of variance is explained with the second dimension. Then we have the results for the groups of variables. So first for the active groups of variables with the coordinates on the first dimension. The contribution of the groups to the construction of the first dimension and the quality of representation explained with the squared cosine. Then we have the results for the second dimension and then the results for the third dimension. We also have the results for the supplementary groups of variables, so the 2 groups of variables And we have the coordinate and the quality of representation explained with the squared cosine. There is no contribution since these groups of variables are not used to construct the dimensions. Then we have the results for the individuals. So the results are given for the 10 first individuals. We can have the results for all the individuals using the argument nb_elements. So if I use nb_elements equal to inf for infinity, I will have the results for all the individuals. So by default, I have the result for the 10 first individuals with the coordinates of the individuals, the contribution to the construction of the dimension, and the squared cosine. Then we have the results for the variables. So first for the continuous active variables. Once again, we have the coordinates, the contribution, and the square cosine for the first, then the second, and the third dimension. We also have the result for the supplementary continuous variables, so with the coordinate and square cosine, and then we have the results for the categorical variables. So there is no active categorical variables, but if we have some active categorical variables, we would have the results for these variables. Here we have only results on supplementary categorical variables, so the results are given for the categories of each variable. We have the coordinate, the squared cosine, no contribution because these variables do not contribute to the construction of the dimension, and a test value which takes its value between -2 and 2 if the coordinate is not significantly different from 0, and a value greater than 2 in absolute value if the coordinate is significantly different from 0. So for example, the category reference has a coordinate which is significantly different from 0 in the first dimension. So here are the summary of the results for the MFA. So then many graphs appeared earlier. We first have a graph with the groups of variables. In brown, we have the active groups of variables, and in green, the supplementary groups of variables with continuous and with categorical variables. Then we have a graph with the partial axes, the partial dimensions of each analysis. So for each group of variables, we performed an analysis. So for continuous variables, a PCA was performed, and we project the dimensions of the PCA as supplementary information in the MFA. So for instance, for the group of visual here, the first dimension of visual is closely linked to the first dimension of the MFA. And the 2nd dimension of visual is less linked to the 2nd dimension of MFA. For the groups of qualitative variables, as the origin here, we perform an MCA and not a PCA. We also project the dimensions of the MCA on the MFA dimensions. So we now have a graph with the mean individuals only, so the individuals, the wines, seen by all the active groups of variables. We have a graph with the variables. So you can see that the variables are colored according to their group. So a same color is used for a same group. And we have a graph with the individuals, and for some individuals, we also have a partial point. So it means the individual seen by only the variables of one group. So for example, this is the wine T2 seen by only the variables of the olfactive group. So we can see here the wines which have the biggest within inertia, so which are seen in very different ways. From one group to another, and the 2 wines which have the smallest inertia, so which are seen similarly by all the groups of variables. And we also have a graph with the categories, so the supplementary and if we have the active categories, and the partial points associated to each category. So I can go back on some graphs to show how to build graphs. So I will build the graph of the individuals using plot_res and we will see how to improve these graphs. So here there are the individuals and also the categories of the categorical variables. So first I can make invisible, for instance, categories of qualitative variables. So here is a graph with only the individuals. So there is one color for each individual, so I can put only one color, the black color, for all the individuals. So here is the graph. The graph is quite readable, but if I want that the labels are less close to each other, or if I have more points, I'm willing to separate labels. So I can reduce a little bit the police of the labels using the argument cex. So cex equal odd. And the labels are smaller and points are better separated and the graph is more readable. On this graph, I can put some partial points. For instance, I can put partial points for 2 wines. So here are the 2 wines for which there are partial points. Rather than having a black color for all the groups, I can use a different color for each partial point a color according to the group. So it is easier now to see for which groups of variables corresponds each partial point. So I have this one seen by only the olfactive variables. Here the same one seen by, seen by only the visual variables. The colors that are used correspond to the colors that were used for the graph of the variables. I can also construct a graph of the group. So this is the same color that is used for the groups, graph of the variables, and the graph with the partial points. With the graph with the individuals, I can select some individuals. So I can select, for example, the wines that are well represented on the map, so the wines that have a square cosine that is higher than 0.8. So I have 4 wines that have a square cosine that is greater than 0.8 on these 2 dimensions. And for the other wines, the square cosine is lower. So the other wines are colored with some transparency and there are no labels for these wines. So the partial points are drawn when the individuals have a square cosine greater than 0.8. I can also color the individuals according to a variable, for example the variable 1, which is a categorical variable. So I color just the individuals with the variable 1. The wines which correspond to the Saumur label are in red The wines that correspond to the Chinon are in blue and the wines which correspond to Bourgueil are in green. So some points are colored with transparencies because I have selected the wines that are well projected. I use the variable 1 to color the individual. I can use the variable soil. So I can use either the number of the variable or the name of the variable to color The points are now colored according to the soil. So I have always a selection using the square cosine, but I can also select the wines using the contribution. So I can draw the wines that contribute the most to the 2 dimensions. So the 8 wines that contribute the most. So here are the 8 wines that contribute the most to the dimension. So I can play with the transparency here, putting for example unselect= 0. So then the points which do not contribute the most are colored with the same color as the points which contribute the most. The difference is that the points who do not contribute the most do not have label. On the contrary, I can put a total transparency and then The points who contribute the least are not drawn at all. So with the transparency as before here, it maybe happens that you have problems if you want to use this graph with PowerPoint because in PowerPoint the transparency is not managed. But you can save the graph using Save as a PDF, PNG, or JPEG file and the transparency is managed. If you want to copy and paste this graph in PowerPoint, you can use a color rather than a transparency. So I can put the points which contribute the least in gray. So you see that the points are now in gray and they will be drawn in PowerPoint. So you can use this graph, copy and paste this graph in PowerPoint, and for example move the labels of the other points. So by default I have a graph with the dimensions 1 and 2, but of course I can draw a graph with the dimensions 3 and 4. So here is the graph with dimension 3 and dimension 4 and the 8 wines that contribute the most to the construction of these 2 dimensions. So for my selection, I have the wines that contribute the most. I can also select the wine using the name of the wines. The 2 wines I have selected are drawn. So it is on dimensions 3 and 4. Here are the possibilities for the individual graph. We can now also work on the graph of variables. So with the variables, I will use choice equal variable. So I have a graph with all the variables. So by default, we can color the variables using the group information. So there is one color for the variables of the same group. So I advise to do this anytime. You see that here a lot of labels overlap. In fact, the labels are long enough and they cannot be written on the right of the graph. So what is recommended is to first extend the window and to do the plot again. So if I do the plot again, you see that some labels are written in this area. But some labels overlap, so the graph is not very readable. I can use a smaller police and the graph is more readable now. You can see that, for example, aroma is written over the circle, so I can use a shadow. shadow= TRUE. And now the graph is more readable. It's better now. But this shadow is more difficult to manage if you want to use it on PowerPoint because there is a rectangle in white that you have to manage. So if you want to move thereafter the labels, it is advisable not to use the shadow. But if you can use the graph as it is, it is advisable to put a a shadow because the graph is more readable. So this is what we can do with the variables graph. Again, you can use a selection and select only the variables that contribute the most to the construction of the dimension. So the 6— oh, sorry— the 6 variables who contribute the most. So the 6 variables who contribute the most are with the labels, the others are plotted with transparencies and you can see the color of the group of variables. Often it is interesting to do this because the variables that are not well projected on the map are not very interesting to interpret, so the labels can be suppressed. And then you will focus on the variables that are better projected, which therefore have a high coordinate on the dimension. High coordinates are also a high contribution. So of course I can do the same thing with the graph, for example, with dimensions 1 and 3. Okay, so I have the dimension 1 here and the dimension 3 here. So here is what we can do with the multiple factor analysis and the graphical module of the multiple factor analysis in FactoMineR.
More from Yamossoun

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









