Análisis de Correspondencias Múltiples(MCA)

El análisis de correspondencia múltiple (MCA) es una extensión del análisis de correspondencia simple para resumir y visualizar una tabla de datos que contiene más de dos variables categóricas. También puede verse como una generalización del análisis de componentes principales cuando las variables a analizar son categóricas en lugar de cuantitativas.

MCA se usa generalmente para analizar un conjunto de datos de una encuesta. El objetivo es identificar:

A continuacion, se va a calcular y visualizar análisis de correspondencias múltiples en el software R usando FactoMineR (para el análisis) y factoextra (para la visualización de datos).

library(FactoMineR)
library(factoextra)
library(gplots)
library(corrplot)
library(dplyr)
data("poison")
str(poison)
## 'data.frame':    55 obs. of  15 variables:
##  $ Age       : int  9 5 6 9 7 72 5 10 5 11 ...
##  $ Time      : int  22 0 16 0 14 9 16 8 20 12 ...
##  $ Sick      : Factor w/ 2 levels "Sick_n","Sick_y": 2 1 2 1 2 2 2 2 2 2 ...
##  $ Sex       : Factor w/ 2 levels "F","M": 1 1 1 1 2 2 1 1 2 2 ...
##  $ Nausea    : Factor w/ 2 levels "Nausea_n","Nausea_y": 2 1 1 1 1 1 1 2 2 1 ...
##  $ Vomiting  : Factor w/ 2 levels "Vomit_n","Vomit_y": 1 1 2 1 2 1 2 2 1 2 ...
##  $ Abdominals: Factor w/ 2 levels "Abdo_n","Abdo_y": 2 1 2 1 2 2 2 2 2 1 ...
##  $ Fever     : Factor w/ 2 levels "Fever_n","Fever_y": 2 1 2 1 2 2 2 2 2 2 ...
##  $ Diarrhae  : Factor w/ 2 levels "Diarrhea_n","Diarrhea_y": 2 1 2 1 2 2 2 2 2 2 ...
##  $ Potato    : Factor w/ 2 levels "Potato_n","Potato_y": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Fish      : Factor w/ 2 levels "Fish_n","Fish_y": 2 2 2 2 2 1 2 2 2 2 ...
##  $ Mayo      : Factor w/ 2 levels "Mayo_n","Mayo_y": 2 2 2 1 2 2 2 2 2 2 ...
##  $ Courgette : Factor w/ 2 levels "Courg_n","Courg_y": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Cheese    : Factor w/ 2 levels "Cheese_n","Cheese_y": 2 1 2 2 2 2 2 2 2 2 ...
##  $ Icecream  : Factor w/ 2 levels "Icecream_n","Icecream_y": 2 2 2 2 2 2 2 2 2 2 ...
dim(poison)
## [1] 55 15
write.csv2(poison, "poison1.csv")
poison%>%DT::datatable()

La data es resultado de una encuesta realizada a niños de primaria que sufrieron intoxicación alimentaria. Se les preguntó sobre sus síntomas y sobre lo que comían.

Consideremos unicamente variables culitativas de los sintomas y comida consumida

poison_active=poison[,5:15]
poison_active%>%DT::datatable()
balloonplot(as.table(t(as.matrix(housetasks))), label=F, main="Tareas del hogar")

observemos la frecuencia de los sintomas

summary(poison_active[,1:4])
##       Nausea      Vomiting   Abdominals     Fever   
##  Nausea_n:43   Vomit_n:33   Abdo_n:18   Fever_n:20  
##  Nausea_y:12   Vomit_y:22   Abdo_y:37   Fever_y:35

observemos la frecuencias de la comida consumida

summary(poison_active[,6:11])
##       Potato       Fish        Mayo      Courgette       Cheese  
##  Potato_n: 3   Fish_n: 1   Mayo_n:10   Courg_n: 5   Cheese_n: 7  
##  Potato_y:52   Fish_y:54   Mayo_y:45   Courg_y:50   Cheese_y:48  
##        Icecream 
##  Icecream_n: 4  
##  Icecream_y:51
for (i in 1:4) {
  plot(poison_active[, i], main=colnames(poison_active) [i],
        ylab ="Count", col="steelblue", las =2)
  }

