What does “argument to 'which' is not logical” mean in FactoMineR MCA?

余生长醉 提交于 2019-11-30 02:40:33

问题


I'm trying to run an MCA on a datatable using FactoMineR. It contains only 0/1 numerical columns, and its size is 200.000 * 20.

require(FactoMineR)
result <- MCA(data[, colnames, with=F], ncp = 3)

I get the following error :

Error in which(unlist(lapply(listModa, is.numeric))) : argument to 'which' is not logical

I didn't really know what to do with this error. Then I tried to turn every column to character, and everything worked. I thought it could be useful to someone else, and that maybe someone would be able to explain the error to me ;)

Cheers


回答1:


It's difficult to tell without further input, but what you can do is:

  • Find the function where the error occurred (via traceback()),
  • Set a breakpoint and debug it:

    trace(tab.disjonctif, browser)
    

I did the following (offline) to find the name of tab.disjonctif:

  • Found the package on the CRAN mirror on GitHub
  • Search for that particular expression that gives the error



回答2:


Are the classes of your variables character or factor?I was having this problem. My solution was to change al variables to factor.

#my data.frame was "aux.da"
i=0
while(i < ncol(aux.da)){
  i=i+1  aux.da[,i] = as.factor(aux.da[,i])
}



回答3:


I just started to learn R yesterday, but the error comes from the fact that the MCA is for categorical data, so that's why your data cannot be numeric. Then to be more precise, before the MCA a "tableau disjonctif" (sorry i don't know the word in english : Complete disjunctive matrix) is created. So FactomineR is using this function :

https://github.com/cran/FactoMineR/blob/master/R/tab.disjonctif.R

Where i think it's looking for categorical values that can be matched to a numerical value (like Y = 1, N = 0).

For others ; be careful : for R categorical data is related to factor type, so even if you have characters you could get this error.




回答4:


Same problem as well and changing to factor did not solve my answer either, because I had put every variable as supplementary.

What I did first was transform all my numeric data to factor :

Xfac = factor(X[,1], ordered = TRUE)
for (i in 2:29){
  tfac = factor(X[,i], ordered = TRUE)
  Xfac = data.frame(Xfac, tfac)
}
colnames(Xfac)=labels(X[1,])

Still, it would not work. But my 2nd problem was that I included EVERY factor as supplementary variable ! So these :

MCA(Xfac, quanti.sup = c(1:29), graph=TRUE)
MCA(Xfac, quali.sup = c(1:29), graph=TRUE)

Would generate the same error, but this one works :

MCA(Xfac, graph=TRUE)

Not transforming the data to factors also generated the problem.

I posted the same answer to a related topic : https://stackoverflow.com/a/40737335/7193352



来源:https://stackoverflow.com/questions/34266186/what-does-argument-to-which-is-not-logical-mean-in-factominer-mca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!