1. Clean

rm(list = ls()) 
graphics.off()

2. Load Packages and Sources

Note: install all packages if did not install before or required

library(openxlsx)
library(readxl)
library(ggplot2)
library(FactoMineR)
library(SensoMineR)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa

3. Import Data

napping <- read_excel("C:/Users/Admin/OneDrive/Desktop/L02_3_slmt.xlsx", sheet = "dif") #read file
napping2 <- read_excel("C:/Users/Admin/OneDrive/Desktop/L02_3_slmt.xlsx", sheet = "des")
## New names:
## • `Độ mỏng` -> `Độ mỏng...17`
## • `Độ mỏng` -> `Độ mỏng...18`
napping <- data.frame(napping,row.names = 1) #hiding first column name
head(napping,5) #displaying 5 rows
##                            X1   Y1   X2   Y2   X3   Y3   X4   Y4   X5   Y5   X6
## Fresh Cuts (426,853) - A  9.0 35.4 25.0 22.3 26.2 14.3 11.0 24.9 12.5 28.1 33.6
## O'star (752,104) - B     31.1 35.5 41.8 23.0 11.6 14.2 47.9 14.9  9.0 18.5 46.8
## Lays (913,758) - C       30.3 35.8 22.5 22.0 14.6 14.7 49.8 15.8  9.4 27.9 45.0
## Slide (141,671) - D       5.9 30.4 28.7 22.6 37.9 13.6  9.1 27.9 25.9 21.1 28.5
## Pringles (347,842) - E   19.9 35.1 34.7 23.1 42.0 13.3 28.3 32.9 22.4 20.9 26.2
##                            Y6   X7   Y7   X8   Y8   X9   Y9  X10  Y10  X11  Y11
## Fresh Cuts (426,853) - A 21.6 13.9 25.5  9.8 31.3 12.1 18.4 14.8 18.3 46.2 21.4
## O'star (752,104) - B     23.5 10.9 24.1 31.8 22.3 14.2 21.5 22.3 19.2 36.8 27.5
## Lays (913,758) - C       24.6 47.3 26.8 14.3 29.9  9.6 17.3 11.8 17.3 48.3 25.8
## Slide (141,671) - D      30.1 35.2 27.7 16.5 20.5 19.1 24.2 27.8 21.2 47.5 28.1
## Pringles (347,842) - E   31.0 31.5 27.9 19.0 19.7 29.3 28.8 23.8 19.9 37.8 25.0
##                           X12  Y12  X13  Y13  X14  Y14  X15  Y15  X16  Y16  X17
## Fresh Cuts (426,853) - A 21.6 20.8  8.0 24.6  3.1 33.3 32.1 22.8 29.7 26.0 14.2
## O'star (752,104) - B     25.0 29.4 14.9 29.5 24.0 31.3 34.3 22.0 25.5 22.0 14.1
## Lays (913,758) - C       23.9 21.0  6.7 24.0  4.8 33.7 33.2 22.0 32.5 22.0  6.9
## Slide (141,671) - D      24.4 31.3  7.3 30.7  6.3 33.7 19.1 28.0 13.8 26.8 33.3
## Pringles (347,842) - E   26.8 30.5  8.8 36.5 13.3 33.5 20.9 28.0 14.7 31.3 36.1
##                           Y17  X18  Y18
## Fresh Cuts (426,853) - A 25.0 25.3 17.7
## O'star (752,104) - B     23.6 26.6 17.6
## Lays (913,758) - C       25.7 25.2 17.2
## Slide (141,671) - D      27.5 26.9 29.0
## Pringles (347,842) - E   27.5 33.7 29.0

4. Show Project Mapping

nS <- ncol(napping)/2 #Calculating subjects because 1 subject has 2 coordinate (x,y)
  rectangle<-function(data,i){
  plot(data[,((i-1)*2+1):(i*2)],col="blue",xlim=c(0,60),ylim=c(0,40),xlab="",ylab="",
       main=paste("Napping: Subject ",i,sep=""),type="n",asp=1)
  points(data[,((i-1)*2+1):(i*2)],col="blue",xlim=c(0,60),pch=20)
  text(data[,((i-1)*2+1):(i*2)],label=rownames(data),col="blue",pos=3,offset=0.2)
  } #Create function for others aims