Tabla de contingencia nauseas vs los que consumieron mayoneasa

table(poison_active[,c(1,8)])
##           Mayo
## Nausea     Mayo_n Mayo_y
##   Nausea_n     10     33
##   Nausea_y      0     12

Tabla de contingencia nauseas vs los que consumieron mayonesa y vomito

table(poison_active[,c(1,2,8)])
## , , Mayo = Mayo_n
## 
##           Vomiting
## Nausea     Vomit_n Vomit_y
##   Nausea_n       9       1
##   Nausea_y       0       0
## 
## , , Mayo = Mayo_y
## 
##           Vomiting
## Nausea     Vomit_n Vomit_y
##   Nausea_n      19      14
##   Nausea_y       5       7

Una forma más apropiada

Para observar todas las variables cualitativas en una sola tabla es usando la funcion Burt

library("GDAtools")
burt(poison_active)
##                     Nausea.Nausea_n Nausea.Nausea_y Vomiting.Vomit_n
## Nausea.Nausea_n                  43               0               28
## Nausea.Nausea_y                   0              12                5
## Vomiting.Vomit_n                 28               5               33
## Vomiting.Vomit_y                 15               7                0
## Abdominals.Abdo_n                18               0               17
## Abdominals.Abdo_y                25              12               16
## Fever.Fever_n                    19               1               18
## Fever.Fever_y                    24              11               15
## Diarrhae.Diarrhea_n              20               0               17
## Diarrhae.Diarrhea_y              23              12               16
## Potato.Potato_n                   1               2                3
## Potato.Potato_y                  42              10               30
## Fish.Fish_n                       1               0                1
## Fish.Fish_y                      42              12               32
## Mayo.Mayo_n                      10               0                9
## Mayo.Mayo_y                      33              12               24
## Courgette.Courg_n                 4               1                1
## Courgette.Courg_y                39              11               32
## Cheese.Cheese_n                   7               0                6
## Cheese.Cheese_y                  36              12               27
## Icecream.Icecream_n               3               1                3
## Icecream.Icecream_y              40              11               30
##                     Vomiting.Vomit_y Abdominals.Abdo_n Abdominals.Abdo_y
## Nausea.Nausea_n                   15                18                25
## Nausea.Nausea_y                    7                 0                12
## Vomiting.Vomit_n                   0                17                16
## Vomiting.Vomit_y                  22                 1                21
## Abdominals.Abdo_n                  1                18                 0
## Abdominals.Abdo_y                 21                 0                37
## Fever.Fever_n                      2                17                 3
## Fever.Fever_y                     20                 1                34
## Diarrhae.Diarrhea_n                3                17                 3
## Diarrhae.Diarrhea_y               19                 1                34
## Potato.Potato_n                    0                 0                 3
## Potato.Potato_y                   22                18                34
## Fish.Fish_n                        0                 0                 1
## Fish.Fish_y                       22                18                36
## Mayo.Mayo_n                        1                 8                 2
## Mayo.Mayo_y                       21                10                35
## Courgette.Courg_n                  4                 1                 4
## Courgette.Courg_y                 18                17                33
## Cheese.Cheese_n                    1                 5                 2
## Cheese.Cheese_y                   21                13                35
## Icecream.Icecream_n                1                 2                 2
## Icecream.Icecream_y               21                16                35
##                     Fever.Fever_n Fever.Fever_y Diarrhae.Diarrhea_n
## Nausea.Nausea_n                19            24                  20
## Nausea.Nausea_y                 1            11                   0
## Vomiting.Vomit_n               18            15                  17
## Vomiting.Vomit_y                2            20                   3
## Abdominals.Abdo_n              17             1                  17
## Abdominals.Abdo_y               3            34                   3
## Fever.Fever_n                  20             0                  18
## Fever.Fever_y                   0            35                   2
## Diarrhae.Diarrhea_n            18             2                  20
## Diarrhae.Diarrhea_y             2            33                   0
## Potato.Potato_n                 1             2                   0
## Potato.Potato_y                19            33                  20
## Fish.Fish_n                     0             1                   0
## Fish.Fish_y                    20            34                  20
## Mayo.Mayo_n                     8             2                   8
## Mayo.Mayo_y                    12            33                  12
## Courgette.Courg_n               1             4                   1
## Courgette.Courg_y              19            31                  19
## Cheese.Cheese_n                 5             2                   5
## Cheese.Cheese_y                15            33                  15
## Icecream.Icecream_n             2             2                   2
## Icecream.Icecream_y            18            33                  18
##                     Diarrhae.Diarrhea_y Potato.Potato_n Potato.Potato_y
## Nausea.Nausea_n                      23               1              42
## Nausea.Nausea_y                      12               2              10
## Vomiting.Vomit_n                     16               3              30
## Vomiting.Vomit_y                     19               0              22
## Abdominals.Abdo_n                     1               0              18
## Abdominals.Abdo_y                    34               3              34
## Fever.Fever_n                         2               1              19
## Fever.Fever_y                        33               2              33
## Diarrhae.Diarrhea_n                   0               0              20
## Diarrhae.Diarrhea_y                  35               3              32
## Potato.Potato_n                       3               3               0
## Potato.Potato_y                      32               0              52
## Fish.Fish_n                           1               0               1
## Fish.Fish_y                          34               3              51
## Mayo.Mayo_n                           2               0              10
## Mayo.Mayo_y                          33               3              42
## Courgette.Courg_n                     4               0               5
## Courgette.Courg_y                    31               3              47
## Cheese.Cheese_n                       2               0               7
## Cheese.Cheese_y                      33               3              45
## Icecream.Icecream_n                   2               0               4
## Icecream.Icecream_y                  33               3              48
##                     Fish.Fish_n Fish.Fish_y Mayo.Mayo_n Mayo.Mayo_y
## Nausea.Nausea_n               1          42          10          33
## Nausea.Nausea_y               0          12           0          12
## Vomiting.Vomit_n              1          32           9          24
## Vomiting.Vomit_y              0          22           1          21
## Abdominals.Abdo_n             0          18           8          10
## Abdominals.Abdo_y             1          36           2          35
## Fever.Fever_n                 0          20           8          12
## Fever.Fever_y                 1          34           2          33
## Diarrhae.Diarrhea_n           0          20           8          12
## Diarrhae.Diarrhea_y           1          34           2          33
## Potato.Potato_n               0           3           0           3
## Potato.Potato_y               1          51          10          42
## Fish.Fish_n                   1           0           0           1
## Fish.Fish_y                   0          54          10          44
## Mayo.Mayo_n                   0          10          10           0
## Mayo.Mayo_y                   1          44           0          45
## Courgette.Courg_n             0           5           1           4
## Courgette.Courg_y             1          49           9          41
## Cheese.Cheese_n               0           7           3           4
## Cheese.Cheese_y               1          47           7          41
## Icecream.Icecream_n           0           4           2           2
## Icecream.Icecream_y           1          50           8          43
##                     Courgette.Courg_n Courgette.Courg_y Cheese.Cheese_n
## Nausea.Nausea_n                     4                39               7
## Nausea.Nausea_y                     1                11               0
## Vomiting.Vomit_n                    1                32               6
## Vomiting.Vomit_y                    4                18               1
## Abdominals.Abdo_n                   1                17               5
## Abdominals.Abdo_y                   4                33               2
## Fever.Fever_n                       1                19               5
## Fever.Fever_y                       4                31               2
## Diarrhae.Diarrhea_n                 1                19               5
## Diarrhae.Diarrhea_y                 4                31               2
## Potato.Potato_n                     0                 3               0
## Potato.Potato_y                     5                47               7
## Fish.Fish_n                         0                 1               0
## Fish.Fish_y                         5                49               7
## Mayo.Mayo_n                         1                 9               3
## Mayo.Mayo_y                         4                41               4
## Courgette.Courg_n                   5                 0               1
## Courgette.Courg_y                   0                50               6
## Cheese.Cheese_n                     1                 6               7
## Cheese.Cheese_y                     4                44               0
## Icecream.Icecream_n                 1                 3               1
## Icecream.Icecream_y                 4                47               6
##                     Cheese.Cheese_y Icecream.Icecream_n Icecream.Icecream_y
## Nausea.Nausea_n                  36                   3                  40
## Nausea.Nausea_y                  12                   1                  11
## Vomiting.Vomit_n                 27                   3                  30
## Vomiting.Vomit_y                 21                   1                  21
## Abdominals.Abdo_n                13                   2                  16
## Abdominals.Abdo_y                35                   2                  35
## Fever.Fever_n                    15                   2                  18
## Fever.Fever_y                    33                   2                  33
## Diarrhae.Diarrhea_n              15                   2                  18
## Diarrhae.Diarrhea_y              33                   2                  33
## Potato.Potato_n                   3                   0                   3
## Potato.Potato_y                  45                   4                  48
## Fish.Fish_n                       1                   0                   1
## Fish.Fish_y                      47                   4                  50
## Mayo.Mayo_n                       7                   2                   8
## Mayo.Mayo_y                      41                   2                  43
## Courgette.Courg_n                 4                   1                   4
## Courgette.Courg_y                44                   3                  47
## Cheese.Cheese_n                   0                   1                   6
## Cheese.Cheese_y                  48                   3                  45
## Icecream.Icecream_n               3                   4                   0
## Icecream.Icecream_y              45                   0                  51

