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 92 93
| #############################################################################
# -- Analyse (factorielle) des correspondances MULTIPLES
# A(F)CM
#
# multiple correspondance analysis (mca)
#############################################################################
library(ade4)
for (j in 1:ncol(X)) X[,j]=as.factor(X[,j]) # facteurs necessaires pour dudi.acm
############################################################################
# -- L'instruction dudi.acm ?dudi.acm
############################################################################
acm=dudi.acm(X, scann = TRUE)
############################################################################
# -- VUE
############################################################################
# par defaut :
#s.arrow(acm$co,cpoint=1.5,boxes=F,edge=F)
#s.arrow(acm$li,cpoint=1.5,boxes=F,edge=F)
contrib=round(100*acm$eig/sum(acm$eig))
plot ( acm$co[,1:2] ,
xlab=paste("Axe 1 - ",contrib[1]," %",sep=""),
ylab=paste("Axe 2 - ",contrib[2]," %",sep=""),
cex=acm$cw*length(acm$cw)*3)
text ( acm$co[,1:2] , labels=rownames(acm$co) , cex=0.75 , pos=3,xpd=NA )
abline(h=0,v=0)
############################################################################
# -- TABLEAUX D'INTERPRETATION
############################################################################
inerties = inertia.dudi(acm, col=T, row=T )
############################################################################
# -- details de inertia.dudi
############################################################################
# inerties$TOT repartition of the total inertia between axes
# inerties$row.abs absolute contributions of the decomposition of inertia for the rows
# inerties$row.rel relative contributions of the decomposition of inertia for the rows
# inerties$row.cum cumulative relative contributions of the decomposition of inertia for the rows
# inerties$col.abs absolute contributions of the decomposition of inertia for the columns
# inerties$col.rel relative contributions of the decomposition of inertia for the columns
# inerties$col.cum cumulative relative contributions of the decomposition of inertia for the columns
#
############################################################################
######################################################################
#
# -- exportation des donnees
#
######################################################################
nomfic="tab_contributions_et_cosinus_carres.txt"
contribution=round(100*inerties$col.abs/apply(inerties$col.abs,2,sum),1)
v=abs(inerties$col.rel[,1:acm$nf])
cosinus_carre=round(v/apply(v,1,sum),2)
M = matrix(0 , length(acm$cw) , 2+4*acm$nf )
for (i in 1:nrow(acm$co)) {
M[i,1] = round(100*acm$cw[i],2)
M[i,2] = round(sum(acm$l1[i,]^2),2)
for (j in 1:acm$nf) {
M[i,3+(j-1)*4] = round(acm$c1[i,j],2)
M[i,4+(j-1)*4] = contribution[i,j]
M[i,5+(j-1)*4] = cosinus_carre[i,j]
M[i,6+(j-1)*4] = sum(cosinus_carre[i,1:j])
}
}
D=data.frame(M)
rownames(D)=rownames(acm$co) ; colnames(D)[1:2]=c("poids rel.","CTR inertie")
for (j in 1:acm$nf) {
colnames(D)[3+(j-1)*4] = paste("axe ",j,sep="") ; colnames(D)[4+(j-1)*4] = "CTR"
colnames(D)[5+(j-1)*4] = "COS2" ; colnames(D)[6+(j-1)*4] = "QLT"
}
entete=matrix(c(" ",colnames(D)),1,ncol(D)+1)
write.table(entete,nomfic,sep="\t",quote=F,row.names=F,col.names=F)
write.table(D,nomfic,sep="\t",quote=F,row.names=T,col.names=F,append=T)
# |
Partager