5. Apply MFA and show results

5.1. Individual plot

res.napping <- MFA(napping,
                   group=rep(2,nS),
                   type=rep("c",nS),
                   name.group=paste("S",1:nS,sep=""),
                   graph=F) #Calculating napping
summary(res.napping) #Show napping
## 
## Call:
## MFA(base = napping, group = rep(2, nS), type = rep("c", nS),  
##      name.group = paste("S", 1:nS, sep = ""), graph = F) 
## 
## 
## Eigenvalues
##                        Dim.1   Dim.2   Dim.3   Dim.4
## Variance              10.569   6.167   1.695   1.031
## % of var.             54.307  31.687   8.710   5.296
## Cumulative % of var.  54.307  85.994  94.704 100.000
## 
## Groups
##                             Dim.1    ctr   cos2    Dim.2    ctr   cos2    Dim.3
## S1                       |  0.251  2.374  0.063 |  0.457  7.408  0.209 |  0.257
## S2                       |  0.124  1.172  0.015 |  0.840 13.625  0.706 |  0.036
## S3                       |  0.788  7.454  0.621 |  0.174  2.829  0.030 |  0.002
## S4                       |  0.344  3.259  0.118 |  0.394  6.385  0.154 |  0.296
## S5                       |  0.935  8.848  0.825 |  0.269  4.369  0.068 |  0.003
## S6                       |  0.766  7.244  0.582 |  0.214  3.475  0.046 |  0.062
## S7                       |  0.009  0.089  0.000 |  0.215  3.480  0.046 |  0.773
## S8                       |  0.272  2.575  0.071 |  0.871 14.124  0.729 |  0.010
## S9                       |  0.855  8.094  0.732 |  0.028  0.452  0.001 |  0.011
## S10                      |  0.774  7.327  0.600 |  0.080  1.291  0.006 |  0.013
##                             ctr   cos2  
## S1                       15.179  0.066 |
## S2                        2.146  0.001 |
## S3                        0.121  0.000 |
## S4                       17.438  0.087 |
## S5                        0.201  0.000 |
## S6                        3.656  0.004 |
## S7                       45.617  0.598 |
## S8                        0.571  0.000 |
## S9                        0.659  0.000 |
## S10                       0.759  0.000 |
## 
## Individuals
##                             Dim.1    ctr   cos2    Dim.2    ctr   cos2    Dim.3
## Fresh Cuts (426,853) - A | -2.164  8.863  0.326 | -2.315 17.375  0.373 | -1.996
## O'star (752,104) - B     | -1.424  3.836  0.087 |  4.556 67.323  0.888 | -0.594
## Lays (913,758) - C       | -4.070 31.348  0.764 | -1.169  4.434  0.063 |  1.936
## Slide (141,671) - D      |  3.479 22.907  0.692 | -1.714  9.531  0.168 |  0.030
## Pringles (347,842) - E   |  4.179 33.046  0.857 |  0.642  1.337  0.020 |  0.624
##                             ctr   cos2  
## Fresh Cuts (426,853) - A 47.016  0.277 |
## O'star (752,104) - B      4.162  0.015 |
## Lays (913,758) - C       44.215  0.173 |
## Slide (141,671) - D       0.011  0.000 |
## Pringles (347,842) - E    4.597  0.019 |
## 
## Continuous variables (the 10 first)
##                             Dim.1    ctr   cos2    Dim.2    ctr   cos2    Dim.3
## X1                       | -5.130  2.240  0.241 |  7.095  7.341  0.461 |  5.349
## Y1                       | -1.256  0.134  0.382 |  0.674  0.066  0.110 |  0.058
## X2                       |  2.440  1.157  0.123 |  6.391 13.598  0.841 | -1.329
## Y2                       |  0.284  0.016  0.468 |  0.285  0.027  0.472 | -0.075
## X3                       | 10.750  7.438  0.787 | -5.063  2.828  0.175 | -0.548
## Y3                       | -0.498  0.016  0.979 | -0.029  0.000  0.003 |  0.029
## X4                       | -8.906  2.276  0.263 | 11.043  5.996  0.404 |  9.822
## Y4                       |  5.853  0.983  0.706 | -2.813  0.389  0.163 | -1.013
## X5                       |  6.496  7.740  0.866 | -2.331  1.707  0.111 |  0.409
## Y5                       | -2.458  1.108  0.388 | -2.910  2.661  0.544 |  0.094
##                             ctr   cos2  
## X1                       15.177  0.262 |
## Y1                        0.002  0.001 |
## X2                        2.139  0.036 |
## Y2                        0.007  0.033 |
## X3                        0.121  0.002 |
## Y3                        0.000  0.003 |
## X4                       17.255  0.319 |
## Y4                        0.183  0.021 |
## X5                        0.191  0.003 |
## Y5                        0.010  0.001 |
plot.MFA(res.napping, choix="ind", habillage="none", graph.type = "classic")

