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

倖福魔咒の 提交于 2019-12-01 03:48:08

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

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])
}

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.

Pierre Gourseaud

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

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