Dear all,
I don't understand how works the argument "excl" of the MFA function.
The manual says : "excl : an argument that may possible to exclude categories of active variables of categorical variable groups. NULL by default, it is a list with indexes of categories that are excluded per group".
I tried several possibilities, but all of them have failed... I show some of them bellow.
Many thanks,
(and a very big thank for this so useful package, and the help list)
Aliette
********************************
library(dplyr)
library(FactoMineR)
#- "d" = dataframe exemple. 8 variables réparties en 3 groupes. Categories to exclude are "NR".
d <- data.frame(G1A=sample(c("O","N"),100,replace=T),
G1B=sample(c("O","N","NR"),100,prob=c(.6,.37,.03),replace=T),
G1C=sample(c("O","N","NR"),100,prob=c(.6,.35,.05),replace=T),
G1D=sample(c("O","N"),100,replace=T),
G2A=sample(c("O","N"),100,replace=T),
G2B=sample(c("O","N"),100,replace=T),
G3A=sample(c("O","N"),100,replace=T),
G3B=sample(c("O","N","NR"),100,prob=c(.6,.37,.03),replace=T)) %>%
mutate_all(.,as.factor)
#- "tab.disj" = disjunctive data table
tab.disj <- tab.disjonctif.prop(d,seed=NULL,row.w=NULL)
#- 2 useful vectors for follow-up :
#---- "excl.names" = names of categories to exclude
#---- "excl.index.disj" = index of categories to exclude
in the disjunctive data table
excl.names <- colnames(tab.disj)[grepl("NR",colnames(tab.disj))]
excl.index.disj <- which(colnames(tab.disj) %in% excl.names)
#- I first tried to use "excl.names" or "excl.index.disj"
(such in MCA)
res.afm <- MFA(d,group=c(4,2,2),type=rep("n",3),excl=excl.names)
#- Error in -excl : invalid argument to unary operator
res.afm <- MFA(d,group=c(4,2,2),type=rep("n",3),excl=excl.index.disj)
#- Error in eigen(crossprod(X, X), symmetric = TRUE) : valeurs infinies ou manquantes dans 'x'
#- So I tried four other solutions... and they've all failed...
#========================================================
#- ATTEMPT 1 - a list of length 3 (because 3 groups) ; each element of the list contains the indexes of categories to exclude within the variables of the group. These indexes come from the disjunctive data table "tab.disj".
#========================================================
excl.list.index.disj.cont <- vector(mode = "list", length = 3)
excl.list.index.disj.cont[[1]] <- which(colnames(tab.disj) %in% excl.names[grepl("G1",excl.names)])
excl.list.index.disj.cont[[3]] <- which(colnames(tab.disj) %in% excl.names[grepl("G3",excl.names)])
res.afm <- MFA(d,group=c(4,2,2),type=rep("n",3),
excl=excl.list.index.disj.cont)
#- Error in eigen(crossprod(X, X), symmetric = TRUE) : valeurs infinies ou manquantes dans 'x'
#========================================================
#- ATTEMPT 2 - a list of length 3 (because 3 groups) ; each element of
the list contains the indexes of categories to exclude within the
variables of the group. Unlike ATTEMPT 1, these indexes come from differents disjunctives data-tables (1 disjunctive data table per group).
#========================================================
tab.disj1 <- tab.disjonctif.prop(d[,1:4],seed=NULL,row.w=NULL)
tab.disj3 <- tab.disjonctif.prop(d[,7:8],seed=NULL,row.w=NULL)
excl.list.index.disj.pergroup <- vector(mode = "list", length = 3)
excl.list.index.disj.pergroup[[1]] <- which(colnames(tab.disj1) %in% excl.names[grepl("G1",excl.names)])
excl.list.index.disj.pergroup[[3]] <- which(colnames(tab.disj3) %in% excl.names[grepl("G3",excl.names)])
res.afm <- MFA(d,group=c(4,2,2),type=rep("n",3),
excl=excl.list.index.disj.pergroup)
#- Error in f() : Insufficient values in manual scale. 4 needed but only 3 provided.
#========================================================
#- ATTEMPT 3 - a list of length 3 (because 3 groups) ; each element of
the list contains the names of categories to exclude within the
variables of the group.
#========================================================
excl.list.names <- vector(mode = "list", length = 3)
excl.list.names[[1]] <- excl.names[grepl("G1",excl.names)]
excl.list.names[[3]] <- excl.names[grepl("G3",excl.names)]
res.afm <- MFA(d,group=c(4,2,2),type=rep("n",3),
excl=excl.list.names)
#- Error in -excl : invalid argument to unary operator
#========================================================
#- ATTEMPT 4 - a list of length 3 (because 3 groups) ; each element of
the list contains the indexes of rows that contain a category to exclude within the
variables of the group. It's a priori useless because we try to exclude categories and not rows, but I've tried everything... !
#========================================================
excl.list.index.rows <- vector(mode = "list", length = 3)
excl.list.index.rows[[1]] <- which(d[,c("G1A","G1B","G1C")]=="NR")
excl.list.index.rows[[3]] <- which(d[,c("G3A","G3B")]=="NR")
res.afm <- MFA(d,group=c(4,2,2),type=rep("n",3),
excl=excl.list.index.rows)
#- Error in eigen(crossprod(X, X), symmetric = TRUE) : valeurs infinies ou manquantes dans 'x'