-
Notifications
You must be signed in to change notification settings - Fork 0
/
factor_analysis_script.R
94 lines (65 loc) · 2.25 KB
/
factor_analysis_script.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
library("FactoMineR")
library("factoextra")
library(Factoshiny)
library(corrplot)
#######################################
#MCA
#######################################
SOB <- read.csv("~/Desktop/SOB.csv",
header=TRUE, na.strings=c("NA","NaN", "") )
data<-SOB
data<-na.omit(data)
#data summary
summary(data)
#apply MCA
res.mca<-MCA(data, ncp = 5, graph = TRUE)
#screeplot
fviz_screeplot(res.mca, addlabels = TRUE, ylim = c(0, 20))
#eigen values
eig.val <- get_eigenvalue(res.mca)
#MCA-Biplot
fviz_mca_biplot(res.mca,
repel = TRUE, # Avoid text overlapping (slow if many point)
ggtheme = theme_minimal())
#corrleation plot
corrplot(res.mca$var$coord, is.corr=FALSE)
#f you want to highlight the correlation between variables
#(active & supplementary) and dimensions,
#use the function fviz_mca_var() with the argument choice = “mca.cor”:
fviz_mca_var(res.mca, choice = "mca.cor",
repel = TRUE, # Avoid text overlapping (slow)
ggtheme = theme_minimal())
#Bi-plot variable categories
fviz_mca_var(res.mca,
repel = TRUE, # Avoid text overlapping (slow)
ggtheme = theme_minimal())
#The function dimdesc() [in FactoMineR] can be used to
#identify the most correlated variables with a given dimension:
res.desc <- dimdesc(res.mca, axes = c(1,2))
res.desc[[1]]
#######################################
#MFA
#######################################
SOB <- read.csv("~/Desktop/SOB.csv",
header=TRUE, na.strings=c("NA","NaN", "") )
data<-SOB
data<-na.omit(data)
#create model
res.mfa <- MFA(data,
group = c(6,4,6,2,1),
type = c("n",rep("n",4)),
ncp=5,
name.group = c("demo", "process",
"social", "project", "SOB"),
graph = FALSE)
print(res.mfa)
#screeplot
fviz_screeplot(res.mfa, addlabels = TRUE, ylim = c(0, 15))
#To plot the groups of variables, type this:
fviz_mfa_var(res.mfa, "group")
#contribution plot
fviz_contrib(res.mfa, "group", axes = 1)
fviz_contrib(res.mfa, "group", axes = 2)
fviz_mfa_var(res.mfa, "quali.var", palette = "jco",
col.var.sup = "violet", repel = TRUE,
geom = c("point", "text"), legend = "bottom")