-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalise_correspondencia_multipla.R
61 lines (50 loc) · 1.72 KB
/
analise_correspondencia_multipla.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## 5. ANÁLISE DE CORRESPONDÊNCIA MÚLTIPLA (MCA)
#Descrição: Usada para dados categóricos, identifica padrões e agrupamentos.
#Vantagens: Adequada para variáveis categóricas.
#Desvantagens: Menos comum e pode ser complexa.
# Instalando pacotes
# install.packages("FactoMineR", "gglot2", "readxl")
# install.packages("devtools")
# devtools::install_github("kassambara/factoextra")
rm(list=ls(all=TRUE))
library("ggplot2")
library("FactoMineR")
library("factoextra")
library("readxl")
library("gplots")
library("corrplot")
library("graphics")
library("foreign")
library("readxl")
library("amap")
# ler os dados
investidor <- read_excel("perfil investidor x aplicacao x estadocivil.xlsx")
investidor
# Codificação binária e matriz de BURT
matbinaria <- matlogic(dados)
matbinaria
dados.burt <-burt(dados)
dados.burt
# MCA with function dudi.acm
library(ade4)
# apply dudi.acm
mca1 <- dudi.acm(dados, scannf = FALSE)
# eig eigenvalues, a vector with min(n,p) components
# c1 principal axes, data frame with p rows and nf columns
# co column coordinates, data frame with p rows and nf columns
summary(mca1)
#coordenadas principais (BURT)
round(mca1$co, 3)
# coordenadas padrão (geradas com a matriz binária)
round(mca1$c1, 3)
# number of categories per variable
cats = apply(dados, 2, function(x) nlevels(as.factor(x)))
# data frame for ggplot
mca1_vars_df = data.frame(mca1$co, Variable = rep(names(cats), cats))
# plot
ggplot(data = mca1_vars_df,
aes(x = Comp1, y = Comp2, label = rownames(mca1_vars_df))) +
geom_hline(yintercept = 0, colour = "gray70") +
geom_vline(xintercept = 0, colour = "gray70") +
geom_text(aes(colour = Variable)) +
ggtitle("MCA plot of variables")