Análisis de correspondencia Múltiple

poison_active_mca=MCA(poison_active, graph = F)
poison_active_mca
## **Results of the Multiple Correspondence Analysis (MCA)**
## The analysis was performed on 55 individuals, described by 11 variables
## *The results are available in the following objects:
## 
##    name              description                       
## 1  "$eig"            "eigenvalues"                     
## 2  "$var"            "results for the variables"       
## 3  "$var$coord"      "coord. of the categories"        
## 4  "$var$cos2"       "cos2 for the categories"         
## 5  "$var$contrib"    "contributions of the categories" 
## 6  "$var$v.test"     "v-test for the categories"       
## 7  "$var$eta2"       "coord. of variables"             
## 8  "$ind"            "results for the individuals"     
## 9  "$ind$coord"      "coord. for the individuals"      
## 10 "$ind$cos2"       "cos2 for the individuals"        
## 11 "$ind$contrib"    "contributions of the individuals"
## 12 "$call"           "intermediate results"            
## 13 "$call$marge.col" "weights of columns"              
## 14 "$call$marge.li"  "weights of rows"
get_eigenvalue(poison_active_mca)
##        eigenvalue variance.percent cumulative.variance.percent
## Dim.1  0.33523140        33.523140                    33.52314
## Dim.2  0.12913979        12.913979                    46.43712
## Dim.3  0.10734849        10.734849                    57.17197
## Dim.4  0.09587950         9.587950                    66.75992
## Dim.5  0.07883277         7.883277                    74.64319
## Dim.6  0.07108981         7.108981                    81.75217
## Dim.7  0.06016580         6.016580                    87.76876
## Dim.8  0.05577301         5.577301                    93.34606
## Dim.9  0.04120578         4.120578                    97.46663
## Dim.10 0.01304158         1.304158                    98.77079
## Dim.11 0.01229208         1.229208                   100.00000
fviz_screeplot(poison_active_mca,addlabel=T)

