### Multiple Factor Analysis by Example Using R. CRC Press. 2014. Jérôme Pagès # ##### Script for Indscal in chapter 7 - MFA - Data: 10 white wines from Touraine & cards (color & shape) library(FactoMineR) napping=read.table("napping.csv",header=TRUE,sep=";",row.names=1) # Indscal function is in SensoMineR package # It is devoted to the analysis of napping data (all the groups have 2 variables) library(SensoMineR) # The unique dimension of nappe 10 is dupplicated (column 19) res=indscal(napping[,c(1:19,19:21)]) # Indscal function display all the useful graphs. # To customise graphs of figure 7.7 (larger font) plot(res$points) text(res$points,rownames(res$points),offset=0.5,pos=3,cex=1.3) x11() plot(res$W) text(res$W,paste("",1:11,sep=""),offset=0.5,pos=3,cex=1.3) # Table 7.5 and figure 7.8 # They requires an Indscal solution with one dimension (option coord=c(1,1)) # For figure 7.8, factors are stored after each analysis in DonFig7_8 # For Indscal, these factors are in $points ; for MFA they are in $ind$coord DonFig7_8=res$points Tab7_5=matrix(nrow=4,ncol=2) rownames(Tab7_5)=c("Indscal","MFA","Indscal without subject 10","MFA without subject 10") colnames(Tab7_5)=c("1 dimension","2 dimensions") # Indscal with 1 dimension res1=indscal(napping[,c(1:19,19:21)],coord=c(1,1)) DonFig7_8=cbind(DonFig7_8,res1$points) Tab7_5[1,]=c(res1$r2,res$r2) # Indscal without subject 10 res=indscal(napping[,c(1:18,20:21)]) DonFig7_8=cbind(DonFig7_8,res$points) res1=indscal(napping[,c(1:18,20:21)],coord=c(1,1)) DonFig7_8=cbind(DonFig7_8,res1$points) Tab7_5[3,]=c(res1$r2,res$r2) # MFA with and then without subject sujet 10 res=MFA(napping[,c(1:19,19:21)],group=rep(2,11),type=rep("c",11),graph=F) DonFig7_8=cbind(DonFig7_8,res$ind$coord[,1:2]) lig2=apply(res$group$coord^2,MARGIN=2,FUN=sum)/sum(res$group$dist2) Tab7_5[2,]=c(lig2[1],sum(lig2[1:2])) res=MFA(napping[,c(1:18,20:21)],group=rep(2,10),type=rep("c",10),graph=F) DonFig7_8=cbind(DonFig7_8,res$ind$coord[,1:2]) lig2=apply(res$group$coord^2,MARGIN=2,FUN=sum)/sum(res$group$dist2) Tab7_5[4,]=c(lig2[1],sum(lig2[1:2])) round(Tab7_5,4) colnames(DonFig7_8)=c("F1Ind","F2Ind","FInd","F1Ind10","F2Ind10","FInd10","F1MFA","F2MFA","F1MFA10","F2MFA10") res=PCA(DonFig7_8) ############# Color & shape (Cards) # # Import and verification # Cards=read.table("4Cards.csv",header=TRUE,sep=";",row.names=1) Cards # library(FactoMineR) # # Figure 7.4 (b) # res=MFA(Cards,group=c(2,2),type=c("c","c"),graph=F,name.group=c("G1","G2")) plot(res,choix="group",cex=1.3) points(1,res$eig[2,1]/res$eig[1,1],pch=16,cex=1.3) text(1,res$eig[2,1]/res$eig[1,1],"mean(MFA)",offset=0.5,pos=3,cex=1.3)