5.2. Group presentation

plot.MFA(res.napping, choix = "group", habillage = "none",
         col.hab = c(rep("black",11)),
         graph.type = "classic") #Draw plot's MFA group presentation

RV coefficients

res.napping$group$RV #Calculating RV coefficients to understand how much the are relative
##             S1          S2          S3         S4        S5         S6
## S1  1.00000000 0.122485515 0.500895094 0.97319257 0.4435680 0.56985887
## S2  0.12248551 1.000000000 0.004801930 0.08005653 0.2373547 0.01811628
## S3  0.50089509 0.004801930 1.000000000 0.61998499 0.8156670 0.99307604
## S4  0.97319257 0.080056533 0.619984988 1.00000000 0.4830767 0.68942326
## S5  0.44356798 0.237354698 0.815666981 0.48307665 1.0000000 0.80625053
## S6  0.56985887 0.018116284 0.993076040 0.68942326 0.8062505 1.00000000
## S7  0.01106272 0.319132810 0.046706531 0.02594278 0.1049715 0.06061842
## S8  0.28315977 0.868462790 0.201636385 0.26501132 0.4321125 0.23837763
## S9  0.05422084 0.207454691 0.658633453 0.16369523 0.6495611 0.62487409
## S10 0.15570167 0.344438247 0.360825678 0.17439486 0.7572759 0.35330294
## S11 0.19733880 0.870315334 0.001439442 0.13124582 0.1998114 0.02187758
## S12 0.03920231 0.514712272 0.241703215 0.05344933 0.6526765 0.24287271
## S13 0.10521585 0.658123004 0.507264428 0.15578122 0.6549901 0.48753807
## S14 0.32697337 0.930062491 0.088931933 0.26602739 0.2369563 0.12043396
## S15 0.36738550 0.002796762 0.873572273 0.42594549 0.9495937 0.85104645
## S16 0.25144315 0.133583398 0.773898060 0.33756349 0.9256910 0.75265073
## S17 0.29365457 0.080831068 0.853124252 0.39331002 0.9178585 0.82838416
## S18 0.22830997 0.068491154 0.825774099 0.30787142 0.8859739 0.79459285
## MFA 0.48082592 0.528627801 0.761791996 0.53134696 0.9078579 0.76863638
##              S7        S8          S9        S10         S11        S12
## S1  0.011062718 0.2831598 0.054220843 0.15570167 0.197338803 0.03920231
## S2  0.319132810 0.8684628 0.207454691 0.34443825 0.870315334 0.51471227
## S3  0.046706531 0.2016364 0.658633453 0.36082568 0.001439442 0.24170322
## S4  0.025942780 0.2650113 0.163695227 0.17439486 0.131245816 0.05344933
## S5  0.104971511 0.4321125 0.649561091 0.75727593 0.199811428 0.65267648
## S6  0.060618425 0.2383776 0.624874091 0.35330294 0.021877582 0.24287271
## S7  1.000000000 0.1293264 0.007187942 0.01869212 0.285016419 0.01426432
## S8  0.129326371 1.0000000 0.271217883 0.46212405 0.711249871 0.65662274
## S9  0.007187942 0.2712179 1.000000000 0.52943640 0.294510655 0.61976038
## S10 0.018692118 0.4621240 0.529436400 1.00000000 0.229981980 0.89992929
## S11 0.285016419 0.7112499 0.294510655 0.22998198 1.000000000 0.43091009
## S12 0.014264321 0.6566227 0.619760380 0.89992929 0.430910090 1.00000000
## S13 0.198417110 0.6603220 0.863359955 0.59296684 0.654803583 0.75949537
## S14 0.248103467 0.8978929 0.078171360 0.16513599 0.824021971 0.34643224
## S15 0.121441606 0.1999380 0.667438032 0.58194579 0.018687344 0.46930508
## S16 0.012725664 0.3036861 0.832000900 0.81074545 0.127010342 0.73500694
## S17 0.022540615 0.2350166 0.846449705 0.70912423 0.082760458 0.62116620
## S18 0.087750676 0.2351398 0.877329021 0.60392463 0.130487334 0.58695400
## MFA 0.221097732 0.6575141 0.754045941 0.71283284 0.508390739 0.72498858
##           S13         S14         S15        S16         S17        S18
## S1  0.1052159 0.326973374 0.367385500 0.25144315 0.293654566 0.22830997
## S2  0.6581230 0.930062491 0.002796762 0.13358340 0.080831068 0.06849115
## S3  0.5072644 0.088931933 0.873572273 0.77389806 0.853124252 0.82577410
## S4  0.1557812 0.266027393 0.425945492 0.33756349 0.393310021 0.30787142
## S5  0.6549901 0.236956257 0.949593661 0.92569099 0.917858495 0.88597388
## S6  0.4875381 0.120433957 0.851046448 0.75265073 0.828384164 0.79459285
## S7  0.1984171 0.248103467 0.121441606 0.01272566 0.022540615 0.08775068
## S8  0.6603220 0.897892937 0.199938044 0.30368610 0.235016572 0.23513978
## S9  0.8633600 0.078171360 0.667438032 0.83200090 0.846449705 0.87732902
## S10 0.5929668 0.165135994 0.581945790 0.81074545 0.709124229 0.60392463
## S11 0.6548036 0.824021971 0.018687344 0.12701034 0.082760458 0.13048733
## S12 0.7594954 0.346432240 0.469305081 0.73500694 0.621166197 0.58695400
## S13 1.0000000 0.535899089 0.558200021 0.72210112 0.703056788 0.73886504
## S14 0.5358991 1.000000000 0.029547945 0.03492822 0.008533544 0.02851934
## S15 0.5582000 0.029547945 1.000000000 0.89598409 0.924321634 0.93619834
## S16 0.7221011 0.034928224 0.895984093 1.00000000 0.984420188 0.93821516
## S17 0.7030568 0.008533544 0.924321634 0.98442019 1.000000000 0.95716890
## S18 0.7388650 0.028519338 0.936198343 0.93821516 0.957168899 1.00000000
## MFA 0.8617731 0.504139575 0.803226692 0.86079261 0.851631856 0.83326288
##           MFA
## S1  0.4808259
## S2  0.5286278
## S3  0.7617920
## S4  0.5313470
## S5  0.9078579
## S6  0.7686364
## S7  0.2210977
## S8  0.6575141
## S9  0.7540459
## S10 0.7128328
## S11 0.5083907
## S12 0.7249886
## S13 0.8617731
## S14 0.5041396
## S15 0.8032267
## S16 0.8607926
## S17 0.8516319
## S18 0.8332629
## MFA 1.0000000