corrplot(poison_active_mca$var$cos2)

corrplot(poison_active_mca$var$contrib*0.01)

fviz_mca_var(poison_active_mca, repel = F, col.var = "cos2", gradient.cols=c("red", "yellow", "green"))

fviz_mca_var(poison_active_mca, repel = F, choice = "mca.cor" )

  • La componente 1: asocia los sintomas: fiebre, diarrea y dolor abdominal
  • componente 2: alimentos
fviz_mca_var(poison_active_mca, repel = F, axes = c(1,3),choice = "mca.cor" )

fviz_mca_biplot(poison_active_mca,  col.var = "cos2", gradient.cols=c("red", "yellow", "green"), arrows = c(T,F))
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.

Con variables suplementarias

poison_sup_mca=MCA(poison, ind.sup=53:55,
quanti.sup=1:2,
quali.sup=3:4,
graph=F)
fviz_mca_biplot(poison_sup_mca, repel = T, choice="var", habillage = c(3,4), addEllipses = T )
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## ℹ Please use `gather()` instead.
## ℹ The deprecated feature was likely used in the factoextra package.
##   Please report the issue at <https://github.com/kassambara/factoextra/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

La hora y el hecho de estar enfermo esta fuertemente correlacionado con

el sexo y la edad no presentan incidencia sobr elos sintomas